diff options
Diffstat (limited to 'src/microhttpd/mhd_sockets.h')
-rw-r--r-- | src/microhttpd/mhd_sockets.h | 239 |
1 files changed, 141 insertions, 98 deletions
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h index 08b01c20..3099357b 100644 --- a/src/microhttpd/mhd_sockets.h +++ b/src/microhttpd/mhd_sockets.h | |||
@@ -37,8 +37,8 @@ | |||
37 | #include <errno.h> | 37 | #include <errno.h> |
38 | #include <stdbool.h> | 38 | #include <stdbool.h> |
39 | 39 | ||
40 | #if !defined(MHD_POSIX_SOCKETS) && !defined(MHD_WINSOCK_SOCKETS) | 40 | #if ! defined(MHD_POSIX_SOCKETS) && ! defined(MHD_WINSOCK_SOCKETS) |
41 | # if !defined(_WIN32) || defined(__CYGWIN__) | 41 | # if ! defined(_WIN32) || defined(__CYGWIN__) |
42 | # define MHD_POSIX_SOCKETS 1 | 42 | # define MHD_POSIX_SOCKETS 1 |
43 | # else /* defined(_WIN32) && !defined(__CYGWIN__) */ | 43 | # else /* defined(_WIN32) && !defined(__CYGWIN__) */ |
44 | # define MHD_WINSOCK_SOCKETS 1 | 44 | # define MHD_WINSOCK_SOCKETS 1 |
@@ -93,7 +93,7 @@ | |||
93 | # include <sys/epoll.h> | 93 | # include <sys/epoll.h> |
94 | # endif | 94 | # endif |
95 | # ifdef HAVE_NETINET_TCP_H | 95 | # ifdef HAVE_NETINET_TCP_H |
96 | /* for TCP_FASTOPEN and TCP_CORK */ | 96 | /* for TCP_FASTOPEN and TCP_CORK */ |
97 | # include <netinet/tcp.h> | 97 | # include <netinet/tcp.h> |
98 | # endif | 98 | # endif |
99 | # ifdef HAVE_STRING_H | 99 | # ifdef HAVE_STRING_H |
@@ -112,10 +112,10 @@ | |||
112 | #endif | 112 | #endif |
113 | 113 | ||
114 | #include <stddef.h> | 114 | #include <stddef.h> |
115 | #if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED) | 115 | #if defined(_MSC_FULL_VER) && ! defined (_SSIZE_T_DEFINED) |
116 | # include <stdint.h> | 116 | # include <stdint.h> |
117 | # define _SSIZE_T_DEFINED | 117 | # define _SSIZE_T_DEFINED |
118 | typedef intptr_t ssize_t; | 118 | typedef intptr_t ssize_t; |
119 | #endif /* !_SSIZE_T_DEFINED */ | 119 | #endif /* !_SSIZE_T_DEFINED */ |
120 | 120 | ||
121 | #include "mhd_limits.h" | 121 | #include "mhd_limits.h" |
@@ -124,7 +124,7 @@ | |||
124 | # define _MHD_SYS_DEFAULT_FD_SETSIZE FD_SETSIZE | 124 | # define _MHD_SYS_DEFAULT_FD_SETSIZE FD_SETSIZE |
125 | #else /* ! _MHD_FD_SETSIZE_IS_DEFAULT */ | 125 | #else /* ! _MHD_FD_SETSIZE_IS_DEFAULT */ |
126 | # include "sysfdsetsize.h" | 126 | # include "sysfdsetsize.h" |
127 | # define _MHD_SYS_DEFAULT_FD_SETSIZE get_system_fdsetsize_value() | 127 | # define _MHD_SYS_DEFAULT_FD_SETSIZE get_system_fdsetsize_value () |
128 | #endif /* ! _MHD_FD_SETSIZE_IS_DEFAULT */ | 128 | #endif /* ! _MHD_FD_SETSIZE_IS_DEFAULT */ |
129 | 129 | ||
130 | #ifndef MHD_PANIC | 130 | #ifndef MHD_PANIC |
@@ -132,8 +132,9 @@ | |||
132 | # include <stdlib.h> | 132 | # include <stdlib.h> |
133 | /* Simple implementation of MHD_PANIC, to be used outside lib */ | 133 | /* Simple implementation of MHD_PANIC, to be used outside lib */ |
134 | # define MHD_PANIC(msg) do { fprintf (stderr, \ | 134 | # define MHD_PANIC(msg) do { fprintf (stderr, \ |
135 | "Abnormal termination at %d line in file %s: %s\n", \ | 135 | "Abnormal termination at %d line in file %s: %s\n", \ |
136 | (int)__LINE__, __FILE__, msg); abort();} while(0) | 136 | (int) __LINE__, __FILE__, msg); abort (); \ |
137 | } while (0) | ||
137 | #endif /* ! MHD_PANIC */ | 138 | #endif /* ! MHD_PANIC */ |
138 | 139 | ||
139 | #ifndef MHD_SOCKET_DEFINED | 140 | #ifndef MHD_SOCKET_DEFINED |
@@ -141,10 +142,10 @@ | |||
141 | * MHD_socket is type for socket FDs | 142 | * MHD_socket is type for socket FDs |
142 | */ | 143 | */ |
143 | # if defined(MHD_POSIX_SOCKETS) | 144 | # if defined(MHD_POSIX_SOCKETS) |
144 | typedef int MHD_socket; | 145 | typedef int MHD_socket; |
145 | # define MHD_INVALID_SOCKET (-1) | 146 | # define MHD_INVALID_SOCKET (-1) |
146 | # elif defined(MHD_WINSOCK_SOCKETS) | 147 | # elif defined(MHD_WINSOCK_SOCKETS) |
147 | typedef SOCKET MHD_socket; | 148 | typedef SOCKET MHD_socket; |
148 | # define MHD_INVALID_SOCKET (INVALID_SOCKET) | 149 | # define MHD_INVALID_SOCKET (INVALID_SOCKET) |
149 | # endif /* MHD_WINSOCK_SOCKETS */ | 150 | # endif /* MHD_WINSOCK_SOCKETS */ |
150 | 151 | ||
@@ -175,17 +176,18 @@ | |||
175 | # define MAYBE_MSG_NOSIGNAL 0 | 176 | # define MAYBE_MSG_NOSIGNAL 0 |
176 | #endif /* ! MSG_NOSIGNAL */ | 177 | #endif /* ! MSG_NOSIGNAL */ |
177 | 178 | ||
178 | #if !defined(SHUT_WR) && defined(SD_SEND) | 179 | #if ! defined(SHUT_WR) && defined(SD_SEND) |
179 | # define SHUT_WR SD_SEND | 180 | # define SHUT_WR SD_SEND |
180 | #endif | 181 | #endif |
181 | #if !defined(SHUT_RD) && defined(SD_RECEIVE) | 182 | #if ! defined(SHUT_RD) && defined(SD_RECEIVE) |
182 | # define SHUT_RD SD_RECEIVE | 183 | # define SHUT_RD SD_RECEIVE |
183 | #endif | 184 | #endif |
184 | #if !defined(SHUT_RDWR) && defined(SD_BOTH) | 185 | #if ! defined(SHUT_RDWR) && defined(SD_BOTH) |
185 | # define SHUT_RDWR SD_BOTH | 186 | # define SHUT_RDWR SD_BOTH |
186 | #endif | 187 | #endif |
187 | 188 | ||
188 | #if HAVE_ACCEPT4+0 != 0 && (defined(HAVE_SOCK_NONBLOCK) || defined(SOCK_CLOEXEC) || defined(SOCK_NOSIGPIPE)) | 189 | #if HAVE_ACCEPT4 + 0 != 0 && (defined(HAVE_SOCK_NONBLOCK) || \ |
190 | defined(SOCK_CLOEXEC) || defined(SOCK_NOSIGPIPE)) | ||
189 | # define USE_ACCEPT4 1 | 191 | # define USE_ACCEPT4 1 |
190 | #endif | 192 | #endif |
191 | 193 | ||
@@ -218,25 +220,25 @@ | |||
218 | * MHD_SCKT_OPT_BOOL_ is type for bool parameters for setsockopt()/getsockopt() | 220 | * MHD_SCKT_OPT_BOOL_ is type for bool parameters for setsockopt()/getsockopt() |
219 | */ | 221 | */ |
220 | #ifdef MHD_POSIX_SOCKETS | 222 | #ifdef MHD_POSIX_SOCKETS |
221 | typedef int MHD_SCKT_OPT_BOOL_; | 223 | typedef int MHD_SCKT_OPT_BOOL_; |
222 | #else /* MHD_WINSOCK_SOCKETS */ | 224 | #else /* MHD_WINSOCK_SOCKETS */ |
223 | typedef BOOL MHD_SCKT_OPT_BOOL_; | 225 | typedef BOOL MHD_SCKT_OPT_BOOL_; |
224 | #endif /* MHD_WINSOCK_SOCKETS */ | 226 | #endif /* MHD_WINSOCK_SOCKETS */ |
225 | 227 | ||
226 | /** | 228 | /** |
227 | * MHD_SCKT_SEND_SIZE_ is type used to specify size for send and recv | 229 | * MHD_SCKT_SEND_SIZE_ is type used to specify size for send and recv |
228 | * functions | 230 | * functions |
229 | */ | 231 | */ |
230 | #if !defined(MHD_WINSOCK_SOCKETS) | 232 | #if ! defined(MHD_WINSOCK_SOCKETS) |
231 | typedef size_t MHD_SCKT_SEND_SIZE_; | 233 | typedef size_t MHD_SCKT_SEND_SIZE_; |
232 | #else | 234 | #else |
233 | typedef int MHD_SCKT_SEND_SIZE_; | 235 | typedef int MHD_SCKT_SEND_SIZE_; |
234 | #endif | 236 | #endif |
235 | 237 | ||
236 | /** | 238 | /** |
237 | * MHD_SCKT_SEND_MAX_SIZE_ is maximum send()/recv() size value. | 239 | * MHD_SCKT_SEND_MAX_SIZE_ is maximum send()/recv() size value. |
238 | */ | 240 | */ |
239 | #if !defined(MHD_WINSOCK_SOCKETS) | 241 | #if ! defined(MHD_WINSOCK_SOCKETS) |
240 | # define MHD_SCKT_SEND_MAX_SIZE_ SSIZE_MAX | 242 | # define MHD_SCKT_SEND_MAX_SIZE_ SSIZE_MAX |
241 | #else | 243 | #else |
242 | # define MHD_SCKT_SEND_MAX_SIZE_ INT_MAX | 244 | # define MHD_SCKT_SEND_MAX_SIZE_ INT_MAX |
@@ -252,10 +254,10 @@ | |||
252 | * counted as success, only EBADF counts as an error!), | 254 | * counted as success, only EBADF counts as an error!), |
253 | * boolean false otherwise. | 255 | * boolean false otherwise. |
254 | */ | 256 | */ |
255 | #if !defined(MHD_WINSOCK_SOCKETS) | 257 | #if ! defined(MHD_WINSOCK_SOCKETS) |
256 | # define MHD_socket_close_(fd) ((0 == close((fd))) || (EBADF != errno)) | 258 | # define MHD_socket_close_(fd) ((0 == close ((fd))) || (EBADF != errno)) |
257 | #else | 259 | #else |
258 | # define MHD_socket_close_(fd) (0 == closesocket((fd))) | 260 | # define MHD_socket_close_(fd) (0 == closesocket ((fd))) |
259 | #endif | 261 | #endif |
260 | 262 | ||
261 | /** | 263 | /** |
@@ -264,9 +266,9 @@ | |||
264 | * @param fd socket to close | 266 | * @param fd socket to close |
265 | */ | 267 | */ |
266 | #define MHD_socket_close_chk_(fd) do { \ | 268 | #define MHD_socket_close_chk_(fd) do { \ |
267 | if (!MHD_socket_close_(fd)) \ | 269 | if (! MHD_socket_close_ (fd)) \ |
268 | MHD_PANIC(_("Close socket failed.\n")); \ | 270 | MHD_PANIC (_ ("Close socket failed.\n")); \ |
269 | } while(0) | 271 | } while (0) |
270 | 272 | ||
271 | 273 | ||
272 | /** | 274 | /** |
@@ -277,7 +279,8 @@ | |||
277 | * @return ssize_t type value | 279 | * @return ssize_t type value |
278 | */ | 280 | */ |
279 | #define MHD_send_(s,b,l) \ | 281 | #define MHD_send_(s,b,l) \ |
280 | ((ssize_t)send((s),(const void*)(b),(MHD_SCKT_SEND_SIZE_)(l), MAYBE_MSG_NOSIGNAL)) | 282 | ((ssize_t) send ((s),(const void*) (b),(MHD_SCKT_SEND_SIZE_) (l), \ |
283 | MAYBE_MSG_NOSIGNAL)) | ||
281 | 284 | ||
282 | 285 | ||
283 | /** | 286 | /** |
@@ -288,7 +291,7 @@ | |||
288 | * @return ssize_t type value | 291 | * @return ssize_t type value |
289 | */ | 292 | */ |
290 | #define MHD_recv_(s,b,l) \ | 293 | #define MHD_recv_(s,b,l) \ |
291 | ((ssize_t)recv((s),(void*)(b),(MHD_SCKT_SEND_SIZE_)(l), 0)) | 294 | ((ssize_t) recv ((s),(void*) (b),(MHD_SCKT_SEND_SIZE_) (l), 0)) |
292 | 295 | ||
293 | 296 | ||
294 | /** | 297 | /** |
@@ -301,11 +304,18 @@ | |||
301 | * boolean false otherwise. | 304 | * boolean false otherwise. |
302 | */ | 305 | */ |
303 | #if defined(MHD_POSIX_SOCKETS) | 306 | #if defined(MHD_POSIX_SOCKETS) |
304 | # define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ((fd) < ((MHD_socket)setsize)) | 307 | # define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ((fd) < \ |
308 | ((MHD_socket) \ | ||
309 | setsize)) | ||
305 | #elif defined(MHD_WINSOCK_SOCKETS) | 310 | #elif defined(MHD_WINSOCK_SOCKETS) |
306 | # define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ( ((void*)(pset)==(void*)0) || \ | 311 | # define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ( ((void*) (pset)== \ |
307 | (((fd_set*)(pset))->fd_count < ((unsigned)setsize)) || \ | 312 | (void*) 0) || \ |
308 | (FD_ISSET((fd),(pset))) ) | 313 | (((fd_set*) (pset)) \ |
314 | ->fd_count < \ | ||
315 | ((unsigned) \ | ||
316 | setsize)) || \ | ||
317 | (FD_ISSET ((fd), \ | ||
318 | (pset))) ) | ||
309 | #endif | 319 | #endif |
310 | 320 | ||
311 | /** | 321 | /** |
@@ -316,7 +326,9 @@ | |||
316 | * @return boolean true if FD can be added to fd_set, | 326 | * @return boolean true if FD can be added to fd_set, |
317 | * boolean false otherwise. | 327 | * boolean false otherwise. |
318 | */ | 328 | */ |
319 | #define MHD_SCKT_FD_FITS_FDSET_(fd,pset) MHD_SCKT_FD_FITS_FDSET_SETSIZE_((fd),(pset),FD_SETSIZE) | 329 | #define MHD_SCKT_FD_FITS_FDSET_(fd,pset) MHD_SCKT_FD_FITS_FDSET_SETSIZE_ ((fd), \ |
330 | (pset), \ | ||
331 | FD_SETSIZE) | ||
320 | 332 | ||
321 | /** | 333 | /** |
322 | * Add FD to fd_set with specified FD_SETSIZE. | 334 | * Add FD to fd_set with specified FD_SETSIZE. |
@@ -327,34 +339,35 @@ | |||
327 | * system definition of FD_SET() is not used. | 339 | * system definition of FD_SET() is not used. |
328 | */ | 340 | */ |
329 | #if defined(MHD_POSIX_SOCKETS) | 341 | #if defined(MHD_POSIX_SOCKETS) |
330 | # define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) FD_SET((fd),(pset)) | 342 | # define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) FD_SET ((fd), \ |
343 | (pset)) | ||
331 | #elif defined(MHD_WINSOCK_SOCKETS) | 344 | #elif defined(MHD_WINSOCK_SOCKETS) |
332 | # define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) \ | 345 | # define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) \ |
333 | do { \ | 346 | do { \ |
334 | u_int _i_ = 0; \ | 347 | u_int _i_ = 0; \ |
335 | fd_set* const _s_ = (fd_set*)(pset); \ | 348 | fd_set*const _s_ = (fd_set*) (pset); \ |
336 | while((_i_ < _s_->fd_count) && ((fd) != _s_->fd_array[_i_])) {++_i_;} \ | 349 | while ((_i_ < _s_->fd_count) && ((fd) != _s_->fd_array [_i_])) {++_i_;} \ |
337 | if ((_i_ == _s_->fd_count)) {_s_->fd_array[_s_->fd_count++] = (fd);} \ | 350 | if ((_i_ == _s_->fd_count)) {_s_->fd_array [_s_->fd_count ++] = (fd);} \ |
338 | } while(0) | 351 | } while (0) |
339 | #endif | 352 | #endif |
340 | 353 | ||
341 | /* MHD_SYS_select_ is wrapper macro for system select() function */ | 354 | /* MHD_SYS_select_ is wrapper macro for system select() function */ |
342 | #if !defined(MHD_WINSOCK_SOCKETS) | 355 | #if ! defined(MHD_WINSOCK_SOCKETS) |
343 | # define MHD_SYS_select_(n,r,w,e,t) select((n),(r),(w),(e),(t)) | 356 | # define MHD_SYS_select_(n,r,w,e,t) select ((n),(r),(w),(e),(t)) |
344 | #else | 357 | #else |
345 | # define MHD_SYS_select_(n,r,w,e,t) \ | 358 | # define MHD_SYS_select_(n,r,w,e,t) \ |
346 | ( ( (((void*)(r) == (void*)0) || ((fd_set*)(r))->fd_count == 0) && \ | 359 | ( ( (((void*) (r) == (void*) 0) || ((fd_set*) (r))->fd_count == 0) && \ |
347 | (((void*)(w) == (void*)0) || ((fd_set*)(w))->fd_count == 0) && \ | 360 | (((void*) (w) == (void*) 0) || ((fd_set*) (w))->fd_count == 0) && \ |
348 | (((void*)(e) == (void*)0) || ((fd_set*)(e))->fd_count == 0) ) ? \ | 361 | (((void*) (e) == (void*) 0) || ((fd_set*) (e))->fd_count == 0) ) ? \ |
349 | ( ((void*)(t) == (void*)0) ? 0 : \ | 362 | ( ((void*) (t) == (void*) 0) ? 0 : \ |
350 | (Sleep(((struct timeval*)(t))->tv_sec * 1000 + \ | 363 | (Sleep (((struct timeval*) (t))->tv_sec * 1000 \ |
351 | ((struct timeval*)(t))->tv_usec / 1000), 0) ) : \ | 364 | + ((struct timeval*) (t))->tv_usec / 1000), 0) ) : \ |
352 | (select((int)0,(r),(w),(e),(t))) ) | 365 | (select ((int) 0,(r),(w),(e),(t))) ) |
353 | #endif | 366 | #endif |
354 | 367 | ||
355 | #if defined(HAVE_POLL) | 368 | #if defined(HAVE_POLL) |
356 | /* MHD_sys_poll_ is wrapper macro for system poll() function */ | 369 | /* MHD_sys_poll_ is wrapper macro for system poll() function */ |
357 | # if !defined(MHD_WINSOCK_SOCKETS) | 370 | # if ! defined(MHD_WINSOCK_SOCKETS) |
358 | # define MHD_sys_poll_ poll | 371 | # define MHD_sys_poll_ poll |
359 | # else /* MHD_WINSOCK_SOCKETS */ | 372 | # else /* MHD_WINSOCK_SOCKETS */ |
360 | # define MHD_sys_poll_ WSAPoll | 373 | # define MHD_sys_poll_ WSAPoll |
@@ -383,16 +396,19 @@ | |||
383 | # elif defined(__linux__) | 396 | # elif defined(__linux__) |
384 | # define MHD_POLL_EVENTS_ERR_DISC POLLPRI | 397 | # define MHD_POLL_EVENTS_ERR_DISC POLLPRI |
385 | # else /* ! __linux__ */ | 398 | # else /* ! __linux__ */ |
386 | # define MHD_POLL_EVENTS_ERR_DISC (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO) | 399 | # define MHD_POLL_EVENTS_ERR_DISC (MHD_POLLPRI_OR_ZERO \ |
400 | | MHD_POLLRDBAND_OR_ZERO) | ||
387 | # endif /* ! __linux__ */ | 401 | # endif /* ! __linux__ */ |
388 | /* MHD_POLL_REVENTS_ERR_DISC is 'revents' mask for errors and disconnect. | 402 | /* MHD_POLL_REVENTS_ERR_DISC is 'revents' mask for errors and disconnect. |
389 | * Note: Out-of-band data is treated as error. */ | 403 | * Note: Out-of-band data is treated as error. */ |
390 | # define MHD_POLL_REVENTS_ERR_DISC \ | 404 | # define MHD_POLL_REVENTS_ERR_DISC \ |
391 | (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO | POLLERR | POLLHUP) | 405 | (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO \ |
406 | | POLLERR | POLLHUP) | ||
392 | /* MHD_POLL_REVENTS_ERRROR is 'revents' mask for errors. | 407 | /* MHD_POLL_REVENTS_ERRROR is 'revents' mask for errors. |
393 | * Note: Out-of-band data is treated as error. */ | 408 | * Note: Out-of-band data is treated as error. */ |
394 | # define MHD_POLL_REVENTS_ERRROR \ | 409 | # define MHD_POLL_REVENTS_ERRROR \ |
395 | (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO | POLLERR) | 410 | (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO \ |
411 | | POLLERR) | ||
396 | #endif /* HAVE_POLL */ | 412 | #endif /* HAVE_POLL */ |
397 | 413 | ||
398 | #define MHD_SCKT_MISSING_ERR_CODE_ 31450 | 414 | #define MHD_SCKT_MISSING_ERR_CODE_ 31450 |
@@ -526,30 +542,30 @@ | |||
526 | #if defined(MHD_POSIX_SOCKETS) | 542 | #if defined(MHD_POSIX_SOCKETS) |
527 | # define MHD_socket_get_error_() (errno) | 543 | # define MHD_socket_get_error_() (errno) |
528 | #elif defined(MHD_WINSOCK_SOCKETS) | 544 | #elif defined(MHD_WINSOCK_SOCKETS) |
529 | # define MHD_socket_get_error_() WSAGetLastError() | 545 | # define MHD_socket_get_error_() WSAGetLastError () |
530 | #endif | 546 | #endif |
531 | 547 | ||
532 | #ifdef MHD_WINSOCK_SOCKETS | 548 | #ifdef MHD_WINSOCK_SOCKETS |
533 | /* POSIX-W32 sockets compatibility functions */ | 549 | /* POSIX-W32 sockets compatibility functions */ |
534 | 550 | ||
535 | /** | 551 | /** |
536 | * Return pointer to string description of specified WinSock error | 552 | * Return pointer to string description of specified WinSock error |
537 | * @param err the WinSock error code. | 553 | * @param err the WinSock error code. |
538 | * @return pointer to string description of specified WinSock error. | 554 | * @return pointer to string description of specified WinSock error. |
539 | */ | 555 | */ |
540 | const char* MHD_W32_strerror_winsock_(int err); | 556 | const char*MHD_W32_strerror_winsock_ (int err); |
541 | #endif /* MHD_WINSOCK_SOCKETS */ | 557 | #endif /* MHD_WINSOCK_SOCKETS */ |
542 | 558 | ||
543 | /* MHD_socket_last_strerr_ is description string of specified socket error code */ | 559 | /* MHD_socket_last_strerr_ is description string of specified socket error code */ |
544 | #if defined(MHD_POSIX_SOCKETS) | 560 | #if defined(MHD_POSIX_SOCKETS) |
545 | # define MHD_socket_strerr_(err) strerror((err)) | 561 | # define MHD_socket_strerr_(err) strerror ((err)) |
546 | #elif defined(MHD_WINSOCK_SOCKETS) | 562 | #elif defined(MHD_WINSOCK_SOCKETS) |
547 | # define MHD_socket_strerr_(err) MHD_W32_strerror_winsock_((err)) | 563 | # define MHD_socket_strerr_(err) MHD_W32_strerror_winsock_ ((err)) |
548 | #endif | 564 | #endif |
549 | 565 | ||
550 | /* MHD_socket_last_strerr_ is description string of last errno (non-W32) / | 566 | /* MHD_socket_last_strerr_ is description string of last errno (non-W32) / |
551 | * description string of last socket error (W32) */ | 567 | * description string of last socket error (W32) */ |
552 | #define MHD_socket_last_strerr_() MHD_socket_strerr_(MHD_socket_get_error_()) | 568 | #define MHD_socket_last_strerr_() MHD_socket_strerr_ (MHD_socket_get_error_ ()) |
553 | 569 | ||
554 | /** | 570 | /** |
555 | * MHD_socket_fset_error_() set socket system native error code. | 571 | * MHD_socket_fset_error_() set socket system native error code. |
@@ -557,7 +573,7 @@ | |||
557 | #if defined(MHD_POSIX_SOCKETS) | 573 | #if defined(MHD_POSIX_SOCKETS) |
558 | # define MHD_socket_fset_error_(err) (errno = (err)) | 574 | # define MHD_socket_fset_error_(err) (errno = (err)) |
559 | #elif defined(MHD_WINSOCK_SOCKETS) | 575 | #elif defined(MHD_WINSOCK_SOCKETS) |
560 | # define MHD_socket_fset_error_(err) (WSASetLastError((err))) | 576 | # define MHD_socket_fset_error_(err) (WSASetLastError ((err))) |
561 | #endif | 577 | #endif |
562 | 578 | ||
563 | /** | 579 | /** |
@@ -569,7 +585,8 @@ | |||
569 | * and error was not set. | 585 | * and error was not set. |
570 | */ | 586 | */ |
571 | #define MHD_socket_try_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ != (err)) ? \ | 587 | #define MHD_socket_try_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ != (err)) ? \ |
572 | (MHD_socket_fset_error_((err)), !0) : 0 ) | 588 | (MHD_socket_fset_error_ ((err)), ! 0) : \ |
589 | 0) | ||
573 | 590 | ||
574 | /** | 591 | /** |
575 | * MHD_socket_set_error_() set socket system native error code to | 592 | * MHD_socket_set_error_() set socket system native error code to |
@@ -582,7 +599,8 @@ | |||
582 | (errno = ENOSYS) : (errno = (err)) ) | 599 | (errno = ENOSYS) : (errno = (err)) ) |
583 | # elif defined(EOPNOTSUPP) | 600 | # elif defined(EOPNOTSUPP) |
584 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ | 601 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ |
585 | (errno = EOPNOTSUPP) : (errno = (err)) ) | 602 | (errno = EOPNOTSUPP) : (errno = \ |
603 | (err)) ) | ||
586 | # elif defined (EFAULT) | 604 | # elif defined (EFAULT) |
587 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ | 605 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ |
588 | (errno = EFAULT) : (errno = (err)) ) | 606 | (errno = EFAULT) : (errno = (err)) ) |
@@ -590,13 +608,14 @@ | |||
590 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ | 608 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ |
591 | (errno = EINVAL) : (errno = (err)) ) | 609 | (errno = EINVAL) : (errno = (err)) ) |
592 | # else /* !EOPNOTSUPP && !EFAULT && !EINVAL */ | 610 | # else /* !EOPNOTSUPP && !EFAULT && !EINVAL */ |
593 | # warning No suitable replacement for missing socket error code is found. Edit this file and add replacement code which is defined on system. | 611 | # warning \ |
612 | No suitable replacement for missing socket error code is found. Edit this file and add replacement code which is defined on system. | ||
594 | # define MHD_socket_set_error_(err) (errno = (err)) | 613 | # define MHD_socket_set_error_(err) (errno = (err)) |
595 | # endif /* !EOPNOTSUPP && !EFAULT && !EINVAL*/ | 614 | # endif /* !EOPNOTSUPP && !EFAULT && !EINVAL*/ |
596 | #elif defined(MHD_WINSOCK_SOCKETS) | 615 | #elif defined(MHD_WINSOCK_SOCKETS) |
597 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ | 616 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ |
598 | (WSASetLastError((WSAEOPNOTSUPP))) : \ | 617 | (WSASetLastError ((WSAEOPNOTSUPP))) : \ |
599 | (WSASetLastError((err))) ) | 618 | (WSASetLastError ((err))) ) |
600 | #endif | 619 | #endif |
601 | 620 | ||
602 | /** | 621 | /** |
@@ -620,7 +639,8 @@ | |||
620 | * last socket error equals to MHD_SCKT_E*_ @a code; | 639 | * last socket error equals to MHD_SCKT_E*_ @a code; |
621 | * boolean false otherwise | 640 | * boolean false otherwise |
622 | */ | 641 | */ |
623 | #define MHD_SCKT_LAST_ERR_IS_(code) MHD_SCKT_ERR_IS_(MHD_socket_get_error_() ,(code)) | 642 | #define MHD_SCKT_LAST_ERR_IS_(code) MHD_SCKT_ERR_IS_ (MHD_socket_get_error_ (), \ |
643 | (code)) | ||
624 | 644 | ||
625 | /* Specific error code checks */ | 645 | /* Specific error code checks */ |
626 | 646 | ||
@@ -630,7 +650,7 @@ | |||
630 | * @return boolean true if @a err is equal to sockets' EINTR code; | 650 | * @return boolean true if @a err is equal to sockets' EINTR code; |
631 | * boolean false otherwise. | 651 | * boolean false otherwise. |
632 | */ | 652 | */ |
633 | #define MHD_SCKT_ERR_IS_EINTR_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_EINTR_) | 653 | #define MHD_SCKT_ERR_IS_EINTR_(err) MHD_SCKT_ERR_IS_ ((err),MHD_SCKT_EINTR_) |
634 | 654 | ||
635 | /** | 655 | /** |
636 | * Check whether given socket error is equal to system's | 656 | * Check whether given socket error is equal to system's |
@@ -639,10 +659,12 @@ | |||
639 | * boolean false otherwise. | 659 | * boolean false otherwise. |
640 | */ | 660 | */ |
641 | #if MHD_SCKT_EAGAIN_ == MHD_SCKT_EWOULDBLOCK_ | 661 | #if MHD_SCKT_EAGAIN_ == MHD_SCKT_EWOULDBLOCK_ |
642 | # define MHD_SCKT_ERR_IS_EAGAIN_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_EAGAIN_) | 662 | # define MHD_SCKT_ERR_IS_EAGAIN_(err) MHD_SCKT_ERR_IS_ ((err),MHD_SCKT_EAGAIN_) |
643 | #else /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ | 663 | #else /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ |
644 | # define MHD_SCKT_ERR_IS_EAGAIN_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_EAGAIN_) || \ | 664 | # define MHD_SCKT_ERR_IS_EAGAIN_(err) (MHD_SCKT_ERR_IS_ ((err), \ |
645 | MHD_SCKT_ERR_IS_((err),MHD_SCKT_EWOULDBLOCK_) ) | 665 | MHD_SCKT_EAGAIN_) || \ |
666 | MHD_SCKT_ERR_IS_ ((err), \ | ||
667 | MHD_SCKT_EWOULDBLOCK_) ) | ||
646 | #endif /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ | 668 | #endif /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ |
647 | 669 | ||
648 | /** | 670 | /** |
@@ -650,10 +672,17 @@ | |||
650 | * @return boolean true if @a err is any kind of "low resource" error, | 672 | * @return boolean true if @a err is any kind of "low resource" error, |
651 | * boolean false otherwise. | 673 | * boolean false otherwise. |
652 | */ | 674 | */ |
653 | #define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_EMFILE_) || \ | 675 | #define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err) (MHD_SCKT_ERR_IS_ ((err), \ |
654 | MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENFILE_) || \ | 676 | MHD_SCKT_EMFILE_) \ |
655 | MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENOMEM_) || \ | 677 | || \ |
656 | MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENOBUFS_) ) | 678 | MHD_SCKT_ERR_IS_ ((err), \ |
679 | MHD_SCKT_ENFILE_) \ | ||
680 | || \ | ||
681 | MHD_SCKT_ERR_IS_ ((err), \ | ||
682 | MHD_SCKT_ENOMEM_) \ | ||
683 | || \ | ||
684 | MHD_SCKT_ERR_IS_ ((err), \ | ||
685 | MHD_SCKT_ENOBUFS_) ) | ||
657 | 686 | ||
658 | /** | 687 | /** |
659 | * Check whether is given socket error is type of "incoming connection | 688 | * Check whether is given socket error is type of "incoming connection |
@@ -662,9 +691,11 @@ | |||
662 | * boolean false otherwise. | 691 | * boolean false otherwise. |
663 | */ | 692 | */ |
664 | #if defined(MHD_POSIX_SOCKETS) | 693 | #if defined(MHD_POSIX_SOCKETS) |
665 | # define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNABORTED_) | 694 | # define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_ ((err), \ |
695 | MHD_SCKT_ECONNABORTED_) | ||
666 | #elif defined(MHD_WINSOCK_SOCKETS) | 696 | #elif defined(MHD_WINSOCK_SOCKETS) |
667 | # define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNRESET_) | 697 | # define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_ ((err), \ |
698 | MHD_SCKT_ECONNRESET_) | ||
668 | #endif | 699 | #endif |
669 | 700 | ||
670 | /** | 701 | /** |
@@ -673,8 +704,11 @@ | |||
673 | * @return boolean true is @a err match described socket error code, | 704 | * @return boolean true is @a err match described socket error code, |
674 | * boolean false otherwise. | 705 | * boolean false otherwise. |
675 | */ | 706 | */ |
676 | #define MHD_SCKT_ERR_IS_REMOTE_DISCNN_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNRESET_) || \ | 707 | #define MHD_SCKT_ERR_IS_REMOTE_DISCNN_(err) (MHD_SCKT_ERR_IS_ ((err), \ |
677 | MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNABORTED_)) | 708 | MHD_SCKT_ECONNRESET_) \ |
709 | || \ | ||
710 | MHD_SCKT_ERR_IS_ ((err), \ | ||
711 | MHD_SCKT_ECONNABORTED_)) | ||
678 | 712 | ||
679 | /* Specific error code set */ | 713 | /* Specific error code set */ |
680 | 714 | ||
@@ -683,12 +717,16 @@ | |||
683 | * available on platform. | 717 | * available on platform. |
684 | */ | 718 | */ |
685 | #if MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOMEM_ | 719 | #if MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOMEM_ |
686 | # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_) | 720 | # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \ |
721 | MHD_SCKT_ENOMEM_) | ||
687 | #elif MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOBUFS_ | 722 | #elif MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOBUFS_ |
688 | # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOBUFS_) | 723 | # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \ |
724 | MHD_SCKT_ENOBUFS_) | ||
689 | #else | 725 | #else |
690 | # warning No suitable replacement for ENOMEM error codes is found. Edit this file and add replacement code which is defined on system. | 726 | # warning \ |
691 | # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_) | 727 | No suitable replacement for ENOMEM error codes is found. Edit this file and add replacement code which is defined on system. |
728 | # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \ | ||
729 | MHD_SCKT_ENOMEM_) | ||
692 | #endif | 730 | #endif |
693 | 731 | ||
694 | /* Socket functions */ | 732 | /* Socket functions */ |
@@ -700,22 +738,26 @@ | |||
700 | #endif /* AF_UNIX */ | 738 | #endif /* AF_UNIX */ |
701 | 739 | ||
702 | #if defined(MHD_POSIX_SOCKETS) && defined(MHD_SCKT_LOCAL) | 740 | #if defined(MHD_POSIX_SOCKETS) && defined(MHD_SCKT_LOCAL) |
703 | # define MHD_socket_pair_(fdarr) (!socketpair(MHD_SCKT_LOCAL, SOCK_STREAM, 0, (fdarr))) | 741 | # define MHD_socket_pair_(fdarr) (! socketpair (MHD_SCKT_LOCAL, SOCK_STREAM, 0, \ |
742 | (fdarr))) | ||
704 | # if defined(HAVE_SOCK_NONBLOCK) | 743 | # if defined(HAVE_SOCK_NONBLOCK) |
705 | # define MHD_socket_pair_nblk_(fdarr) (!socketpair(MHD_SCKT_LOCAL, SOCK_STREAM | SOCK_NONBLOCK, 0, (fdarr))) | 744 | # define MHD_socket_pair_nblk_(fdarr) (! socketpair (MHD_SCKT_LOCAL, \ |
745 | SOCK_STREAM \ | ||
746 | | SOCK_NONBLOCK, 0, \ | ||
747 | (fdarr))) | ||
706 | # endif /* HAVE_SOCK_NONBLOCK*/ | 748 | # endif /* HAVE_SOCK_NONBLOCK*/ |
707 | #elif defined(MHD_WINSOCK_SOCKETS) | 749 | #elif defined(MHD_WINSOCK_SOCKETS) |
708 | /** | 750 | /** |
709 | * Create pair of mutually connected TCP/IP sockets on loopback address | 751 | * Create pair of mutually connected TCP/IP sockets on loopback address |
710 | * @param sockets_pair array to receive resulted sockets | 752 | * @param sockets_pair array to receive resulted sockets |
711 | * @param non_blk if set to non-zero value, sockets created in non-blocking mode | 753 | * @param non_blk if set to non-zero value, sockets created in non-blocking mode |
712 | * otherwise sockets will be in blocking mode | 754 | * otherwise sockets will be in blocking mode |
713 | * @return non-zero if succeeded, zero otherwise | 755 | * @return non-zero if succeeded, zero otherwise |
714 | */ | 756 | */ |
715 | int MHD_W32_socket_pair_(SOCKET sockets_pair[2], int non_blk); | 757 | int MHD_W32_socket_pair_ (SOCKET sockets_pair[2], int non_blk); |
716 | 758 | ||
717 | # define MHD_socket_pair_(fdarr) MHD_W32_socket_pair_((fdarr), 0) | 759 | # define MHD_socket_pair_(fdarr) MHD_W32_socket_pair_ ((fdarr), 0) |
718 | # define MHD_socket_pair_nblk_(fdarr) MHD_W32_socket_pair_((fdarr), 1) | 760 | # define MHD_socket_pair_nblk_(fdarr) MHD_W32_socket_pair_ ((fdarr), 1) |
719 | #endif | 761 | #endif |
720 | 762 | ||
721 | /** | 763 | /** |
@@ -804,7 +846,7 @@ MHD_socket_buffering_reset_ (MHD_socket sock); | |||
804 | 846 | ||
805 | 847 | ||
806 | #if defined(SOL_SOCKET) && defined(SO_NOSIGPIPE) | 848 | #if defined(SOL_SOCKET) && defined(SO_NOSIGPIPE) |
807 | static const int _MHD_socket_int_one = 1; | 849 | static const int _MHD_socket_int_one = 1; |
808 | /** | 850 | /** |
809 | * Change socket options to no signal on remote disconnect. | 851 | * Change socket options to no signal on remote disconnect. |
810 | * | 852 | * |
@@ -812,7 +854,8 @@ MHD_socket_buffering_reset_ (MHD_socket sock); | |||
812 | * @return non-zero if succeeded, zero otherwise | 854 | * @return non-zero if succeeded, zero otherwise |
813 | */ | 855 | */ |
814 | # define MHD_socket_nosignal_(sock) \ | 856 | # define MHD_socket_nosignal_(sock) \ |
815 | (!setsockopt((sock),SOL_SOCKET,SO_NOSIGPIPE,&_MHD_socket_int_one,sizeof(_MHD_socket_int_one))) | 857 | (! setsockopt ((sock),SOL_SOCKET,SO_NOSIGPIPE,&_MHD_socket_int_one, \ |
858 | sizeof(_MHD_socket_int_one))) | ||
816 | #endif /* SOL_SOCKET && SO_NOSIGPIPE */ | 859 | #endif /* SOL_SOCKET && SO_NOSIGPIPE */ |
817 | 860 | ||
818 | /** | 861 | /** |