コード例 #1
0
ファイル: Connector.cpp プロジェクト: hujb1983/OldGame
void * connect_thread(void * param)
{
	printf ( "--->connect_thread 0x%x \n", pthread_self() );
	
	Connector	* pClass = (Connector *) param;
	Session 	* pSession;
	
	while (true)
	{
		sem_wait( &pClass->m_semConnect );
		//printf("After sem_wait.Begin to handle ConnectingList \n");
		if ( pClass->m_bShutdown )
		{
			printf ( "\n connect_thread 0x%x exit \n", pthread_self() );
			pthread_exit (NULL);
		}
		
		while ( !pClass->m_pConnectingList->empty() ) 
		{
			if ( pClass->m_bShutdown )
			{
				printf ( "\n connect_thread 0x%x exit \n", pthread_self() );
				pthread_exit (NULL);
			}
			
			pClass->m_pConnectingList->Lock();
			pSession = pClass->m_pConnectingList->front();
			pClass->m_pConnectingList->pop_front();
			pClass->m_pConnectingList->Unlock();
			
			int err = connect( pSession->GetSocket(), (SOCKADDR*)( pSession->GetSockAddr() ),sizeof(SOCKADDR_IN));
			
			if (err == SOCKET_ERROR)
			{
				//printf ( "connect fail, errno = %d\n", errno );
				
				pClass->m_pSync->m_pConnectFailList->Lock();
				pClass->m_pSync->m_pConnectFailList->push_back( pSession );			
				pClass->m_pSync->m_pConnectFailList->Unlock();
			}
			else 
			{
				printf("connect success\n");
				SocketOpt::Nonblocking( pSession->GetSocket() );
				SocketOpt::DisableBuffering( pSession->GetSocket() );

				pClass->m_pSync->m_pConnectSuccessList->Lock();
				pClass->m_pSync->m_pConnectSuccessList->push_back( pSession );			
				pClass->m_pSync->m_pConnectSuccessList->Unlock();
			}
		}
	}
}
コード例 #2
0
ファイル: Static.cpp プロジェクト: truelsy/iEngine
void
Static::Accept()
{
	Session * pSession = GETSESSIONPOOL()->NEW();

	m_Acceptor.async_accept(pSession->GetSocket(),
			boost::bind(&Static::OnSessionOpen, this, pSession, boost::asio::placeholders::error)
	);
}
コード例 #3
0
ファイル: WorkerServer.cpp プロジェクト: Goatform/ascent
void WServer::HandleWoWPacket(WorldPacket & pck)
{
	uint32 sessionid, size;
	uint16 opcode;

	/* get session */
	pck >> sessionid >> opcode >> size;
	Session * session = sClientMgr.GetSession(sessionid);
	if(!session) return;

	/* write it to that session's output buffer */
	WorldSocket * s = session->GetSocket();
	if(s) s->OutPacket(opcode, size, size ? ((const void*)(pck.contents() + 10)) : 0);
}
コード例 #4
0
ファイル: Connector.cpp プロジェクト: fallenbird/MolyDB
//=============================================================================================================================
unsigned __stdcall connect_thread( LPVOID param )
{
	Connector	*pClass = (Connector*)param;
	Session		*pSession;

	while( !pClass->m_bShutdown )
	{
		DWORD dwRet = WaitForMultipleObjects( 2, pClass->m_hEvent, FALSE, INFINITE );

		if( dwRet - WAIT_OBJECT_0 == 0 )
		{
			// 
			while( !pClass->m_pConnectingList->empty() )
			{
				//
				pClass->m_pConnectingList->Lock();				
				pSession = pClass->m_pConnectingList->front();
				pClass->m_pConnectingList->pop_front();
				pClass->m_pConnectingList->Unlock();

				// 
				int err = connect( pSession->GetSocket(), (SOCKADDR*)( pSession->GetSockAddr() ), sizeof(SOCKADDR_IN) );
								   
				if( err == SOCKET_ERROR )
				{
					// 
					int x = WSAGetLastError();
					pClass->m_pIoHandler->m_pConnectFailList->Lock();
					pClass->m_pIoHandler->m_pConnectFailList->push_back( pSession );
					pClass->m_pIoHandler->m_pConnectFailList->Unlock();
				}
				else
				{
					// 
					pClass->m_pIoHandler->m_pConnectSuccessList->Lock();
					pClass->m_pIoHandler->m_pConnectSuccessList->push_back( pSession );
					pClass->m_pIoHandler->m_pConnectSuccessList->Unlock();
				}
			}
		}
		else if( dwRet - WAIT_OBJECT_0 == 1 )
		{
			//
			break;
		}
	}

	return 0;
}
コード例 #5
0
void WSSocket::OnRead()
{
    for(;;)
	{
		if(!_cmd)
		{
			if(readBuffer.GetSize() < 6)
				break;

			readBuffer.Read(&_cmd, 2);
			readBuffer.Read(&_remaining, 4);
		}

        if(_remaining && readBuffer.GetSize() < _remaining)
			break;

		if(_cmd == ICMSG_WOW_PACKET)
		{
			uint32 sid;
			uint16 op;
			uint32 sz;


			GetReadBuffer().Read(&sid, 4);
			GetReadBuffer().Read(&op, 2);
			GetReadBuffer().Read(&sz, 4);

			Session * session = sClientMgr.GetSession(sid);
			if(session != NULL && session->GetSocket() != NULL)
			{
				uint8* buf = new uint8[sz];
				GetReadBuffer().Read(buf, sz);
				session->GetSocket()->OutPacket(op, sz, buf);
				delete [] buf;
			}
			else
				GetReadBuffer().Remove(sz);

			_cmd = 0;

			continue;
		}
		WorldPacket * pck = new WorldPacket(_cmd, _remaining);
		_cmd = 0;
		pck->resize(_remaining);
		readBuffer.Read((uint8*)pck->contents(), _remaining);

		if(_authenticated)
		{
			// push to queue
			if(!_ws)
			{
				if(pck->GetOpcode() == ICMSG_REGISTER_WORKER)
				{
					// handle register worker
					HandleRegisterWorker(*pck);
				}

				/* I deliberately don't delete pck here for a reason :P */
			}
			else
			{
				_ws->QueuePacket(pck);
			}
		}
		else
		{
			if(pck->GetOpcode() != ICMSG_AUTH_REPLY)
				Disconnect();
			else
				HandleAuthRequest(*pck);
			
			delete pck;
		}
	}
}