fixes chunked transfer encoding

Sun, 30 Oct 2016 11:44:04 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 30 Oct 2016 11:44:04 +0100
changeset 126
631aaa01b2b5
parent 125
c913d515be1e
child 127
84e206063b64

fixes chunked transfer encoding

src/server/daemon/event_linux.c file | annotate | diff | comparison | revisions
src/server/safs/cgi.c file | annotate | diff | comparison | revisions
src/server/safs/cgiutils.c file | annotate | diff | comparison | revisions
src/server/util/io.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/event_linux.c	Sun Oct 30 10:22:00 2016 +0100
+++ b/src/server/daemon/event_linux.c	Sun Oct 30 11:44:04 2016 +0100
@@ -96,7 +96,7 @@
     for(;;) {
         /* wait for events */
         int ret = epoll_wait(ep, events, 16, 100000);
-        if(ret == -1) {
+        if(ret == -1 && errno != EINTR) {
             /* TODO: check for error */
             perror("epoll_wait");
             continue;
--- a/src/server/safs/cgi.c	Sun Oct 30 10:22:00 2016 +0100
+++ b/src/server/safs/cgi.c	Sun Oct 30 11:44:04 2016 +0100
@@ -109,7 +109,7 @@
     CGIResponseParser *parser = cgi_parser_new(sn, rq);
     WSBool cgiheader = TRUE;
     ssize_t wr = 0;
-    int result = REQ_PROCEED;
+    int result = REQ_PROCEED;   
     while((r = read(cgip.out[0], buf, 4096)) > 0) {
         if(cgiheader) {
             size_t pos;
@@ -142,7 +142,7 @@
             }
         }
     }
-    
+      
     cgi_parser_free(parser);
     return result;
 }
--- a/src/server/safs/cgiutils.c	Sun Oct 30 10:22:00 2016 +0100
+++ b/src/server/safs/cgiutils.c	Sun Oct 30 11:44:04 2016 +0100
@@ -273,7 +273,7 @@
             env[x++] = util_env_str("SCRIPT_NAME", t);
         }
 
-        if (t = pblock_findval("path", rq->vars))
+        if ((t = pblock_findval("path", rq->vars)))
             env[x++] = util_env_str("SCRIPT_FILENAME", t);
     }
 
@@ -341,10 +341,10 @@
 
     // Handle Apache ErrorDocument-style variables from the send-error SAF
     if (rq->orig_rq != rq) {
-        if (t = pblock_findval("uri", rq->orig_rq->reqpb)) {
+        if ((t = pblock_findval("uri", rq->orig_rq->reqpb))) {
             env[x++] = util_env_str("REDIRECT_URL", t);
         }
-        if (t = pblock_findval("status", rq->orig_rq->srvhdrs)) {
+        if ((t = pblock_findval("status", rq->orig_rq->srvhdrs))) {
             env[x++] = util_env_str("REDIRECT_STATUS", t);
         }
     }
--- a/src/server/util/io.c	Sun Oct 30 10:22:00 2016 +0100
+++ b/src/server/util/io.c	Sun Oct 30 11:44:04 2016 +0100
@@ -35,13 +35,17 @@
 #include <sys/uio.h>
 #include <sys/uio.h>
 
-#ifndef BSD
+#if defined(LINUX) || defined(SOLARIS)
 #include <sys/sendfile.h>
-#else
+#define WS_SENDFILE
+#elif defined(BSD)
 #if defined(__NetBSD__) || defined(__OpenBSD__)
-#define WS_NO_SENDFILE
 #define net_sys_sendfile net_fallback_sendfile
+#else
+#define WS_SENDFILE
 #endif
+#else
+#define net_sys_sendfile net_fallback_sendfile
 #endif
 
 #include "../daemon/vfs.h"
@@ -101,7 +105,7 @@
     return read(st->fd, buf, nbytes);
 }
 
-#ifndef WS_NO_SENDFILE
+#ifdef WS_SENDFILE
 ssize_t net_sys_sendfile(SysStream *st, sendfiledata *sfd) {
     ssize_t ret = 0;
     off_t fileoffset = sfd->offset;
@@ -142,8 +146,7 @@
         }
 #endif
     } else {
-        // TODO: regular copy
-        fprintf(stderr, "sendfile not implemented for SYS_FILE\n");
+        return net_fallback_sendfile((IOStream*)st, sfd);
     }
     
     return ret;
@@ -206,13 +209,15 @@
     IOStream *fd = st->fd;
     if(st->chunked_enc) {
         // TODO: on some plattforms iov_len is smaller than size_t
-        struct iovec io[2];
+        struct iovec io[3];
         char chunk_len[16];
         io[0].iov_base = chunk_len;
-        io[0].iov_len = snprintf(chunk_len, 16, "\r\n%zx\r\n", nbytes);
+        io[0].iov_len = snprintf(chunk_len, 16, "%zx\r\n", nbytes);
         io[1].iov_base = buf;
         io[1].iov_len = nbytes;
-        ssize_t r = fd->writev(fd, io, 2);
+        io[2].iov_base = "\r\n";
+        io[2].iov_len = 2;
+        ssize_t r = fd->writev(fd, io, 3);
         return r - io[0].iov_len;
     } else {
         return fd->write(fd, buf, nbytes);

mercurial