#include <CMultiServer.h>
Public Member Functions | |
| bool | addSocket (CSocket *inSocket) |
| void | serve () |
Protected Attributes | |
| list< CSocket * > | mSockets |
| map< int, CSocket * > | mDescriptorToSocket |
Definition at line 34 of file CMultiServer.h.
a Server that serves multiple sockets at the same time
Definition at line 5 of file CMultiServer.cc.
References mDescriptorToSocket, and mSockets.
Referenced by main().
00005 { 00006 if(inSocket && bool(*inSocket)){ 00007 mSockets.push_back(inSocket); 00008 mDescriptorToSocket[mSockets.back()->getSocketDescriptor()]= 00009 mSockets.back(); 00010 return 1; 00011 }else{ 00012 return 0; 00013 } 00014 };
| void CMultiServer::serve | ( | ) |
start serving these sockets
Definition at line 16 of file CMultiServer.cc.
References mSockets.
Referenced by main().
00016 { 00017 for(;;) { 00018 00019 fd_set lReadFileDescriptors; 00020 FD_ZERO(&lReadFileDescriptors); 00021 int lMax(0); 00022 for(list<CSocket*>::iterator i=mSockets.begin(); 00023 i!=mSockets.end(); 00024 i++){ 00025 00026 FD_SET(((*i)->getSocketDescriptor()),&lReadFileDescriptors); 00027 00028 if((*i)->getSocketDescriptor()>lMax){ 00029 lMax=(*i)->getSocketDescriptor(); 00030 } 00031 } 00032 00033 int done, n; 00034 cout << "Waiting for connection..." << endl; 00035 00036 int lReturnValue = select(lMax+1, &lReadFileDescriptors, NULL, NULL, NULL); 00037 00038 cout << "...select" << endl; 00039 00040 for(list<CSocket*>::iterator i=mSockets.begin(); 00041 i!=mSockets.end(); 00042 i++){ 00043 if(FD_ISSET(((*i)->getSocketDescriptor()), 00044 &lReadFileDescriptors)){ 00045 try{ 00046 cerr << "trying to accept " << (*i)->getSocketDescriptor() << " " << bool(**i) << endl; 00047 if(**i){ 00048 (*i)->acceptAndServe(); 00049 } 00050 }catch(const char*){ 00051 cerr << "Accept failed, exception caught" << endl; 00052 } 00053 } 00054 } 00055 cout << "endfor " << endl; 00056 } 00057 }
list<CSocket*> CMultiServer::mSockets [protected] |
a list containing domain sockets
Definition at line 37 of file CMultiServer.h.
Referenced by addSocket(), and serve().
map<int,CSocket*> CMultiServer::mDescriptorToSocket [protected] |
find for a given file descriptor the socket
Definition at line 39 of file CMultiServer.h.
Referenced by addSocket().
1.5.6