aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-02-18 10:05:26 +0000
committerChristian Grothoff <christian@grothoff.org>2011-02-18 10:05:26 +0000
commit18177698ac76827da36d5d3d93bc0a4c86e7f2f9 (patch)
tree58aa588ad86b55ca3d8c63d59630bd799ea4c070 /src
parent74019e111cbdad0721c76018793e650b7d339ab1 (diff)
downloadlibmicrohttpd-18177698ac76827da36d5d3d93bc0a4c86e7f2f9.tar.gz
libmicrohttpd-18177698ac76827da36d5d3d93bc0a4c86e7f2f9.zip
try to handle sendfile corner cases better
Diffstat (limited to 'src')
-rw-r--r--src/daemon/daemon.c27
-rw-r--r--src/include/microhttpd.h2
2 files changed, 22 insertions, 7 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index d220973e..a9778c61 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -709,7 +709,8 @@ send_param_adapter (struct MHD_Connection *connection,
709#if LINUX 709#if LINUX
710 int fd; 710 int fd;
711 off_t offset; 711 off_t offset;
712 int ret; 712 off_t left;
713 ssize_t ret;
713#endif 714#endif
714 if (connection->socket_fd == -1) 715 if (connection->socket_fd == -1)
715 return -1; 716 return -1;
@@ -723,14 +724,28 @@ send_param_adapter (struct MHD_Connection *connection,
723 { 724 {
724 /* can use sendfile */ 725 /* can use sendfile */
725 offset = (off_t) connection->response_write_position + connection->response->fd_off; 726 offset = (off_t) connection->response_write_position + connection->response->fd_off;
727 left = connection->response->total_size - offset;
728 if (left > SSIZE_MAX)
729 left = SSIZE_MAX; /* cap at return value limit */
726 ret = sendfile (connection->socket_fd, 730 ret = sendfile (connection->socket_fd,
727 fd, 731 fd,
728 &offset, 732 &offset,
729 connection->response->total_size - offset); 733 left);
730 if ( (ret == -1) && 734 if (ret != -1)
731 (errno == EINTR) ) 735 return ret;
732 return 0; 736 if (ret == -1)
733 return ret; 737 {
738 if (EINTR == errno)
739 return 0;
740 if ( (EINVAL == errno) ||
741 (EBADF == errno) ||
742 (EAGAIN == errno) )
743 return -1;
744 /* None of the 'usual' sendfile errors occurred, so we should try
745 to fall back to 'SEND'; see also this thread for info on
746 odd libc/Linux behavior with sendfile:
747 http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */
748 }
734 } 749 }
735#endif 750#endif
736 return SEND (connection->socket_fd, other, i, MSG_NOSIGNAL | MSG_DONTWAIT); 751 return SEND (connection->socket_fd, other, i, MSG_NOSIGNAL | MSG_DONTWAIT);
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 67240fc8..e1bc1239 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -106,7 +106,7 @@ extern "C"
106/** 106/**
107 * Current version of the library. 107 * Current version of the library.
108 */ 108 */
109#define MHD_VERSION 0x00090700 109#define MHD_VERSION 0x00090701
110 110
111/** 111/**
112 * MHD-internal return code for "YES". 112 * MHD-internal return code for "YES".