[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [RFC PATCH] httpd: handle HTTP upload case better
From:       Joachim Nilsson <troglobit () gmail ! com>
Date:       2020-05-09 11:26:43
Message-ID: 20200509112643.2449262-1-troglobit () gmail ! com
[Download RAW message or body]

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 <troglobit@gmail.com>
---
 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
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic