Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5625 in orxonox.OLD for branches/network/src/lib


Ignore:
Timestamp:
Nov 17, 2005, 10:05:35 AM (19 years ago)
Author:
rennerc
Message:

network_socket: added new mutex

Location:
branches/network/src/lib/network
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/network_socket.cc

    r5624 r5625  
    4141
    4242  mutex = SDL_CreateMutex();
     43  socketmutex = SDL_CreateMutex();
    4344  terminateThread = false;
    4445
     
    6263NetworkSocket::~ NetworkSocket( )
    6364{
    64   SDL_DestroyMutex(mutex);
    65 
    6665  /* Quit SDL_net */
    6766  // NOTE: what if other instances of NetworkSocket running?
    6867  SDLNet_Quit();
    6968  PRINTF(5)("SDL_net shutdown\n");
     69
     70  SDL_DestroyMutex(mutex);
     71  SDL_DestroyMutex(socketmutex);
    7072}
    7173
     
    135137  terminateThread = true;
    136138  /* Close the connection */
     139
     140  SDL_mutexP(socketmutex);
    137141  SDLNet_TCP_Close(tcpSocket);
    138142  tcpSocket = NULL;
     143  SDL_mutexV(socketmutex);
    139144
    140145}
     
    151156int NetworkSocket::writeBytes(byte * data, int length)
    152157{
     158  SDL_mutexP(socketmutex);
     159
    153160  if (!tcpSocket || data==NULL)
    154161    return 0;
    155162
    156163  int res = SDLNet_TCP_Send(tcpSocket, data, length);
     164
     165  SDL_mutexV(socketmutex);
    157166
    158167  if (res<length)
     
    175184int NetworkSocket::readBytes(byte * data, int length)
    176185{
    177   if (!tcpSocket || data==NULL)
     186  if (data==NULL)
    178187    return 0;
    179188
     
    212221  tempsocket = SDLNet_TCP_Accept(self->tcpSocket);
    213222
     223  SDL_mutexP(self->socketmutex);
    214224  SDLNet_TCP_Close(self->tcpSocket);
    215225  self->tcpSocket = NULL;
     
    218228  {
    219229    PRINTF(1)("SDLNet_TCP_Accept: %s\n", SDLNet_GetError());
     230    SDL_mutexV(self->socketmutex);
    220231    return -1;
    221232  }
    222233
    223234  self->tcpSocket = tempsocket;
     235
     236  SDL_mutexV(self->socketmutex);
    224237
    225238  return thread_read(data);
     
    249262    {
    250263      PRINTF(1)("SDLNet_TCP_Recv: %s\n", SDLNet_GetError());
     264
     265      SDL_mutexP(self->socketmutex);
     266
    251267      SDLNet_TCP_Close(self->tcpSocket);
    252268      self->tcpSocket = NULL;
     269
     270      SDL_mutexV(self->socketmutex);
    253271      SDL_mutexV(self->mutex);
    254272      return -1;
  • branches/network/src/lib/network/network_socket.h

    r5624 r5625  
    3939
    4040  SDL_mutex * mutex;
     41  SDL_mutex * socketmutex;
    4142  bool terminateThread;
    4243
Note: See TracChangeset for help on using the changeset viewer.