本文整理汇总了C++中SockAddr::GetPort方法的典型用法代码示例。如果您正苦于以下问题:C++ SockAddr::GetPort方法的具体用法?C++ SockAddr::GetPort怎么用?C++ SockAddr::GetPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SockAddr
的用法示例。
在下文中一共展示了SockAddr::GetPort方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FlushStream
bool NetChannelBase::FlushStream()
{
bool bError = false;
while (m_StreamOut.GetSize() > 0)
{
int32 nLen = (int32)m_StreamOut.GetSize();
int32 nRet = m_socket.Send((char*)m_StreamOut.GetBufferStart(), nLen);
if( nRet < 0 )
{
int32 nError = Socket::GetSysError();
if( nError == MY_EWOULDBLOCK || nError == MY_EAGAIN )
break;
else if( nError == MY_ECONNRESET )
nRet = 0;
else
{
SockAddr addr;
m_socket.GetSockAddr(addr);
MyLog::error("[%s:%u] IO Error [%d] when sending data !", addr.GetIP().c_str(), addr.GetPort(), GetID(), nError);
DisConnect();
nError = true;
break;
}
}
if( nRet == 0 )
{
SockAddr addr;
m_socket.GetPeerAddr(addr);
MyLog::error("NetChannelBase::flushStream() [%s:%u][%u] connection is closed!", addr.GetIP().c_str(), addr.GetPort(), GetID());
DisConnect();
bError = true;
break;
}
m_pMgr->BytesSend().Add(nRet);
m_StreamOut.Remove(nRet);
m_nTotalSendByte += nRet;
if( nRet < nLen )
break;
}
return !bError;
}
示例2: RecvData
int32 NetChannelBase::RecvData(char* buffer, int32 nLen)
{
int32 nRet = m_socket.Recv( buffer, nLen, 0);
if(nRet < 0)
{
int32 nError = Socket::GetSysError();
if( MY_EWOULDBLOCK == nError || MY_EAGAIN == nError )
return 0;
else if( MY_ECONNRESET == nError )
{
SockAddr addr;
m_socket.GetPeerAddr(addr);
MyLog::error("NetChannelBase::recvData() [%s:%u][%u] An existing connection was forcibly closed by thre remote host!", addr.GetIP().c_str(), addr.GetPort(), GetID());
return -1;
}
else
{
SockAddr addr;
m_socket.GetSockAddr(addr);
MyLog::error("[%s:%u][%u] IO error [%d] when sending data !",
addr.GetIP().c_str(), addr.GetPort(), GetID(), nError);
return -1;
}
}
if(nRet == 0)
{
SockAddr addr;
m_socket.GetPeerAddr(addr);
MyLog::error("NetChannelBase::recvData() [%s:%u][%u] remote connection is closed!",
addr.GetIP().c_str(), addr.GetPort(), GetID());
return -1;
}
m_pMgr->BytesRecv().Add(nRet);
return nRet;
}
示例3: ProcNewConnection
void NetManager::ProcNewConnection()
{
std::deque<NetChannelBase*> tmpQueue;
{
AUTOLOCK( m_mutexChannels);
tmpQueue.swap(m_newSocketQueue);
}
while (!tmpQueue.empty())
{
NetChannelBase* pChannel = tmpQueue.front();
assert( pChannel);
int32 nSocketID = AddChannel( pChannel );
if(nSocketID < 0)
{
// channel list is full , can't add another one
MyLog::warning("NetManager::ProcNewConnection() socket list is full");
break;
}
pChannel->StartChannel();
OnChannelStart( pChannel );
if(pChannel->m_bCreateByAccept)
{
if(m_AcceptCallBack)
(*m_AcceptCallBack)(nSocketID);
}
else
{
if(m_ConnectCallBack)
(*m_ConnectCallBack)(nSocketID);
}
tmpQueue.pop_front();
if(pChannel->m_hProcNewNotify.IsValid())
pChannel->m_hProcNewNotify.SetEvent();
FreeChannel( pChannel );
}
// failed process
while (!tmpQueue.empty())
{
NetChannelBase* pChannel = tmpQueue.front();
tmpQueue.pop_front();
assert(pChannel);
if(pChannel->m_hProcNewNotify.IsValid())
{
AUTOLOCK(m_mutexChannels);
m_newSocketQueue.push_back( pChannel );
}
else
{
SockAddr addr;
pChannel->GetAddr( addr );
MyLog::warning("NetManager::ProcNewConnection() drop new socket (%s:%d)", addr.GetIP().c_str(), addr.GetPort());
FreeChannel(pChannel);
}
}
}