diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-04-16 17:58:14 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-04-16 17:58:14 +0300 |
commit | 99f2df6dea40624ff82b00ebe362e587f722985f (patch) | |
tree | 8e9647d22f9724dd6a21397ecaf77e3ce36904b3 /src | |
parent | 9829eb349801efd7bc89fc791bb0f9e8f18221a6 (diff) | |
download | libmicrohttpd-99f2df6dea40624ff82b00ebe362e587f722985f.tar.gz libmicrohttpd-99f2df6dea40624ff82b00ebe362e587f722985f.zip |
mhd_send: finally handle sockets errors in portable way
Diffstat (limited to 'src')
-rw-r--r-- | src/microhttpd/mhd_send.c | 72 | ||||
-rw-r--r-- | src/microhttpd/mhd_sockets.h | 6 |
2 files changed, 36 insertions, 42 deletions
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c index 02079c03..793df8d0 100644 --- a/src/microhttpd/mhd_send.c +++ b/src/microhttpd/mhd_send.c | |||
@@ -186,15 +186,17 @@ MHD_connection_set_nodelay_state_ (struct MHD_Connection *connection, | |||
186 | connection->sk_nodelay = nodelay_state; | 186 | connection->sk_nodelay = nodelay_state; |
187 | return true; | 187 | return true; |
188 | } | 188 | } |
189 | |||
189 | err_code = MHD_socket_get_error_ (); | 190 | err_code = MHD_socket_get_error_ (); |
190 | switch (err_code) | 191 | if (MHD_SCKT_ERR_IS_ (err_code, MHD_SCKT_EINVAL_) || |
192 | MHD_SCKT_ERR_IS_ (err_code, MHD_SCKT_ENOPROTOOPT_) || | ||
193 | MHD_SCKT_ERR_IS_ (err_code, MHD_SCKT_ENOTSOCK_)) | ||
191 | { | 194 | { |
192 | case EINVAL: | 195 | if (_MHD_UNKNOWN == connection->is_nonip) |
193 | case ENOPROTOOPT: | 196 | connection->is_nonip = _MHD_YES; |
194 | case ENOTSOCK: | ||
195 | if (_MHD_NO == connection->is_nonip) | ||
196 | { | ||
197 | #ifdef HAVE_MESSAGES | 197 | #ifdef HAVE_MESSAGES |
198 | else | ||
199 | { | ||
198 | MHD_DLOG (connection->daemon, | 200 | MHD_DLOG (connection->daemon, |
199 | _ ("Setting %s option to %s state failed " | 201 | _ ("Setting %s option to %s state failed " |
200 | "for TCP/IP socket %d: %s\n"), | 202 | "for TCP/IP socket %d: %s\n"), |
@@ -202,26 +204,20 @@ MHD_connection_set_nodelay_state_ (struct MHD_Connection *connection, | |||
202 | nodelay_state ? _ ("ON") : _ ("OFF"), | 204 | nodelay_state ? _ ("ON") : _ ("OFF"), |
203 | (int) connection->socket_fd, | 205 | (int) connection->socket_fd, |
204 | MHD_socket_strerr_ (err_code)); | 206 | MHD_socket_strerr_ (err_code)); |
205 | #endif /* HAVE_MESSAGES */ | ||
206 | } | 207 | } |
207 | else | 208 | #endif /* HAVE_MESSAGES */ |
208 | connection->is_nonip = _MHD_YES; | 209 | } |
209 | break; | ||
210 | case EBADF: | ||
211 | case EFAULT: | ||
212 | /* Hard errors, something is wrong. Too tricky to | ||
213 | * break connection here, just log the message. | ||
214 | * Shound't really happen too often. */ | ||
215 | default: | ||
216 | #ifdef HAVE_MESSAGES | 210 | #ifdef HAVE_MESSAGES |
211 | else | ||
212 | { | ||
217 | MHD_DLOG (connection->daemon, | 213 | MHD_DLOG (connection->daemon, |
218 | _ ("Setting %s option to %s state failed: %s\n"), | 214 | _ ("Setting %s option to %s state failed: %s\n"), |
219 | "TCP_NODELAY", | 215 | "TCP_NODELAY", |
220 | nodelay_state ? _ ("ON") : _ ("OFF"), | 216 | nodelay_state ? _ ("ON") : _ ("OFF"), |
221 | MHD_socket_strerr_ (err_code)); | 217 | MHD_socket_strerr_ (err_code)); |
222 | #endif /* HAVE_MESSAGES */ | ||
223 | break; | ||
224 | } | 218 | } |
219 | #endif /* HAVE_MESSAGES */ | ||
220 | |||
225 | return false; | 221 | return false; |
226 | } | 222 | } |
227 | 223 | ||
@@ -255,15 +251,17 @@ connection_set_cork_state_ (struct MHD_Connection *connection, | |||
255 | connection->sk_corked = cork_state; | 251 | connection->sk_corked = cork_state; |
256 | return true; | 252 | return true; |
257 | } | 253 | } |
254 | |||
258 | err_code = MHD_socket_get_error_ (); | 255 | err_code = MHD_socket_get_error_ (); |
259 | switch (err_code) | 256 | if (MHD_SCKT_ERR_IS_ (err_code, MHD_SCKT_EINVAL_) || |
257 | MHD_SCKT_ERR_IS_ (err_code, MHD_SCKT_ENOPROTOOPT_) || | ||
258 | MHD_SCKT_ERR_IS_ (err_code, MHD_SCKT_ENOTSOCK_)) | ||
260 | { | 259 | { |
261 | case EINVAL: | 260 | if (_MHD_UNKNOWN == connection->is_nonip) |
262 | case ENOPROTOOPT: | 261 | connection->is_nonip = _MHD_YES; |
263 | case ENOTSOCK: | ||
264 | if (_MHD_NO == connection->is_nonip) | ||
265 | { | ||
266 | #ifdef HAVE_MESSAGES | 262 | #ifdef HAVE_MESSAGES |
263 | else | ||
264 | { | ||
267 | MHD_DLOG (connection->daemon, | 265 | MHD_DLOG (connection->daemon, |
268 | _ ("Setting %s option to %s state failed " | 266 | _ ("Setting %s option to %s state failed " |
269 | "for TCP/IP socket %d: %s\n"), | 267 | "for TCP/IP socket %d: %s\n"), |
@@ -271,30 +269,20 @@ connection_set_cork_state_ (struct MHD_Connection *connection, | |||
271 | nodelay_state ? _ ("ON") : _ ("OFF"), | 269 | nodelay_state ? _ ("ON") : _ ("OFF"), |
272 | (int) connection->socket_fd, | 270 | (int) connection->socket_fd, |
273 | MHD_socket_strerr_ (err_code)); | 271 | MHD_socket_strerr_ (err_code)); |
274 | #endif /* HAVE_MESSAGES */ | ||
275 | } | 272 | } |
276 | else | 273 | #endif /* HAVE_MESSAGES */ |
277 | connection->is_nonip = _MHD_YES; | 274 | } |
278 | break; | ||
279 | case EBADF: | ||
280 | case EFAULT: | ||
281 | /* Hard errors, something is wrong. Too tricky to | ||
282 | * break connection here, just log the message. | ||
283 | * Shound't really happen too often. */ | ||
284 | default: | ||
285 | #ifdef HAVE_MESSAGES | 275 | #ifdef HAVE_MESSAGES |
276 | else | ||
277 | { | ||
286 | MHD_DLOG (connection->daemon, | 278 | MHD_DLOG (connection->daemon, |
287 | _ ("Setting %s option to %s state failed: %s\n"), | 279 | _ ("Setting %s option to %s state failed: %s\n"), |
288 | #ifdef TCP_CORK | 280 | "TCP_NODELAY", |
289 | "TCP_CORK", | 281 | nodelay_state ? _ ("ON") : _ ("OFF"), |
290 | #else /* ! TCP_CORK */ | ||
291 | "TCP_NOPUSH", | ||
292 | #endif /* ! TCP_CORK */ | ||
293 | cork_state ? _ ("ON") : _ ("OFF"), | ||
294 | MHD_socket_strerr_ (err_code)); | 282 | MHD_socket_strerr_ (err_code)); |
295 | #endif /* HAVE_MESSAGES */ | ||
296 | break; | ||
297 | } | 283 | } |
284 | #endif /* HAVE_MESSAGES */ | ||
285 | |||
298 | return false; | 286 | return false; |
299 | } | 287 | } |
300 | 288 | ||
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h index c22a1b12..b16a8b1a 100644 --- a/src/microhttpd/mhd_sockets.h +++ b/src/microhttpd/mhd_sockets.h | |||
@@ -567,6 +567,11 @@ typedef int MHD_SCKT_SEND_SIZE_; | |||
567 | # else /* ! ENOSYS */ | 567 | # else /* ! ENOSYS */ |
568 | # define MHD_SCKT_ENOSYS_ MHD_SCKT_MISSING_ERR_CODE_ | 568 | # define MHD_SCKT_ENOSYS_ MHD_SCKT_MISSING_ERR_CODE_ |
569 | # endif /* ! ENOSYS */ | 569 | # endif /* ! ENOSYS */ |
570 | # ifdef ENOPROTOOPT | ||
571 | # define MHD_SCKT_ENOPROTOOPT_ ENOPROTOOPT | ||
572 | # else /* ! ENOPROTOOPT */ | ||
573 | # define MHD_SCKT_ENOSYS_ MHD_SCKT_MISSING_ERR_CODE_ | ||
574 | # endif /* ! ENOPROTOOPT */ | ||
570 | # ifdef ENOTSUP | 575 | # ifdef ENOTSUP |
571 | # define MHD_SCKT_ENOTSUP_ ENOTSUP | 576 | # define MHD_SCKT_ENOTSUP_ ENOTSUP |
572 | # else /* ! ENOTSUP */ | 577 | # else /* ! ENOTSUP */ |
@@ -603,6 +608,7 @@ typedef int MHD_SCKT_SEND_SIZE_; | |||
603 | # define MHD_SCKT_EINVAL_ WSAEINVAL | 608 | # define MHD_SCKT_EINVAL_ WSAEINVAL |
604 | # define MHD_SCKT_EFAUL_ WSAEFAULT | 609 | # define MHD_SCKT_EFAUL_ WSAEFAULT |
605 | # define MHD_SCKT_ENOSYS_ MHD_SCKT_MISSING_ERR_CODE_ | 610 | # define MHD_SCKT_ENOSYS_ MHD_SCKT_MISSING_ERR_CODE_ |
611 | # define MHD_SCKT_ENOPROTOOPT_ WSAENOPROTOOPT | ||
606 | # define MHD_SCKT_ENOTSUP_ MHD_SCKT_MISSING_ERR_CODE_ | 612 | # define MHD_SCKT_ENOTSUP_ MHD_SCKT_MISSING_ERR_CODE_ |
607 | # define MHD_SCKT_EOPNOTSUPP_ WSAEOPNOTSUPP | 613 | # define MHD_SCKT_EOPNOTSUPP_ WSAEOPNOTSUPP |
608 | # define MHD_SCKT_EACCESS_ WSAEACCES | 614 | # define MHD_SCKT_EACCESS_ WSAEACCES |