r1606: make the low level socket read/write routines cope properly with non-blocking...
authorAndrew Tridgell <tridge@samba.org>
Thu, 29 Jul 2004 11:55:57 +0000 (11:55 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:57:44 +0000 (12:57 -0500)
source/lib/util_sock.c

index 43da8a2f577aedc7e71dc41e9c73413b131f82ff..8c9a140746e679ecbae2bb05ac464bf5c91cd4f3 100644 (file)
@@ -195,10 +195,13 @@ ssize_t read_data(int fd, char *buffer, size_t N)
        while (total < N) {
                ret = sys_read(fd,buffer + total,N - total);
                if (ret == 0) {
-                       return 0;
+                       return total;
                }
                if (ret == -1) {
-                       return -1;
+                       if (total == 0) {
+                               return -1;
+                       }
+                       return total;
                }
                total += ret;
        }
@@ -222,10 +225,14 @@ ssize_t write_data(int fd, const char *buffer, size_t N)
        while (total < N) {
                ret = sys_write(fd, buffer + total, N - total);
                if (ret == -1) {
-                       return -1;
+                       if (total == 0) {
+                               return -1;
+                       }
+                       return total;
                }
-               if (ret == 0)
+               if (ret == 0) {
                        return total;
+               }
 
                total += ret;
        }