+
+ #if USE_TCP
+ for( ;; )
+ {
+ fd_set fds;
+ int nfd = Client->Socket;
+ FD_ZERO(&fds);
+ FD_SET(Client->Socket, &fds);
+
+ select(nfd, &fds, NULL, NULL, NULL); // TODO: Timeouts?
+
+ if( FD_ISSET(Client->Socket, &fds) )
+ {
+ const int ciMaxParamCount = 6;
+ char lbuf[sizeof(tRequestHeader) + ciMaxParamCount*sizeof(tRequestValue)];
+ tRequestHeader *hdr = (void*)lbuf;
+ size_t len = recv(Client->Socket, hdr, sizeof(*hdr), 0);
+ if( len != sizeof(hdr) ) {
+ // Oops?
+ }
+
+ if( hdr->NParams > ciMaxParamCount ) {
+ // Oops.
+ }
+
+ len = recv(Client->Socket, hdr->Params, hdr->NParams*sizeof(tRequestValue), 0);
+ if( len != hdr->NParams*sizeof(tRequestValue) ) {
+ // Oops.
+ }
+
+ // Get buffer size
+ size_t hdrsize = sizeof(tRequestHeader) + hdr->NParams*sizeof(tRequestValue);
+ size_t bufsize = hdrsize;
+ int i;
+ for( i = 0; i < hdr->NParams; i ++ )
+ {
+ if( hdr->Params[i].Flags & ARG_FLAG_ZEROED )
+ ;
+ else {
+ bufsize += hdr->Params[i].Length;
+ }
+ }
+
+ // Allocate full buffer
+ hdr = malloc(bufsize);
+ memcpy(hdr, lbuf, hdrsize);
+ len = recv(Client->Socket, hdr->Params + hdr->NParams, bufsize - hdrsize, 0);
+ if( len != bufsize - hdrsize ) {
+ // Oops?
+ }
+
+ int retlen;
+ tRequestHeader *retHeader;
+ retHeader = SyscallRecieve(hdr, &retlen);
+ if( !retHeader ) {
+ // Some sort of error
+ }
+
+ send(Client->Socket, retHeader, retlen, 0);
+
+ // Clean up
+ free(hdr);
+ }
+ }
+ #else