libmicrohttpd

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

commit b1284bff7358c92b93bf311a81278c5a8607427c
parent 0692908cdbb5cf80de854c217702f6ea6d28595a
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 17 Nov 2007 07:56:19 +0000

sigpipe

Diffstat:
MChangeLog | 6++++++
MREADME | 11+++++++++++
Msrc/daemon/connection.c | 16++++++++++++----
Msrc/daemon/daemon.c | 14++++++++++++++
4 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,9 @@ +Sat Nov 17 00:55:24 MST 2007 + Fixed off-by-one in error message string matching. + Added code to avoid generating SIGPIPE on platforms + where this is possible (everywhere else, the main + application should install a handler for SIGPIPE). + Thu Oct 11 11:02:06 MDT 2007 Releasing libmicrohttpd 0.1.1. - CG diff --git a/README b/README @@ -27,6 +27,15 @@ space!). If you are concerned about space, you should set "CFLAGS" to resulting binary should be less than 25k (on x86). +Portability +=========== + +The latest version of libmicrohttpd will try to avoid SIGPIPE on its +sockets. This should work on OS X, Linux and recent BSD systems (at +least). On other systems that may trigger a SIGPIPE on send/recv, the +main application should install a signal handler to handle SIGPIPE. + + Development Status ================== @@ -67,3 +76,5 @@ Documentation: ============== - manual (texinfo, man) - tutorial + + diff --git a/src/daemon/connection.c b/src/daemon/connection.c @@ -32,6 +32,10 @@ #include "response.h" #include "reason_phrase.h" +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif + /** * Message to transmit when http 1.1 request is received */ @@ -888,7 +892,8 @@ MHD_connection_handle_read (struct MHD_Connection *connection) } bytes_read = RECV (connection->socket_fd, &connection->read_buffer[connection->readLoc], - connection->read_buffer_size - connection->readLoc, 0); + connection->read_buffer_size - connection->readLoc, + MSG_NOSIGNAL); if (bytes_read < 0) { if (errno == EINTR) @@ -1056,7 +1061,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) { ret = SEND (connection->socket_fd, &HTTP_100_CONTINUE[connection->continuePos], - strlen (HTTP_100_CONTINUE) - connection->continuePos, 0); + strlen (HTTP_100_CONTINUE) - connection->continuePos, + MSG_NOSIGNAL); if (ret < 0) { if (errno == EINTR) @@ -1099,7 +1105,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) } ret = SEND (connection->socket_fd, &connection->write_buffer[connection->writePos], - connection->writeLoc - connection->writePos, 0); + connection->writeLoc - connection->writePos, + MSG_NOSIGNAL); if (ret < 0) { if (errno == EINTR) @@ -1148,7 +1155,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) ret = SEND (connection->socket_fd, &response->data[connection->messagePos - response->data_start], response->data_size - (connection->messagePos - - response->data_start), 0); + response->data_start), + MSG_NOSIGNAL); if (response->crc != NULL) pthread_mutex_unlock (&response->mutex); if (ret < 0) diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c @@ -254,6 +254,9 @@ MHD_accept_connection (struct MHD_Daemon *daemon) struct sockaddr *addr = (struct sockaddr *) &addr6; socklen_t addrlen; int s; +#if OSX + static int on=1; +#endif if (sizeof (struct sockaddr) > sizeof (struct sockaddr_in6)) @@ -296,6 +299,17 @@ MHD_accept_connection (struct MHD_Daemon *daemon) CLOSE (s); return MHD_YES; } +#if OSX +#ifdef SOL_SOCKET +#ifdef SO_NOSIGPIPE + setsockopt(s, + SOL_SOCKET, + SO_NOSIGPIPE, + &on, + sizeof(on)); +#endif +#endif +#endif connection = malloc (sizeof (struct MHD_Connection)); if (connection == NULL) {