Force the sending of bytes. - geomyidae - A small C-based gopherd.
git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/geomyidae/
Log
Files
Refs
Tags
README
LICENSE
---
commit 953a8272e76a2a224155d2b3f23c1018eec6c501
parent 0fd85c6a6fb9acd564e77ae4824d9870d6a0b1c4
Author: Christoph Lohmann <20h@r-36.net>
Date:   Fri, 18 Sep 2015 19:08:37 +0200

Force the sending of bytes.

Diffstat:
  M handlr.c                            |      12 +++++++++---

1 file changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/handlr.c b/handlr.c
@@ -105,7 +105,7 @@ handlebin(int sock, char *file, char *port, char *base, char *args,
                 char *sear, char *ohost)
 {
         char sendb[1024];
-        int len, fd;
+        int len, fd, sent;
 
         len = -1;
         USED(port);
@@ -116,8 +116,14 @@ handlebin(int sock, char *file, char *port, char *base, char *args,
 
         fd = open(file, O_RDONLY);
         if(fd >= 0) {
-                while((len = read(fd, sendb, sizeof(sendb))) > 0)
-                        send(sock, sendb, len, 0);
+                while((len = read(fd, sendb, sizeof(sendb))) > 0) {
+                        while(len > 0) {
+                                sent = send(sock, sendb, len, 0);
+                                if(sent < 0)
+                                        break;
+                                len -= sent;
+                        }
+                }
                 close(fd);
         }
 }