]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Mon, 28 Mar 2022 06:16:48 +0000 (23:16 -0700)
committeralex <[email protected]>
Mon, 28 Mar 2022 06:16:48 +0000 (23:16 -0700)
src/net/wait.c
test/unit/net.tests.c

index c5003936ab8a5f8a8097f81eeb0686532f919ca7..beb4af31a8a475c974d654a3fa085be0f0c5d443 100644 (file)
@@ -17,21 +17,20 @@ int net_wait(int sock, struct peer *info, void *buf, size_t buf_size) {
 
        i = recv(sock,p,size,0);
        if(-1==i) {
-               if(!((errno==EAGAIN)||(errno==EWOULDBLOCK))) {
-                       perror("recv");
-                       return -1;
-               }
+               if((errno==EAGAIN)||(errno==EWOULDBLOCK)) { return 0; }
+               perror("recv");
+               return -1;
        }
 
-       if((i!=size)&&(size>0)) { goto cached; }
+       if(i!=size) { goto cached; }
 
        return 1;
 cached:
        if(net_cache(
                &(info->in), /* void **prev */
                &(info->in_size), /* size_t *prev_size */
-               p, /* void *p */
-               i /* size_t size */
+               buf, /* void *p */
+               buf_size - size + i /* size_t size */
                )<0) { return -1; }
        return 0;
 }
index 748983cdff08625a23b693e9f6ef7a713b767316..0fabe6dba73d0751bfacffcaaa0a932eae147b4a 100644 (file)
@@ -132,7 +132,6 @@ static void net_wait_basic_test() {
 
        assert(1==net_wait(read_sock,info,buf,100));
        assert(info->in==NULL);
-       assert(info->in_size==0);
        assert(memcmp(buf,expected,100)==0);
        
        close(read_sock);