+ if( len != Length ) {
+ fprintf(stderr, "[ERROR %i] ", giSyscall_ClientID);
+ perror("SendData");
+ exit(-1);
+ }
+}
+
+int ReadData(void *Dest, int MaxLength, int Timeout)
+{
+ int ret;
+ fd_set fds;
+ struct timeval tv;
+ struct timeval *timeoutPtr;
+
+ FD_ZERO(&fds);
+ FD_SET(gSocket, &fds);
+
+ if( Timeout ) {
+ tv.tv_sec = Timeout;
+ tv.tv_usec = 0;
+ timeoutPtr = &tv;
+ }
+ else {
+ timeoutPtr = NULL;
+ }
+
+ ret = select(gSocket+1, &fds, NULL, NULL, timeoutPtr);
+ if( ret == -1 ) {
+ fprintf(stderr, "[ERROR %i] ", giSyscall_ClientID);
+ perror("ReadData - select");
+ exit(-1);
+ }
+
+ if( !ret ) {
+ printf("[ERROR %i] Timeout reading from socket\n", giSyscall_ClientID);
+ return 0; // Timeout
+ }
+
+ #if USE_TCP
+ ret = recv(gSocket, Dest, MaxLength, 0);
+ #else
+ ret = recvfrom(gSocket, Dest, MaxLength, 0, NULL, 0);
+ #endif
+
+ if( ret < 0 ) {
+ fprintf(stderr, "[ERROR %i] ", giSyscall_ClientID);
+ perror("ReadData");
+ exit(-1);
+ }
+
+ DEBUG_S("%i bytes read from socket\n", ret);
+
+ return ret;