本文整理汇总了C++中TCPSocket::pollRead方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPSocket::pollRead方法的具体用法?C++ TCPSocket::pollRead怎么用?C++ TCPSocket::pollRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPSocket
的用法示例。
在下文中一共展示了TCPSocket::pollRead方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
void ConnectionManagerIn::execute(void * arg)
{
ConnectionManagerIn * pthis = (ConnectionManagerIn *)arg;
flog<<"Connection manager In Init...\n";
TCPSocket * socket;
event_data_t event_data;
try
{
socket = pthis->cli->getClient()->getSocket();
}
catch (vortex::Exception * e)
{
printf("%s\n",e->what());
flog <<"Cli init:"<<e->what()<<endl;
delete e;
}
char * buffer = (char *)malloc(5);
try
{
if (socket->pollRead())
socket->recv(buffer,5,0);
LoginResponsePacket lrp(buffer,(size_t)5);
if (lrp.getHeader().length()>0)
flog << "Yay got a positive response!\n";
else
flog << "login failed!\n";
}
catch (vortex::Exception * e)
{
flog << "what 1"<<e->what()<<endl;
//Soit Mauvais paquet
//Soit timeout du socket
}
free(buffer);
//LOGIN OK!
//On peux rentrer dans la boucle principale de protocole
while (1)
{
flog << "Main LOOP!\n";
try
{
//D'abord on checks si il y a des donnees a lire avec select
flog << "POLL successful!\n";
char * buffer = (char *)malloc(5);
socket->recv(buffer,5,0);
bitBuffer header(buffer,5);
flog << "Type:" <<(int)header.readChar(false)<<endl;
switch (header.readChar(false))
{
case event_connect_login:
flog << "login" << endl;
break;
case event_connect_logout:
flog << "logout" << endl;
break;
case event_world_add:
flog << "add" << endl;
break;
case event_world_update:
flog << "update" << endl;
break;
case event_world_del:
flog << "del" << endl;
break;
case event_chat_incoming:
flog << "chat" << endl;
break;
}
free(buffer);
}
catch (vortex::Exception * e)
{
flog << "what2"<<e->what()<<endl;
delete e;
}
//Apres on check les events:
}
flog << "main loop end\n";
}