From: Markus R. <rol...@us...> - 2007-02-23 19:25:08
|
Update of /cvsroot/simspark/simspark/spark/oxygen/simulationserver In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv6305 Modified Files: Tag: WIN32 netcontrol.cpp netcontrol.h Log Message: - refactor RemoveClient() implementation - rename SendMessage to SendClientMessage. windows.h already #define SendMessage - use Socket::SocketDesc typedef consistently instead of 'int' to describe a socket handle Index: netcontrol.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/simulationserver/netcontrol.h,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** netcontrol.h 24 May 2006 10:07:10 -0000 1.2 --- netcontrol.h 23 Feb 2007 19:25:00 -0000 1.2.2.1 *************** *** 113,122 **** /** sends a message to the given client */ ! void SendMessage(boost::shared_ptr<Client> client, ! const std::string& msg); /** sends a message to the client with the given address */ ! void SendMessage(const rcss::net::Addr& addr, ! const std::string& msg); /** create a socket according to the given ESocketType */ --- 113,122 ---- /** sends a message to the given client */ ! void SendClientMessage(boost::shared_ptr<Client> client, ! const std::string& msg); /** sends a message to the client with the given address */ ! void SendClientMessage(const rcss::net::Addr& addr, ! const std::string& msg); /** create a socket according to the given ESocketType */ *************** *** 162,165 **** --- 162,168 ---- void RemoveClient(const rcss::net::Addr& from); + /** removes a client entry and closes the associated socket. */ + void RemoveClient(TAddrMap::iterator iter); + /** removes all clients marked in the mCloseClients list */ void CloseDeadConnections(); Index: netcontrol.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/simulationserver/netcontrol.cpp,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** netcontrol.cpp 10 Feb 2007 18:59:51 -0000 1.1.2.2 --- netcontrol.cpp 23 Feb 2007 19:25:00 -0000 1.1.2.3 *************** *** 212,223 **** // close all client connections ! for ( ! TAddrMap::iterator iter = mClients.begin(); ! iter != mClients.end(); ! ++iter ! ) ! { ! RemoveClient((*iter).second->addr); ! } // shutdown the server socket --- 212,219 ---- // close all client connections ! while (! mClients.empty()) ! { ! RemoveClient(mClients.begin()); ! } // shutdown the server socket *************** *** 227,231 **** << DescribeSocketType() << std::endl; mSocket.reset(); - mClients.clear(); } --- 223,226 ---- *************** *** 248,264 **** } ! void NetControl::RemoveClient(const Addr& from) { ! TAddrMap::iterator mapIter = mClients.find(from); ! ! if (mapIter == mClients.end()) ! { ! GetLog()->Warning() ! << "(NetControl) '" << GetName() ! << "' RemoveClient called with an unknown client address\n"; ! return; ! } ! ! shared_ptr<Client> client = (*mapIter).second; ClientDisconnect(client); --- 243,249 ---- } ! void NetControl::RemoveClient(TAddrMap::iterator iter) { ! shared_ptr<Client> client = (*iter).second; ClientDisconnect(client); *************** *** 269,273 **** << ((socket.get() != 0) ? "TCP" : "UDP") << " connection from '" ! << from.getHostStr() << ":" << from.getPort() << "' id " << client->id << endl; --- 254,258 ---- << ((socket.get() != 0) ? "TCP" : "UDP") << " connection from '" ! << client->addr.getHostStr() << ":" << client->addr.getPort() << "' id " << client->id << endl; *************** *** 277,281 **** } ! mClients.erase(mapIter); } --- 262,281 ---- } ! mClients.erase(iter); ! } ! ! void NetControl::RemoveClient(const Addr& from) ! { ! TAddrMap::iterator mapIter = mClients.find(from); ! ! if (mapIter == mClients.end()) ! { ! GetLog()->Warning() ! << "(NetControl) '" << GetName() ! << "' RemoveClient called with an unknown client address\n"; ! return; ! } ! ! RemoveClient(mapIter); } *************** *** 290,294 **** } ! void NetControl::SendMessage(shared_ptr<Client> client, const string& msg) { if (client.get() == 0) --- 290,294 ---- } ! void NetControl::SendClientMessage(shared_ptr<Client> client, const string& msg) { if (client.get() == 0) *************** *** 322,326 **** } ! void NetControl::SendMessage(const Addr& addr, const string& msg) { TAddrMap::iterator iter = mClients.find(addr); --- 322,326 ---- } ! void NetControl::SendClientMessage(const Addr& addr, const string& msg) { TAddrMap::iterator iter = mClients.find(addr); *************** *** 334,338 **** } ! SendMessage((*iter).second,msg); } --- 334,338 ---- } ! SendClientMessage((*iter).second,msg); } *************** *** 359,363 **** for(;;) { ! int ret = select(fd+1, &readfds, 0, 0, &time); if (ret == 0) --- 359,370 ---- for(;;) { ! #ifdef WIN32 ! // maxFd is ignored on Win32 and is present just for api compatibility ! int maxFd = 0; ! #else ! int maxFd = fd + 1; ! #endif ! ! int ret = select(maxFd, &readfds, 0, 0, &time); if (ret == 0) *************** *** 486,490 **** } ! int fd = mSocket->getFD(); fd_set readfds; --- 493,497 ---- } ! Socket::SocketDesc fd = mSocket->getFD(); fd_set readfds; *************** *** 498,502 **** for(;;) { ! int ret = select(fd+1, &readfds, 0, 0, &time); if (ret == 0) --- 505,516 ---- for(;;) { ! #ifdef WIN32 ! // maxFd is ignored on Win32 and is present just for api compatibility ! int maxFd = 0; ! #else ! int maxFd = fd + 1; ! #endif ! ! int ret = select(maxFd, &readfds, 0, 0, &time); if (ret == 0) *************** *** 542,545 **** --- 556,564 ---- void NetControl::ReadTCPMessages() { + if (mClients.empty()) + { + return; + } + // generate a set of client socket fds fd_set client_fds; *************** *** 554,559 **** ) { ! const int fd = (*iter).second->socket->getFD(); maxFd = std::max<int>(fd,maxFd); FD_SET(fd,&client_fds); } --- 573,583 ---- ) { ! const Socket::SocketDesc fd = (*iter).second->socket->getFD(); ! #ifdef WIN32 ! // maxFd is ignored for Win32 ! maxFd = 0; ! #else maxFd = std::max<int>(fd,maxFd); + #endif FD_SET(fd,&client_fds); } *************** *** 592,596 **** ) { ! const int fd = (*iter).second->socket->getFD(); if (! FD_ISSET(fd, &test_fds)) { --- 616,620 ---- ) { ! const Socket::SocketDesc fd = (*iter).second->socket->getFD(); if (! FD_ISSET(fd, &test_fds)) { *************** *** 607,611 **** } else { ! if (rval < 0) { GetLog()->Error() --- 631,635 ---- } else { ! if (rval <= 0) { GetLog()->Error() *************** *** 613,622 **** << "' recv returned error on a client socket '" << strerror(errno) << "' " << endl; - continue; } - // (rval==0) indicates a close() on - // the client side - // mark the client connection to be // closed and exclude it from further --- 637,642 ---- |