Changeset 5625 in orxonox.OLD for branches/network
- Timestamp:
- Nov 17, 2005, 10:05:35 AM (19 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_socket.cc
r5624 r5625 41 41 42 42 mutex = SDL_CreateMutex(); 43 socketmutex = SDL_CreateMutex(); 43 44 terminateThread = false; 44 45 … … 62 63 NetworkSocket::~ NetworkSocket( ) 63 64 { 64 SDL_DestroyMutex(mutex);65 66 65 /* Quit SDL_net */ 67 66 // NOTE: what if other instances of NetworkSocket running? 68 67 SDLNet_Quit(); 69 68 PRINTF(5)("SDL_net shutdown\n"); 69 70 SDL_DestroyMutex(mutex); 71 SDL_DestroyMutex(socketmutex); 70 72 } 71 73 … … 135 137 terminateThread = true; 136 138 /* Close the connection */ 139 140 SDL_mutexP(socketmutex); 137 141 SDLNet_TCP_Close(tcpSocket); 138 142 tcpSocket = NULL; 143 SDL_mutexV(socketmutex); 139 144 140 145 } … … 151 156 int NetworkSocket::writeBytes(byte * data, int length) 152 157 { 158 SDL_mutexP(socketmutex); 159 153 160 if (!tcpSocket || data==NULL) 154 161 return 0; 155 162 156 163 int res = SDLNet_TCP_Send(tcpSocket, data, length); 164 165 SDL_mutexV(socketmutex); 157 166 158 167 if (res<length) … … 175 184 int NetworkSocket::readBytes(byte * data, int length) 176 185 { 177 if ( !tcpSocket ||data==NULL)186 if (data==NULL) 178 187 return 0; 179 188 … … 212 221 tempsocket = SDLNet_TCP_Accept(self->tcpSocket); 213 222 223 SDL_mutexP(self->socketmutex); 214 224 SDLNet_TCP_Close(self->tcpSocket); 215 225 self->tcpSocket = NULL; … … 218 228 { 219 229 PRINTF(1)("SDLNet_TCP_Accept: %s\n", SDLNet_GetError()); 230 SDL_mutexV(self->socketmutex); 220 231 return -1; 221 232 } 222 233 223 234 self->tcpSocket = tempsocket; 235 236 SDL_mutexV(self->socketmutex); 224 237 225 238 return thread_read(data); … … 249 262 { 250 263 PRINTF(1)("SDLNet_TCP_Recv: %s\n", SDLNet_GetError()); 264 265 SDL_mutexP(self->socketmutex); 266 251 267 SDLNet_TCP_Close(self->tcpSocket); 252 268 self->tcpSocket = NULL; 269 270 SDL_mutexV(self->socketmutex); 253 271 SDL_mutexV(self->mutex); 254 272 return -1; -
branches/network/src/lib/network/network_socket.h
r5624 r5625 39 39 40 40 SDL_mutex * mutex; 41 SDL_mutex * socketmutex; 41 42 bool terminateThread; 42 43
Note: See TracChangeset
for help on using the changeset viewer.