diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-05-12 06:45:18 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-05-12 06:45:18 +0000 |
commit | f2c43acacc67599829ef5d1c952c84f15658345f (patch) | |
tree | 4c7a6e1f527439e6a02c63d317a842fc8e0a9951 | |
parent | 84ec6a79caafa209fef4ac8e1b87769863a79346 (diff) | |
download | libmicrohttpd-f2c43acacc67599829ef5d1c952c84f15658345f.tar.gz libmicrohttpd-f2c43acacc67599829ef5d1c952c84f15658345f.zip |
fix epoll ready check reported by Chris Penev on the mailinglist
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 49 |
2 files changed, 30 insertions, 23 deletions
@@ -1,3 +1,7 @@ | |||
1 | Thu May 12 08:42:19 CEST 2016 | ||
2 | Fix handling of partial writes in MHD_USE_EPOLL_LINUX_ONLY; only | ||
3 | consider sockets returning EAGAIN as unready. -CG/CP | ||
4 | |||
1 | Mon May 2 06:08:26 CEST 2016 | 5 | Mon May 2 06:08:26 CEST 2016 |
2 | Adding logic to help address FE performance issue as | 6 | Adding logic to help address FE performance issue as |
3 | discussed on the mailinglist with subject | 7 | discussed on the mailinglist with subject |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 2c0e0a82..9f5c6b21 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -1144,9 +1144,6 @@ recv_param_adapter (struct MHD_Connection *connection, | |||
1144 | size_t i) | 1144 | size_t i) |
1145 | { | 1145 | { |
1146 | ssize_t ret; | 1146 | ssize_t ret; |
1147 | #if EPOLL_SUPPORT | ||
1148 | const size_t requested_size = i; | ||
1149 | #endif | ||
1150 | 1147 | ||
1151 | if ( (MHD_INVALID_SOCKET == connection->socket_fd) || | 1148 | if ( (MHD_INVALID_SOCKET == connection->socket_fd) || |
1152 | (MHD_CONNECTION_CLOSED == connection->state) ) | 1149 | (MHD_CONNECTION_CLOSED == connection->state) ) |
@@ -1162,11 +1159,14 @@ recv_param_adapter (struct MHD_Connection *connection, | |||
1162 | i = INT_MAX; /* return value limit */ | 1159 | i = INT_MAX; /* return value limit */ |
1163 | #endif /* MHD_WINSOCK_SOCKETS */ | 1160 | #endif /* MHD_WINSOCK_SOCKETS */ |
1164 | 1161 | ||
1165 | ret = (ssize_t)recv (connection->socket_fd, other, (_MHD_socket_funcs_size)i, MSG_NOSIGNAL); | 1162 | ret = (ssize_t) recv (connection->socket_fd, |
1163 | other, | ||
1164 | (_MHD_socket_funcs_size) i, | ||
1165 | MSG_NOSIGNAL); | ||
1166 | #if EPOLL_SUPPORT | 1166 | #if EPOLL_SUPPORT |
1167 | if ( (0 > ret) || (requested_size > (size_t) ret)) | 1167 | if ( (0 > ret) && (EAGAIN == MHD_socket_errno_) ) |
1168 | { | 1168 | { |
1169 | /* partial read --- no longer read-ready */ | 1169 | /* Got EAGAIN --- no longer read-ready */ |
1170 | connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY; | 1170 | connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY; |
1171 | } | 1171 | } |
1172 | #endif | 1172 | #endif |
@@ -1188,9 +1188,6 @@ send_param_adapter (struct MHD_Connection *connection, | |||
1188 | size_t i) | 1188 | size_t i) |
1189 | { | 1189 | { |
1190 | ssize_t ret; | 1190 | ssize_t ret; |
1191 | #if EPOLL_SUPPORT | ||
1192 | const size_t requested_size = i; | ||
1193 | #endif | ||
1194 | #if LINUX | 1191 | #if LINUX |
1195 | MHD_socket fd; | 1192 | MHD_socket fd; |
1196 | #endif | 1193 | #endif |
@@ -1210,7 +1207,10 @@ send_param_adapter (struct MHD_Connection *connection, | |||
1210 | #endif /* MHD_WINSOCK_SOCKETS */ | 1207 | #endif /* MHD_WINSOCK_SOCKETS */ |
1211 | 1208 | ||
1212 | if (0 != (connection->daemon->options & MHD_USE_SSL)) | 1209 | if (0 != (connection->daemon->options & MHD_USE_SSL)) |
1213 | return (ssize_t)send (connection->socket_fd, other, (_MHD_socket_funcs_size)i, MSG_NOSIGNAL); | 1210 | return (ssize_t) send (connection->socket_fd, |
1211 | other, | ||
1212 | (_MHD_socket_funcs_size) i, | ||
1213 | MSG_NOSIGNAL); | ||
1214 | #if LINUX | 1214 | #if LINUX |
1215 | if ( (connection->write_buffer_append_offset == | 1215 | if ( (connection->write_buffer_append_offset == |
1216 | connection->write_buffer_send_offset) && | 1216 | connection->write_buffer_send_offset) && |
@@ -1228,6 +1228,7 @@ send_param_adapter (struct MHD_Connection *connection, | |||
1228 | #endif /* HAVE_SENDFILE64 */ | 1228 | #endif /* HAVE_SENDFILE64 */ |
1229 | offsetu64 = connection->response_write_position + connection->response->fd_off; | 1229 | offsetu64 = connection->response_write_position + connection->response->fd_off; |
1230 | left = connection->response->total_size - connection->response_write_position; | 1230 | left = connection->response->total_size - connection->response_write_position; |
1231 | ret = 0; | ||
1231 | #ifndef HAVE_SENDFILE64 | 1232 | #ifndef HAVE_SENDFILE64 |
1232 | offset = (off_t) offsetu64; | 1233 | offset = (off_t) offsetu64; |
1233 | if ( (offsetu64 <= (uint64_t) OFF_T_MAX) && | 1234 | if ( (offsetu64 <= (uint64_t) OFF_T_MAX) && |
@@ -1237,17 +1238,18 @@ send_param_adapter (struct MHD_Connection *connection, | |||
1237 | if ( (offsetu64 <= (uint64_t) OFF64_T_MAX) && | 1238 | if ( (offsetu64 <= (uint64_t) OFF64_T_MAX) && |
1238 | (0 < (ret = sendfile64 (connection->socket_fd, fd, &offset, left))) ) | 1239 | (0 < (ret = sendfile64 (connection->socket_fd, fd, &offset, left))) ) |
1239 | #endif /* HAVE_SENDFILE64 */ | 1240 | #endif /* HAVE_SENDFILE64 */ |
1240 | { | 1241 | { |
1242 | /* write successful */ | ||
1243 | return ret; | ||
1244 | } | ||
1245 | err = MHD_socket_errno_; | ||
1241 | #if EPOLL_SUPPORT | 1246 | #if EPOLL_SUPPORT |
1242 | if (requested_size > (size_t) ret) | 1247 | if ( (0 > ret) && (EAGAIN == err) ) |
1243 | { | 1248 | { |
1244 | /* partial write --- no longer write-ready */ | 1249 | /* EAGAIN --- no longer write-ready */ |
1245 | connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; | 1250 | connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; |
1246 | } | 1251 | } |
1247 | #endif | 1252 | #endif |
1248 | return ret; | ||
1249 | } | ||
1250 | err = MHD_socket_errno_; | ||
1251 | if ( (EINTR == err) || (EAGAIN == err) || (EWOULDBLOCK == err) ) | 1253 | if ( (EINTR == err) || (EAGAIN == err) || (EWOULDBLOCK == err) ) |
1252 | return 0; | 1254 | return 0; |
1253 | if (EBADF == err) | 1255 | if (EBADF == err) |
@@ -1259,11 +1261,11 @@ send_param_adapter (struct MHD_Connection *connection, | |||
1259 | http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */ | 1261 | http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */ |
1260 | } | 1262 | } |
1261 | #endif | 1263 | #endif |
1262 | ret = (ssize_t)send (connection->socket_fd, other, (_MHD_socket_funcs_size)i, MSG_NOSIGNAL); | 1264 | ret = (ssize_t) send (connection->socket_fd, other, (_MHD_socket_funcs_size)i, MSG_NOSIGNAL); |
1263 | #if EPOLL_SUPPORT | 1265 | #if EPOLL_SUPPORT |
1264 | if ( (0 > ret) || (requested_size > (size_t) ret) ) | 1266 | if ( (0 > ret) || (EAGAIN == MHD_socket_errno_) ) |
1265 | { | 1267 | { |
1266 | /* partial write --- no longer write-ready */ | 1268 | /* EAGAIN --- no longer write-ready */ |
1267 | connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; | 1269 | connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; |
1268 | } | 1270 | } |
1269 | #endif | 1271 | #endif |
@@ -1282,7 +1284,8 @@ send_param_adapter (struct MHD_Connection *connection, | |||
1282 | * @param cls closure argument for the function | 1284 | * @param cls closure argument for the function |
1283 | * @return termination code from the thread | 1285 | * @return termination code from the thread |
1284 | */ | 1286 | */ |
1285 | typedef MHD_THRD_RTRN_TYPE_ (MHD_THRD_CALL_SPEC_ *ThreadStartRoutine)(void *cls); | 1287 | typedef MHD_THRD_RTRN_TYPE_ |
1288 | (MHD_THRD_CALL_SPEC_ *ThreadStartRoutine)(void *cls); | ||
1286 | 1289 | ||
1287 | 1290 | ||
1288 | /** | 1291 | /** |