* Simplified and fixed rcv_request().
authorUrban Wallasch <urban.wallasch@freenet.de>
Fri, 25 Oct 2019 21:51:04 +0000 (23:51 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Fri, 25 Oct 2019 21:51:04 +0000 (23:51 +0200)
telehttpd.c

index 7be9f971f7dcf32ca049e6f183c4dc3a1517e0e2..845d91a4b7b27c5f08d43446bb118c4c07d00edf 100644 (file)
@@ -223,40 +223,28 @@ static int rcv_request(int sock, char *buf, size_t size, int timeout) {
     int res = -1;
     size_t total = 0;
     ssize_t bread = 0;
-    struct pollfd pe;
-
-    pe.fd = sock;
-    do {
-        pe.events = POLLIN;
-        pe.revents = 0;
-        res = poll(&pe, 1, timeout);
-        if ( 0 < res && pe.revents == POLLIN ) {
-            errno = 0;
-            bread = read_tm(sock, buf + total, size - total, 1000);
-            if ( 0 > bread ) {
-                switch (errno) {
-                case EAGAIN:
-                case EINTR:
-                    break;
-                default:
-                    EPRINT( "read: %s\n", strerror(errno) );
-                    res = -1;
-                    break;
-                }
-            }
-            else if ( 0 == bread && 0 == errno ) {
-                EPRINT( "read: premature EOF\n" );
-                res = -1;
-            }
-            else {
-                total += bread;
-                if ( strstr(buf, "\r\n\r\n" ) )
-                    res = 0;
-            }
+    --size;
+
+    while ( total < size && !force_quit ) {
+        bread = read_tm( sock, buf + total, size - total, timeout );
+        if ( 0 > bread ) {
+            if ( errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK )
+                continue;
+            EPRINT( "read: %s\n", strerror(errno) );
+            break;
+        }
+        else if ( 0 == bread ) {
+            EPRINT( "read: premature EOF\n" );
+            break;
+        }
+        total += bread;
+        buf[total] = 0;
+        if ( strstr( buf, "\r\n\r\n" ) ) {
+            res = 0;
+            break;
         }
         timeout = 200;
-    } while ( 1 == res && pe.revents == POLLIN && !force_quit );
-    buf[total] = 0;
+    }
     return res;
 }