improve error handling and add some debug code in net_fallback_sendfile

Sun, 04 Aug 2019 10:46:51 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 04 Aug 2019 10:46:51 +0200
changeset 205
b8515afa450a
parent 204
e870a7c8f223
child 206
f5bdca63bbe7

improve error handling and add some debug code in net_fallback_sendfile

src/server/util/io.c file | annotate | diff | comparison | revisions
--- a/src/server/util/io.c	Sat Aug 03 17:54:54 2019 +0200
+++ b/src/server/util/io.c	Sun Aug 04 10:46:51 2019 +0200
@@ -515,22 +515,34 @@
 
     size_t length = sfd->len;
     while(length > 0) {
+        // TODO: remove
+        if(length > sfd->len) {
+            log_ereport(LOG_WARN, "net_fallback_sendfile: length > sfd->len: %zu > %zu", length, sfd->len);
+            free(buf);
+            return IO_ERROR;
+        }
+        
         if((r = system_fread(sfd->fd, buf, 4096)) <= 0) {
             break;
         }
         char *write_buf = buf;
         while(r > 0) {
             ssize_t w = fd->write(fd, write_buf, r);
+            // TODO: remove
+            if(w > r) {
+                log_ereport(LOG_WARN, "net_fallback_sendfile: w > r, %zd > %zd", w, r);
+                w = 0;
+            }
+            
             if(w <= 0) {
-                break;
+                free(buf);
+                fd->io_errno = errno;
+                return IO_ERROR;
             }
             r -= w;
             length -= w;
             write_buf += w;
         }
-        if(r > 0) {
-            break;
-        }
     }
     free(buf);
     if(length > 0) {

mercurial