当前位置: 首页>>代码示例>>C++>>正文


C++ SockAddr::GetIP方法代码示例

本文整理汇总了C++中SockAddr::GetIP方法的典型用法代码示例。如果您正苦于以下问题:C++ SockAddr::GetIP方法的具体用法?C++ SockAddr::GetIP怎么用?C++ SockAddr::GetIP使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SockAddr的用法示例。


在下文中一共展示了SockAddr::GetIP方法的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;
}
开发者ID:singmelody,项目名称:Test,代码行数:52,代码来源:NetChannelBase.cpp

示例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;
}
开发者ID:singmelody,项目名称:Test,代码行数:38,代码来源:NetChannelBase.cpp

示例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);
		}
	}
}
开发者ID:singmelody,项目名称:Test,代码行数:65,代码来源:NetManager.cpp


注:本文中的SockAddr::GetIP方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。