本文整理汇总了C++中CTcpSocket::Retain方法的典型用法代码示例。如果您正苦于以下问题:C++ CTcpSocket::Retain方法的具体用法?C++ CTcpSocket::Retain怎么用?C++ CTcpSocket::Retain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CTcpSocket
的用法示例。
在下文中一共展示了CTcpSocket::Retain方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_inter_listen_accept
void CTcpSocket::on_inter_listen_accept(evutil_socket_t listenfd)
{
socketaddr acceptaddr;
ev_socklen_t addrlen = sizeof(acceptaddr);
evutil_socket_t newfd = ::accept(listenfd, (struct sockaddr*)&acceptaddr, &addrlen);
if (newfd == INVALID_SOCKET)
{
XH_LOG_ERROR(logname_base, "[id:" << m_id << "] tcpsocket listener::accept failed, ip:" << m_localip << ", port : " << m_localport);
return;
}
CTcpSocket* newsocket = CTcpSocket::Create();
if (!newsocket)
{
closetcpsocket(newfd);
return;
}
XH_GUARD([&]{newsocket->Release(); });
m_lcb->On_Accept(GetSocketID(), newsocket);
if (newsocket->m_io && newsocket->m_type == type_accepter)
{
std::string peerip;
unsigned int peerport = 0;
sockaddr2ipport(&acceptaddr, addrlen, peerip, peerport);
newsocket->Retain();
newsocket->m_io->Post(std::bind(&CTcpSocket::on_inter_accept_accept, newsocket, newfd, peerip, peerport));
}
else
{
closetcpsocket(newfd);
switch (newsocket->m_type)
{
case type_listener:
if (newsocket->m_lcb)
{
newsocket->m_lcb->Release();
newsocket->m_lcb = 0;
}
break;
case type_accepter:
if (newsocket->m_acb)
{
newsocket->m_acb->Release();
newsocket->m_acb = 0;
}
break;
case type_connecter:
if (newsocket->m_ccb)
{
newsocket->m_ccb->Release();
newsocket->m_ccb = 0;
}
break;
default:
break;
}
XH_LOG_ERROR(logname_base, "[id:" << m_id << "] tcpsocket listener ITcpSocketCB::On_Accept failed or not be accepted by user, ip:" << m_localip << ", port : " << m_localport);
}
}