QuicSocketAccept函数 返回一个套接字
QuicSocket newSocket = QuicSocketAccept(fd);
跟踪这个函数
QuicSocket QuicSocketAccept(QuicSocket listenSock)
{
//判断传入的值
auto socket = EntryBase::GetFdManager().Get(listenSock);
if (!socket || socket->Category() != EntryCategory::Socket) {
DebugPrint(dbg_api, "sock = %d, return = -1, errno = EBADF", listenSock);
errno = EBADF;
return -1;
}
//重点是这个AcceptSocket函数 返回一个整数
auto newSocket = ((QuicSocketEntry*)socket.get())->AcceptSocket();
if (!newSocket) {
DebugPrint(dbg_api, "sock = %d, return = -1, errno = %d", listenSock, errno);
return -1;
}
DebugPrint(dbg_api, "sock = %d, newSocket = %d", listenSock, newSocket->Fd());
return newSocket->Fd();
}
//跟踪一下这个AcceptSocket函数
QuicSocketEntryPtr QuicSocketEntry::AcceptSocket()
{
//还是先判断一下状态
if (socketState_ != QuicSocketState_Binded) {
errno = EINVAL;
return QuicSocketEntryPtr();
}
std::unique_lock<std::mutex> lock(acceptSocketsMtx_);
if (acceptSockets_.empty()) {//判断是否为空
errno = EAGAIN;
return QuicSocketEntryPtr();
}
auto ptr = acceptSockets_.front();//返回这个列表的第一个元素
acceptSockets_.pop_front();
return ptr;
}
auto ptr = acceptSockets_.front();//返回这个列表的第一个元素
//返回这个列表的第一个元素
// element access
/**
* Returns a read/write reference to the data at the first
* element of the %list.
*/
reference
front() _GLIBCXX_NOEXCEPT
{ return *begin(); }
/**
* Returns a read-only (constant) reference to the data at the first
* element of the %list.
*/
const_reference
front() const _GLIBCXX_NOEXCEPT
{ return *begin(); }
acceptSockets_.pop_front();
/**
* @brief Removes first element.
*
* This is a typical stack operation. It shrinks the %list by
* one. Due to the nature of a %list this operation can be done
* in constant time, and only invalidates iterators/references to
* the element being removed.
*
* Note that no data is returned, and if the first element's data
* is needed, it should be retrieved before pop_front() is
* called.
*/
void
pop_front() _GLIBCXX_NOEXCEPT
{ this->_M_erase(begin()); }
/**
* @brief Add data to the end of the %list.
* @param __x Data to be added.
*
* This is a typical stack operation. The function creates an
* element at the end of the %list and assigns the given data to
* it. Due to the nature of a %list this operation can be done
* in constant time, and does not invalidate iterators and
* references.
*/
void
push_back(const value_type& __x)
{ this->_M_insert(end(), __x); }
类似于出栈操作