When shutting down a connection right after an HTTP upload we must wait
a while for the client to see the response.

Signed-off-by: Joachim Nilsson <[email protected]>
---
 networking/httpd.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/networking/httpd.c b/networking/httpd.c
index c2d226592..6993dcbf3 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1014,15 +1014,18 @@ static int openServer(void)
 static void log_and_exit(void) NORETURN;
 static void log_and_exit(void)
 {
+       int t;
+       socklen_t tl = sizeof(t);
+
        /* Paranoia. IE said to be buggy. It may send some extra data
         * or be confused by us just exiting without SHUT_WR. Oh well. */
-       shutdown(1, SHUT_WR);
-       /* Why??
-       (this also messes up stdin when user runs httpd -i from terminal)
-       ndelay_on(0);
-       while (read(STDIN_FILENO, iobuf, IOBUF_SIZE) > 0)
+       if (getsockopt(STDIN_FILENO, SOL_SOCKET, SO_TYPE, &t, &tl) == 0)
+               shutdown(STDIN_FILENO, SHUT_WR);
+
+       /* Eat any remaining data for a while to allow response to be seen */
+       alarm(30);
+       while (recv(STDIN_FILENO, iobuf, IOBUF_SIZE, MSG_DONTWAIT) > 0)
                continue;
-       */
 
        if (verbose > 2)
                bb_simple_error_msg("closed");
-- 
2.25.1

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to