posix_quic-master socket关闭函数以及流关闭

//关闭quicsocket

QuicCloseSocket(conn);

//跟踪这个函数

int QuicCloseSocket(QuicSocket sock)
{
    EntryPtr entry = EntryBase::GetFdManager().Get(sock);
    if (!entry || entry->Category() != EntryCategory::Socket) {
        DebugPrint(dbg_api, "sock = %d, return = -1, errno = EBADF", sock);
        errno = EBADF;
        return -1;
    }

    auto socket = std::dynamic_pointer_cast<QuicSocketEntry>(entry);
    socket->Close();
    QuicSocketEntry::DeleteQuicSocketEntry(socket);
    DebugPrint(dbg_api, "sock = %d, return = 0", sock);
    return 0;
}

//CLose()函数

socket->Close();
int QuicSocketEntry::Close()
{
    if (socketState_ == QuicSocketState_Closed)
        return 0;

    std::unique_lock<std::recursive_mutex> lock(mtx_);
    if (socketState_ == QuicSocketState_Closed)
        return 0;

    socketState_ = QuicSocketState_Closed;
    connectionVisitor_.CancelNoAckAlarm();
    if (udpSocket_)
        GetConnectionManager().Delete(*udpSocket_, impl_->connection_id(), Fd());
    impl_->CloseConnection("");
    ClearWaitingsByClose();
    ClearAcceptSocketByClose();
    return 0;
}

//流关闭

QuicCloseStream(fd);

跟踪这个函数

int QuicCloseStream(QuicStream stream)
{
    auto entry = EntryBase::GetFdManager().Get(stream);
    if (!entry || entry->Category() != EntryCategory::Stream) {
        DebugPrint(dbg_api, "stream = %d, return = -1, errno = EBADF", stream);
        errno = EBADF;
        return -1;
    }

    entry->Close();
    auto streamPtr = std::dynamic_pointer_cast<QuicStreamEntry>(entry);
    QuicStreamEntry::DeleteQuicStream(streamPtr);
    DebugPrint(dbg_api, "stream = %d, return = 0", stream);
    return 0;
}

//关闭函数

entry->Close();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值