Changeset 7540 in orxonox.OLD for branches/network/src/lib
- Timestamp:
- May 5, 2006, 3:16:09 PM (19 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 8 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/Makefile.am
r7444 r7540 13 13 network_protocol.cc \ 14 14 server_socket.cc \ 15 tcp_server_socket.cc \ 16 tcp_socket.cc \ 17 udp_server_socket.cc \ 18 udp_socket.cc \ 15 19 handshake.cc \ 16 20 network_game_manager.cc \ … … 38 42 network_protocol.h \ 39 43 server_socket.h \ 44 tcp_server_socket.h \ 45 tcp_socket.h \ 46 udp_server_socket.h \ 47 udp_socket.h \ 40 48 handshake.h \ 41 49 network_game_manager.h \ -
branches/network/src/lib/network/network_manager.cc
r7256 r7540 90 90 int NetworkManager::establishConnection(const std::string & name, unsigned int port) 91 91 { 92 IPaddress ipAddress; 93 int error = SDLNet_ResolveHost(&ipAddress, name.c_str(), port); 94 if( error == -1) { 95 printf("\n\nerror on address resolution, program inconsistency\n\n"); 96 return -1; 97 } 98 99 this->defaultSyncStream = new NetworkStream(ipAddress); 92 this->defaultSyncStream = new NetworkStream( name, port ); 100 93 this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream); 101 94 this->defaultSyncStream->startHandshake(); -
branches/network/src/lib/network/network_socket.cc
r6994 r7540 21 21 #define DEBUG_MODULE_NETWORK 22 22 23 #include "converter.h"24 25 23 /* include your own header */ 26 24 #include "network_socket.h" … … 34 32 NetworkSocket::NetworkSocket() 35 33 { 36 this->init();34 bOk = true; 37 35 } 38 36 39 /** 40 * Constructor to connect directly 41 */ 42 NetworkSocket::NetworkSocket(IPaddress ip) 37 NetworkSocket::~ NetworkSocket( ) 43 38 { 44 this->init();45 connectToServer(ip);46 }47 48 49 NetworkSocket::NetworkSocket( TCPsocket sock )50 {51 this->init();52 this->tcpSocket = sock;53 54 readThread = SDL_CreateThread(thread_read, (void*)this);55 writeThread = SDL_CreateThread(thread_write, (void*)this);56 }57 58 void NetworkSocket::init()59 {60 /* set the class id for the base object */61 this->setClassID(CL_NETWORK_SOCKET, "NetworkSocket");62 63 tcpSocket = NULL;64 incomingBufferLength = 0;65 outgoingBufferLength = 0;66 67 readThread = NULL;68 writeThread = NULL;69 70 71 thread_write_running = false;72 thread_read_running = false;73 74 incomingBufferMutex = SDL_CreateMutex();75 outgoingBufferMutex = SDL_CreateMutex();76 77 78 socketMutex = SDL_CreateMutex();79 terminateThread = false;80 81 /* Init SDL_net */82 //NOTE: do we need to call SDLNet_Init for all instances?83 if(SDLNet_Init()==-1)84 {85 PRINTF(1)("SDLNet_Init: %s\n", SDLNet_GetError());86 return;87 }88 else89 PRINTF(5)("SDL_net initialized\n");90 91 PRINTF(0)("NetworkSocket created\n");92 93 39 } 94 40 95 41 96 42 97 /**98 * Default destructor99 * dont use this from outside: use destroy() instead!!100 */101 NetworkSocket::~NetworkSocket( )102 {103 this->terminateThread = true;104 /* Quit SDL_net */105 // NOTE: what if other instances of NetworkSocket running?106 SDLNet_Quit();107 PRINTF(5)("SDL_net shutdown\n");108 109 SDL_DestroyMutex(incomingBufferMutex);110 SDL_DestroyMutex(outgoingBufferMutex);111 SDL_DestroyMutex(socketMutex);112 SDL_DestroyMutex(threadTerminationMutex);113 }114 115 /**116 * This function establishes a TCP/UDP connection to a given server (function argument).117 * It is called by the NetworkStream. It creates a TCP/UDP socket for the connection.118 * @param ip119 */120 void NetworkSocket::connectToServer(IPaddress ip)121 {122 //check if not already connected or listening123 if (tcpSocket)124 {125 PRINTF(1)("NetworkSocket::listen: tcpSocket!=NULL! maybe you already called listen or connectToServer or did not call disconnectServer()!");126 }127 128 /* Connect to the host and port contained in ip using a TCP connection. */129 tcpSocket = SDLNet_TCP_Open(&ip);130 if(!tcpSocket)131 {132 PRINTF(1)("SDLNet_TCP_Open: %s\n", SDLNet_GetError());133 return;134 }135 136 readThread = SDL_CreateThread(thread_read, (void*)this);137 writeThread = SDL_CreateThread(thread_write, (void*)this);138 }139 43 140 44 141 /**142 * DTears down a TCP/UDP connection.143 */144 void NetworkSocket::disconnectServer( )145 {146 terminateThread = true;147 /* Close the connection */148 149 SDL_mutexP(socketMutex);150 SDLNet_TCP_Close(tcpSocket);151 tcpSocket = NULL;152 SDL_mutexV(socketMutex);153 }154 155 156 /**157 * This function writes some bytes (data) to the network connection (if the connection is already158 * estabilhed) otherwise it just does nothing (silently discarding the data). And writes some159 * warnings160 * @param data: pointer to the data to send161 * @param length: n bytes to send162 * @return the number successfully written bytes163 */164 int NetworkSocket::writeBytes(byte * data, int length)165 {166 PRINTF(5)("NetworkSocket::writeBytes()\n");167 #ifdef _USE_OUTGOING_BUFFER168 169 #define min(a,b) (a<b)?a:b170 int nbytes = min(_OUTGOING_BUFFER_SIZE - outgoingBufferLength, length);171 #undef min172 173 if (!tcpSocket || data==NULL || nbytes<=0)174 {175 assert(_OUTGOING_BUFFER_SIZE - outgoingBufferLength > 0);176 return 0;177 }178 179 SDL_mutexP(outgoingBufferMutex);180 181 memcpy(outgoingBuffer + outgoingBufferLength, data, nbytes);182 outgoingBufferLength += nbytes;183 184 SDL_mutexV(outgoingBufferMutex);185 186 187 return nbytes;188 #else189 SDL_mutexP(socketMutex);190 191 if (!tcpSocket || data==NULL)192 return 0;193 194 int res = SDLNet_TCP_Send(tcpSocket, data, length);195 196 SDL_mutexV(socketMutex);197 198 if (res<length)199 PRINTF(1)("SDLNet_TCP_Send: %s\n", SDLNet_GetError());200 201 return res;202 #endif203 }204 205 /**206 * Reads in the bytes from the network interface and passes it to the NetworkStream.207 * This function must internaly be implemented/connected as a thread, since the read208 * functions of many network libraries are blocking an would therefore block the whole209 * program.210 * From outside, the thread shouldn't be accessible at all.211 * @param data: pointer to memory, big enough to store length bytes212 * @param length: n bytes to read213 * @return the number successfully read bytes. -1 on error. may be less than length!214 */215 int NetworkSocket::readBytes(byte * data, int length)216 {217 PRINTF(5)("NetworkSocket::readBytes()\n");218 if (data==NULL)219 return 0;220 221 int nbytes = (length<incomingBufferLength) ? length : incomingBufferLength;222 223 224 //printf("readBytes: nbytes = %d; length=%d; incomingBufferLength=%d\n", nbytes, length, incomingBufferLength);225 226 // just in case ...227 if (nbytes<0)228 return -1;229 230 if (nbytes==0)231 return 0;232 233 SDL_mutexP(incomingBufferMutex);234 235 memcpy(data, incomingBuffer, nbytes);236 237 //important: use memmove because the memory areas may overlap238 memmove(incomingBuffer, incomingBuffer+nbytes, incomingBufferLength-nbytes);239 incomingBufferLength -= nbytes;240 241 SDL_mutexV(incomingBufferMutex);242 243 return nbytes;244 }245 246 /**247 * Reads in the bytes form the network interface and passes it to the NetworkStream.248 * It only reads the bytes if there are enough bytes in our buffer.249 * @param data: pointer to memory, big enough to store length bytes250 * @param length: n bytes to read251 * @return the number successfully read bytes. -1 on error. 0 if there are not enough bytes in our buffer.252 */253 int NetworkSocket::readBlock(byte * data, int length)254 {255 printf("NetworkSocket: got %i bytes, NetworkStream requested %i bytes\n", this->incomingBufferLength, length);256 if (incomingBufferLength >= length)257 return readBytes(data, length);258 else return 0;259 }260 261 262 /**263 * used to create a thread to read from socket264 * @param data: pointer to NetworkSocket265 */266 int NetworkSocket::thread_read( void * data )267 {268 int nbytesread = 0;269 int nbytestoread = 0;270 char buffer[_LOCAL_BUFFER_SIZE];271 NetworkSocket * self = (NetworkSocket*)data;272 273 self->thread_read_running = true;274 275 while (!self->terminateThread)276 {277 #define min(a,b) (a<b)?a:b278 nbytestoread = min(_INCOMING_BUFFER_SIZE - self->incomingBufferLength, _LOCAL_BUFFER_SIZE);279 #undef min280 281 //if buffer is full282 if (nbytestoread<=0 || !self->tcpSocket)283 {284 SDL_Delay(_MSECONDS_SLEEP_FULL_BUFFER);285 continue;286 }287 288 nbytesread = SDLNet_TCP_Recv(self->tcpSocket, buffer, nbytestoread);289 290 SDL_mutexP(self->incomingBufferMutex);291 292 if (nbytesread<=0)293 {294 if (nbytesread<0)295 printf("SDLNet_TCP_Recv: %s\n", SDLNet_GetError());296 297 SDL_mutexP(self->socketMutex);298 299 SDLNet_TCP_Close(self->tcpSocket);300 self->tcpSocket = NULL;301 302 SDL_mutexV(self->socketMutex);303 SDL_mutexV(self->incomingBufferMutex);304 continue;305 }306 307 //printf("thread_read: nbytesread=%d\n", nbytesread);308 309 memcpy(self->incomingBuffer+self->incomingBufferLength, buffer, nbytesread);310 self->incomingBufferLength += nbytesread;311 312 SDL_mutexV(self->incomingBufferMutex);313 }314 315 SDL_mutexP(self->threadTerminationMutex);316 self->thread_read_running = false;317 318 if ( !self->thread_write_running )319 {320 //delete self;321 SDL_mutexV(self->threadTerminationMutex);322 }323 else324 {325 SDL_mutexV(self->threadTerminationMutex);326 }327 328 329 #ifdef DONTEXITTHREADS330 while ( true )331 {332 SDL_Delay(1000);333 }334 #endif335 336 PRINTF(0)("QUIT READ THREAD\n");337 338 return 0;339 }340 341 int NetworkSocket::thread_write( void * data )342 {343 int nbyteswrite = 0;344 int nbytestowrite = 0;345 char buffer[_LOCAL_BUFFER_SIZE];346 NetworkSocket * self = (NetworkSocket*)data;347 348 self->thread_write_running = true;349 350 while (!self->terminateThread)351 {352 #define min(a,b) (a<b)?a:b353 nbytestowrite = min(self->outgoingBufferLength, _LOCAL_BUFFER_SIZE);354 #undef min355 356 // printf("thread_write nbytes=%d listening=%d\n", nbytestowrite, (int)self->_isListening);357 358 //if buffer is full359 if (nbytestowrite<=0 || !self->tcpSocket)360 {361 SDL_Delay(_MSECONDS_SLEEP_EMPTY_BUFFER);362 continue;363 }364 365 SDL_mutexP(self->outgoingBufferMutex);366 367 //printf("a\n");368 369 memcpy(buffer, self->outgoingBuffer, nbytestowrite);370 self->outgoingBufferLength -= nbytestowrite;371 memmove(self->outgoingBuffer, self->outgoingBuffer+nbytestowrite, self->outgoingBufferLength);372 373 SDL_mutexV(self->outgoingBufferMutex);374 375 nbyteswrite = SDLNet_TCP_Send(self->tcpSocket, buffer, nbytestowrite);376 377 if (nbyteswrite<=0)378 {379 printf("SDLNet_TCP_Recv: %s\n", SDLNet_GetError());380 381 SDL_mutexP(self->socketMutex);382 383 SDLNet_TCP_Close(self->tcpSocket);384 self->tcpSocket = NULL;385 386 SDL_mutexV(self->socketMutex);387 continue;388 }389 390 }391 392 SDL_mutexP(self->threadTerminationMutex);393 self->thread_write_running = false;394 395 if ( !self->thread_read_running )396 {397 //delete self;398 SDL_mutexV(self->threadTerminationMutex);399 }400 else401 {402 SDL_mutexV(self->threadTerminationMutex);403 }404 405 #ifdef DONTEXITTHREADS406 while ( true )407 {408 SDL_Delay(1000);409 }410 #endif411 412 PRINTF(0)("QUIT WRITE THREAD\n");413 414 return 0;415 416 }417 418 bool NetworkSocket::writePacket( byte * data, int length )419 {420 PRINTF(5)("NetworkSocket::writePacket() size=%d\n", length);421 422 if ( length > 1024 )423 PRINTF(2)("WARNING SENDING BIG PACKET SIZE = %d\n", length);424 425 byte blen[INTSIZE];426 427 Converter::intToByteArray( length, blen, INTSIZE );428 429 writeBytes(blen, INTSIZE);430 writeBytes(data, length);431 }432 433 int NetworkSocket::readPacket( byte * data, int maxLength )434 {435 PRINTF(5)("NetworkSocket::readPacket()\n");436 if (incomingBufferLength<INTSIZE)437 {438 return 0;439 }440 441 int blen;442 Converter::byteArrayToInt( incomingBuffer, &blen );443 444 if (blen>maxLength)445 {446 PRINTF(1)("Buffersize is too small (%d) for packet (%d).\n", maxLength, blen);447 assert(false);448 return 0;449 }450 451 if (blen>incomingBufferLength)452 {453 return 0;454 }455 456 byte t[INTSIZE];457 readBytes(t, INTSIZE);458 int res = readBytes(data, blen);459 460 if (res!=blen)461 return -1;462 else463 return blen;464 465 }466 467 -
branches/network/src/lib/network/network_socket.h
r6994 r7540 8 8 #define _NETWORK_SOCKET 9 9 10 //TODO HACK else gdb will not work on server11 #define DONTEXITTHREADS12 13 //if you want to use outgoing buffer define _USE_OUTGOING_BUFFER14 #define _USE_OUTGOING_BUFFER15 16 #define _INCOMING_BUFFER_SIZE 202400017 #define _OUTGOING_BUFFER_SIZE 202400018 #define _LOCAL_BUFFER_SIZE 102419 //sleep if incoming buffer is full20 #define _MSECONDS_SLEEP_FULL_BUFFER 1021 //sleep if outgoing buffer is empty22 #define _MSECONDS_SLEEP_EMPTY_BUFFER 1023 24 25 /* contains memmove and memcpy */26 #include <string.h>27 28 #ifdef HAVE_SDL_H29 #include <SDL_thread.h>30 #else31 #include <SDL/SDL_thread.h>32 #endif33 10 /* include this file, it contains some default definitions */ 34 11 #include "netdefs.h" … … 38 15 #include "base_object.h" 39 16 40 /* using namespace std is default, this needs to be here */41 using namespace std;42 43 17 class NetworkSocket : public BaseObject 44 18 { 19 public: 20 NetworkSocket(); 21 virtual ~NetworkSocket(); 45 22 46 private: 47 // IPaddress serverAddress; 48 // unsigned int port; 49 TCPsocket tcpSocket; 50 // UDPsocket udpSocket; 23 /** 24 * connect to server on host with port port 25 * @param host hostname might be xxx.xxx.xxx.xxx or localhost ... 26 * @param port port to connect to 27 */ 28 virtual void connectToServer( std::string host, int port ) = 0; 29 30 /** 31 * disconnect from server 32 */ 33 virtual void disconnectServer() = 0; 51 34 52 byte incomingBuffer[_INCOMING_BUFFER_SIZE]; 53 #ifdef _USE_OUTGOING_BUFFER 54 byte outgoingBuffer[_OUTGOING_BUFFER_SIZE]; 55 #endif 56 int incomingBufferLength; 57 #ifdef _USE_OUTGOING_BUFFER 58 int outgoingBufferLength; 59 #endif 35 /** 36 * send packet to connected socket. will be recieved as whole packet 37 * @param data pointer to data to send 38 * @param length lengt of packet to send 39 * @return true on success 40 */ 41 virtual bool writePacket(byte * data, int length) = 0; 42 43 /** 44 * read a packet sent by another NetworkSocket 45 * @param data data will be copied here 46 * @param maxLength readPacket will not read more than maxLength 47 * @return bytes read. on error less than zero 48 */ 49 virtual int readPacket(byte * data, int maxLength) = 0; 60 50 61 SDL_mutex * incomingBufferMutex; 62 #ifdef _USE_OUTGOING_BUFFER 63 SDL_mutex * outgoingBufferMutex; 64 #endif 65 SDL_mutex * socketMutex; 66 bool terminateThread; 67 68 SDL_mutex* threadTerminationMutex; 69 static int thread_read(void * data); 70 bool thread_read_running; 71 bool thread_write_running; 72 73 SDL_Thread* readThread; 74 SDL_Thread* writeThread; 75 76 #ifdef _USE_OUTGOING_BUFFER 77 static int thread_write(void * data); 78 #endif 79 80 int writeBytes(byte * data, int length); 81 int readBytes(byte * data, int length); 82 int readBlock(byte * data, int length); 83 84 void init(); 85 86 public: 87 88 NetworkSocket(); 89 virtual ~NetworkSocket(); 90 NetworkSocket(IPaddress ip); 91 NetworkSocket(TCPsocket sock); 92 void destroy() { terminateThread = true; }; 93 94 95 void connectToServer(IPaddress ip); 96 void disconnectServer(); 97 98 bool writePacket(byte * data, int length); 99 int readPacket(byte * data, int maxLength); 100 101 inline bool isOk() { return tcpSocket!=NULL; } 51 /** 52 * check if socket is ok 53 * @return true if socket is ok 54 */ 55 inline bool isOk() { return this->bOk; } 56 57 protected: 58 bool bOk; //!< check for socket status 102 59 103 60 }; -
branches/network/src/lib/network/network_stream.cc
r7444 r7540 23 23 #include "base_object.h" 24 24 #include "network_protocol.h" 25 #include "network_socket.h" 25 #include "tcp_socket.h" 26 #include "tcp_server_socket.h" 26 27 #include "connection_monitor.h" 27 28 #include "synchronizeable.h" … … 54 55 55 56 56 NetworkStream::NetworkStream( IPaddress& address)57 NetworkStream::NetworkStream( std::string host, int port ) 57 58 { 58 59 this->type = NET_CLIENT; 59 60 this->init(); 60 this->networkSockets.push_back(new NetworkSocket(address));61 this->networkSockets.push_back(new TcpSocket( host, port )); 61 62 this->networkProtocol = new NetworkProtocol(); 62 63 this->connectionMonitor = new ConnectionMonitor(); … … 65 66 66 67 67 NetworkStream::NetworkStream( unsignedint port)68 NetworkStream::NetworkStream( int port) 68 69 { 69 70 this->type = NET_SERVER; 70 71 this->init(); 71 this->serverSocket = new ServerSocket(port);72 this->serverSocket = new TcpServerSocket(port); 72 73 this->networkProtocol = new NetworkProtocol(); 73 74 this->connectionMonitor = new ConnectionMonitor(); … … 103 104 { 104 105 (*i)->disconnectServer(); 105 (*i)->destroy();106 106 } 107 107 } … … 175 175 //delete networkSockets[i]; 176 176 networkSockets[0]->disconnectServer(); 177 networkSockets[0]->destroy();178 177 networkSockets[0] = NULL; 179 178 … … 241 240 do { 242 241 counter++; 243 244 //check for endless loop245 if ( counter > 50 )246 {247 PRINTF(1)("there seems to be an error in readBytes of %s\n", (*it)->getClassName());248 assert(false);249 }250 242 251 243 reciever = 0; … … 415 407 //delete networkSockets[i]; 416 408 networkSockets[i]->disconnectServer(); 417 networkSockets[i]->destroy();418 409 networkSockets[i] = NULL; 419 410 -
branches/network/src/lib/network/network_stream.h
r6981 r7540 32 32 public: 33 33 NetworkStream(); 34 NetworkStream( IPaddress& address);35 NetworkStream( unsigned int port);34 NetworkStream( std::string host, int port); 35 NetworkStream( int port ); 36 36 37 37 virtual ~NetworkStream(); -
branches/network/src/lib/network/server_socket.cc
r7402 r7540 27 27 28 28 29 ServerSocket::ServerSocket( ConnectionType connectionType ) 29 /** 30 * constructor 31 * @param port port to assign to socket 32 */ 33 ServerSocket::ServerSocket( int port ) 30 34 { 31 this->connectionType = connectionType; 32 init(); 35 bOk = true; 33 36 } 34 37 35 36 ServerSocket::ServerSocket( ConnectionType connectionType, unsigned int port ) 38 ServerSocket::~ ServerSocket( ) 37 39 { 38 this->connectionType = connectionType;39 init();40 listen(port);41 40 } 42 43 44 ServerSocket::ServerSocket()45 {46 this->connectionType == NET_TCP;47 init();48 }49 50 51 ServerSocket::ServerSocket( unsigned int port )52 {53 this->connectionType == NET_TCP;54 init();55 listen(port);56 }57 58 59 /**60 * Default destructor61 */62 ServerSocket::~ServerSocket( )63 {64 /* Quit SDL_net */65 // NOTE: what if other instances of NetworkSocket running?66 SDLNet_Quit();67 PRINTF(5)("SDL_net shutdown\n");68 69 _isListening = false;70 }71 72 73 74 75 void ServerSocket::init( )76 {77 /* set the class id for the base object */78 this->setClassID(CL_SERVER_SOCKET, "ServerSocket");79 80 terminateThread = false;81 listenSocket = NULL;82 _isListening = false;83 84 if(SDLNet_Init()==-1)85 {86 PRINTF(1)("SDLNet_Init: %s\n", SDLNet_GetError());87 return;88 }89 else90 PRINTF(5)("SDL_net initialized\n");91 92 PRINTF(0)("ServerSocket created\n");93 }94 95 96 /**97 * Tells the NetworkSocket to listen on a specific port for incoming connections.98 * NetworkSocket::writeBytes(...) will have no effect until there is a valuable connection.99 * @param port100 */101 bool ServerSocket::listen(unsigned int port)102 {103 PRINTF(0)("ServerSocket::listen()\n");104 _isListening = true;105 //check if not already connected or listening106 if (listenSocket)107 {108 PRINTF(1)("ServerSocket::listen: tcpSocket!=NULL! maybe you already called listen or did not call close()!\n");109 _isListening = false;110 return false;111 }112 113 IPaddress ip;114 115 if (SDLNet_ResolveHost(&ip, NULL, port)==-1)116 {117 PRINTF(1)("SDLNet_ResolveHost: %s\n", SDLNet_GetError());118 _isListening = false;119 return false;120 }121 122 if( this->connectionType == NET_TCP)123 {124 listenSocketTCP = SDLNet_TCP_Open(&ip);125 if( !listenSocketTCP) {126 PRINTF(1)("SDLNet_TCP_Open: %s\n", SDLNet_GetError());127 _isListening = false;128 return false;129 }130 }131 else132 {133 listenSocketUDP = SDLNet_UDP_Open(port);134 PRINTF(1)("SDLNet_UDP_Open: %s\n", SDLNet_GetError());135 _isListening = false;136 return false;137 }138 139 140 return true;141 }142 143 144 /**145 * returns a new NetworkSocket146 * @return new socket147 */148 NetworkSocket* ServerSocket::getNewSocket( )149 {150 if ( !listenSocket )151 {152 PRINTF(1)("listenSocket == NULL! Maybe you forgot to call listen()\n");153 close();154 return NULL;155 }156 157 if( this->connectionType == NET_TCP)158 {159 TCPsocket sockTCP = SDLNet_TCP_Accept(this->listenSocketTCP);160 if( !sockTCP)161 return NULL;162 else163 return new NetworkSocket(sockTCP);164 }165 else166 {167 #warning UDP getNewSocket incomplet168 // UDPsocket sockUDP = SDLNet_UDP_Accept(this->listenSocketUDP);169 // if( !sockUDP)170 // return NULL;171 172 // else173 // return new NetworkSocket();174 }175 }176 177 178 /**179 * closes the ServerSocket180 */181 void ServerSocket::close( )182 {183 if ( listenSocket )184 {185 SDLNet_TCP_Close( listenSocket );186 listenSocket = NULL;187 }188 189 _isListening = false;190 }191 -
branches/network/src/lib/network/server_socket.h
r7402 r7540 8 8 #define _SERVER_SOCKET 9 9 10 #ifdef HAVE_SDL_H11 #include <SDL_thread.h>12 #else13 #include <SDL/SDL_thread.h>14 #endif15 10 /* include this file, it contains some default definitions */ 16 11 #include "netdefs.h" … … 21 16 #include "network_socket.h" 22 17 23 //sleep when waiting for connections24 #define _MSECONDS_SLEEP_LISTEN 10025 26 18 27 19 class ServerSocket : public BaseObject 28 20 { 29 21 public: 30 #warning old socket structure 31 ServerSocket(); 32 ServerSocket(unsigned int port); 22 ServerSocket( int port); 33 23 34 ServerSocket(ConnectionType connectionType);35 ServerSocket(ConnectionType connectionType, unsigned int port );36 24 virtual ~ServerSocket(); 37 25 38 bool listen( unsigned int port );39 NetworkSocket* getNewSocket( void );40 v oid close();41 inline bool isOk(){ return listenSocket!=NULL; }26 virtual bool listen( unsigned int port ) = 0; 27 virtual NetworkSocket* getNewSocket( void ) = 0; 28 virtual void close() = 0; 29 virtual bool isOk() { return this->bOk; }; 42 30 43 44 private: 45 void init(); 46 47 48 private: 49 #warning old socket structure 50 TCPsocket listenSocket; 51 52 ConnectionType connectionType; //!< the connection type of the socket {TCP,UDP} 53 TCPsocket listenSocketTCP; //!< tcp socket 54 UDPsocket listenSocketUDP; //!< udp socket 55 bool terminateThread; //!< true if thread terminated 56 57 bool _isListening; //!< true if listening 58 31 protected: 32 bool bOk; 59 33 60 34 };
Note: See TracChangeset
for help on using the changeset viewer.