Example #1
0
 void IpPool::DisConnectAll()
 {
     for (std::map<protocol::SocketAddr, CandidatePeer::p>::iterator iter = candidate_peers_.begin();
         iter != candidate_peers_.end(); ++iter)
     {
         boost::asio::ip::udp::endpoint endpoint = framework::network::Endpoint(iter->first.IP, iter->first.Port);
         OnDisConnect(endpoint, true);
     }
 }
Example #2
0
	void CServerSocket::FreeClient( CCustomClientSocket * ClientSocket )
	{
		Lock();
		m_SessionMap[m_wCurrentHandle] = NULL;
		for(ClientListIter iter = m_ActiveClientSocketList.begin();iter != m_ActiveClientSocketList.end();iter++)
		{
			if (*iter = ClientSocket)
			{
				m_ActiveClientSocketList.erase(iter);
				m_iClientCount--;
				m_FreeClientPool.Append(ClientSocket);
				if(ClientSocket->GetSocket()!=INVALID_SOCKET)
				{
					ClientSocket->ForceClose();

				}
				OnDisConnect((CCustomSocket*)ClientSocket);
				ClientSocket->Finalize();
				return;
			}
		}
	  Unlock();
	}
Example #3
0
/*-----------------------------------------------------------------
【函数介绍】: 向服务器端发送数据
【入口参数】: buf:待发送的数据
dwBufLen:待发送的数据长度
【出口参数】: (无)
【返回  值】: TRUE:发送数据成功;FALSE:发送数据失败
------------------------------------------------------------------*/
BOOL CTCPClient_CE::SendData(const char * buf , DWORD dwBufLen)
{
    int nBytes = 0;
    int nSendBytes=0;

    while (nSendBytes < dwBufLen)
    {
        nBytes = send(m_socket,buf+nSendBytes,dwBufLen-nSendBytes,0);
        if (nBytes==SOCKET_ERROR )
        {
            int iErrorCode = WSAGetLastError();
            //触发socket的Error事件
            if (OnError)
            {
                OnError(m_pOwner,iErrorCode);
            }
            //触发与服务器端断开连接事件
            if (OnDisConnect)
            {
                OnDisConnect(m_pOwner);
            }
            //关闭socket
            Close();
            return FALSE;
        }

        //累计发送的字节数
        nSendBytes = nSendBytes + nBytes;

        if (nSendBytes < dwBufLen)
        {
            Sleep(1000);
        }
    }
    return TRUE;
}