Merge branch 'master' of ssh.ucc.asn.au:tpg/acess2
[tpg/acess2.git] / AcessNative / ld-acess_src / request.c
index 12a26d1..c9e8565 100644 (file)
@@ -122,6 +122,7 @@ int _InitSyscalls(void)
        {
                tRequestAuthHdr auth;
                auth.pid = giSyscall_ClientID;
+               auth.key = 0;
                SendData(&auth, sizeof(auth));
                int len = ReadData(&auth, sizeof(auth), 5);
                if( len == 0 ) { 
@@ -189,6 +190,7 @@ int SendRequest(tRequestHeader *Request, int RequestSize, int ResponseSize)
                printf("\n");
        }
        #endif
+       #if DEBUG
        {
                 int    i;
                char    *data = (char*)&Request->Params[Request->NParams];
@@ -218,6 +220,7 @@ int SendRequest(tRequestHeader *Request, int RequestSize, int ResponseSize)
                }
                DEBUG_S("\n");
        }
+       #endif
        
        // Send it off
        SendData(Request, RequestSize);
@@ -225,7 +228,23 @@ int SendRequest(tRequestHeader *Request, int RequestSize, int ResponseSize)
        if( Request->CallID == SYS_EXIT )       return 0;
 
        // Wait for a response (no timeout)
-       return ReadData(Request, ResponseSize, 0);
+       ReadData(Request, sizeof(*Request), 0);
+       // TODO: Sanity
+       size_t  recvbytes = sizeof(*Request), expbytes = Request->MessageLength;
+       char    *ptr = (void*)Request->Params;
+       while( recvbytes < expbytes )
+       {
+               size_t  len = ReadData(ptr, expbytes - recvbytes, 1000);
+               if( len == -1 ) {
+                       return -1;
+               }
+               recvbytes += len;
+               ptr += len;
+       }
+       if( recvbytes > expbytes ) {
+               // TODO: Warning
+       }
+       return recvbytes;
 }
 
 void SendData(void *Data, int Length)
@@ -274,7 +293,7 @@ int ReadData(void *Dest, int MaxLength, int Timeout)
        
        if( !ret ) {
                printf("[ERROR %i] Timeout reading from socket\n", giSyscall_ClientID);
-               return 0;       // Timeout
+               return -2;      // Timeout
        }
        
        #if USE_TCP
@@ -288,6 +307,10 @@ int ReadData(void *Dest, int MaxLength, int Timeout)
                perror("ReadData");
                exit(-1);
        }
+       if( ret == 0 ) {
+               fprintf(stderr, "[ERROR %i] Connection closed.\n", giSyscall_ClientID);
+               exit(0);
+       }
        
        DEBUG_S("%i bytes read from socket\n", ret);
        

UCC git Repository :: git.ucc.asn.au