本文整理汇总了C++中Session::GetSocket方法的典型用法代码示例。如果您正苦于以下问题:C++ Session::GetSocket方法的具体用法?C++ Session::GetSocket怎么用?C++ Session::GetSocket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session::GetSocket方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connect
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: GETSESSIONPOOL
void
Static::Accept()
{
Session * pSession = GETSESSIONPOOL()->NEW();
m_Acceptor.async_accept(pSession->GetSocket(),
boost::bind(&Static::OnSessionOpen, this, pSession, boost::asio::placeholders::error)
);
}
示例3: HandleWoWPacket
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: connect_thread
//=============================================================================================================================
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: OnRead
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;
}
}
}