+
+void SendData(void *Data, int Length)
+{
+ int len;
+
+ #if USE_TCP
+ len = send(Data, Length, 0);
+ #else
+ len = sendto(gSocket, Data, Length, 0,
+ (struct sockaddr*)&gSyscall_ServerAddr, sizeof(gSyscall_ServerAddr));
+ #endif
+
+ if( len != Length ) {
+ perror("SendData");
+ exit(-1);
+ }
+}
+
+int ReadData(void *Dest, int MaxLength, int Timeout)
+{
+ int ret;
+ fd_set fds;
+ struct timeval tv;
+
+ FD_ZERO(&fds);
+ FD_SET(gSocket, &fds);
+
+ tv.tv_sec = Timeout;
+ tv.tv_usec = 0;
+
+ ret = select(1, &fds, NULL, NULL, &tv);
+ if( ret == -1 ) {
+ perror("ReadData - select");
+ exit(-1);
+ }
+
+ if( !ret ) {
+ printf("Timeout reading from socket\n");
+ 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 ) {
+ perror("ReadData");
+ exit(-1);
+ }
+
+ return ret;
+}