libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit ce027a58ee2f50b2b20eba590d885530f12c7032
parent 156482cc4f1b0ea9b7fae0f41b4c483b29e97be4
Author: LRN <lrn1986@gmail.com>
Date:   Wed, 14 Aug 2013 05:55:35 +0000

W32: shutdown a socket for writing before closing it

Turns out that closing a socket while having unread data in recv buffer
causes winsock to terminate the connection without sending any pending
data.
This is fixed by shutting down socket for writing before closing it.


Diffstat:
Msrc/microhttpd/daemon.c | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -1582,9 +1582,14 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) MHD_destroy_response (pos->response); pos->response = NULL; } - if ( (-1 != pos->socket_fd) && - (0 != CLOSE (pos->socket_fd)) ) - MHD_PANIC ("close failed\n"); + if (-1 != pos->socket_fd) + { +#ifdef WINDOWS + SHUTDOWN (pos->socket_fd, SHUT_WR); +#endif + if (0 != CLOSE (pos->socket_fd)) + MHD_PANIC ("close failed\n"); + } if (NULL != pos->addr) free (pos->addr); free (pos);