aboutsummaryrefslogtreecommitdiff
path: root/src/lib/mhd_sockets.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/mhd_sockets.h')
-rw-r--r--src/lib/mhd_sockets.h239
1 files changed, 141 insertions, 98 deletions
diff --git a/src/lib/mhd_sockets.h b/src/lib/mhd_sockets.h
index 9be34144..ebe40275 100644
--- a/src/lib/mhd_sockets.h
+++ b/src/lib/mhd_sockets.h
@@ -36,8 +36,8 @@
36 36
37#include <errno.h> 37#include <errno.h>
38 38
39#if !defined(MHD_POSIX_SOCKETS) && !defined(MHD_WINSOCK_SOCKETS) 39#if ! defined(MHD_POSIX_SOCKETS) && ! defined(MHD_WINSOCK_SOCKETS)
40# if !defined(_WIN32) || defined(__CYGWIN__) 40# if ! defined(_WIN32) || defined(__CYGWIN__)
41# define MHD_POSIX_SOCKETS 1 41# define MHD_POSIX_SOCKETS 1
42# else /* defined(_WIN32) && !defined(__CYGWIN__) */ 42# else /* defined(_WIN32) && !defined(__CYGWIN__) */
43# define MHD_WINSOCK_SOCKETS 1 43# define MHD_WINSOCK_SOCKETS 1
@@ -92,7 +92,7 @@
92# include <sys/epoll.h> 92# include <sys/epoll.h>
93# endif 93# endif
94# ifdef HAVE_NETINET_TCP_H 94# ifdef HAVE_NETINET_TCP_H
95 /* for TCP_FASTOPEN and TCP_CORK */ 95/* for TCP_FASTOPEN and TCP_CORK */
96# include <netinet/tcp.h> 96# include <netinet/tcp.h>
97# endif 97# endif
98# ifdef HAVE_STRING_H 98# ifdef HAVE_STRING_H
@@ -111,10 +111,10 @@
111#endif 111#endif
112 112
113#include <stddef.h> 113#include <stddef.h>
114#if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED) 114#if defined(_MSC_FULL_VER) && ! defined (_SSIZE_T_DEFINED)
115# include <stdint.h> 115# include <stdint.h>
116# define _SSIZE_T_DEFINED 116# define _SSIZE_T_DEFINED
117 typedef intptr_t ssize_t; 117typedef intptr_t ssize_t;
118#endif /* !_SSIZE_T_DEFINED */ 118#endif /* !_SSIZE_T_DEFINED */
119 119
120#include "mhd_limits.h" 120#include "mhd_limits.h"
@@ -123,7 +123,7 @@
123# define _MHD_SYS_DEFAULT_FD_SETSIZE FD_SETSIZE 123# define _MHD_SYS_DEFAULT_FD_SETSIZE FD_SETSIZE
124#else /* ! _MHD_FD_SETSIZE_IS_DEFAULT */ 124#else /* ! _MHD_FD_SETSIZE_IS_DEFAULT */
125# include "sysfdsetsize.h" 125# include "sysfdsetsize.h"
126# define _MHD_SYS_DEFAULT_FD_SETSIZE get_system_fdsetsize_value() 126# define _MHD_SYS_DEFAULT_FD_SETSIZE get_system_fdsetsize_value ()
127#endif /* ! _MHD_FD_SETSIZE_IS_DEFAULT */ 127#endif /* ! _MHD_FD_SETSIZE_IS_DEFAULT */
128 128
129#ifndef MHD_PANIC 129#ifndef MHD_PANIC
@@ -131,8 +131,9 @@
131# include <stdlib.h> 131# include <stdlib.h>
132/* Simple implementation of MHD_PANIC, to be used outside lib */ 132/* Simple implementation of MHD_PANIC, to be used outside lib */
133# define MHD_PANIC(msg) do { fprintf (stderr, \ 133# define MHD_PANIC(msg) do { fprintf (stderr, \
134 "Abnormal termination at %d line in file %s: %s\n", \ 134 "Abnormal termination at %d line in file %s: %s\n", \
135 (int)__LINE__, __FILE__, msg); abort();} while(0) 135 (int) __LINE__, __FILE__, msg); abort (); \
136} while (0)
136#endif /* ! MHD_PANIC */ 137#endif /* ! MHD_PANIC */
137 138
138#ifndef MHD_SOCKET_DEFINED 139#ifndef MHD_SOCKET_DEFINED
@@ -140,10 +141,10 @@
140 * MHD_socket is type for socket FDs 141 * MHD_socket is type for socket FDs
141 */ 142 */
142# if defined(MHD_POSIX_SOCKETS) 143# if defined(MHD_POSIX_SOCKETS)
143 typedef int MHD_socket; 144typedef int MHD_socket;
144# define MHD_INVALID_SOCKET (-1) 145# define MHD_INVALID_SOCKET (-1)
145# elif defined(MHD_WINSOCK_SOCKETS) 146# elif defined(MHD_WINSOCK_SOCKETS)
146 typedef SOCKET MHD_socket; 147typedef SOCKET MHD_socket;
147# define MHD_INVALID_SOCKET (INVALID_SOCKET) 148# define MHD_INVALID_SOCKET (INVALID_SOCKET)
148# endif /* MHD_WINSOCK_SOCKETS */ 149# endif /* MHD_WINSOCK_SOCKETS */
149 150
@@ -168,17 +169,18 @@
168# define MAYBE_MSG_NOSIGNAL 0 169# define MAYBE_MSG_NOSIGNAL 0
169#endif /* ! MSG_NOSIGNAL */ 170#endif /* ! MSG_NOSIGNAL */
170 171
171#if !defined(SHUT_WR) && defined(SD_SEND) 172#if ! defined(SHUT_WR) && defined(SD_SEND)
172# define SHUT_WR SD_SEND 173# define SHUT_WR SD_SEND
173#endif 174#endif
174#if !defined(SHUT_RD) && defined(SD_RECEIVE) 175#if ! defined(SHUT_RD) && defined(SD_RECEIVE)
175# define SHUT_RD SD_RECEIVE 176# define SHUT_RD SD_RECEIVE
176#endif 177#endif
177#if !defined(SHUT_RDWR) && defined(SD_BOTH) 178#if ! defined(SHUT_RDWR) && defined(SD_BOTH)
178# define SHUT_RDWR SD_BOTH 179# define SHUT_RDWR SD_BOTH
179#endif 180#endif
180 181
181#if HAVE_ACCEPT4+0 != 0 && (defined(HAVE_SOCK_NONBLOCK) || defined(SOCK_CLOEXEC)) 182#if HAVE_ACCEPT4 + 0 != 0 && (defined(HAVE_SOCK_NONBLOCK) || \
183 defined(SOCK_CLOEXEC))
182# define USE_ACCEPT4 1 184# define USE_ACCEPT4 1
183#endif 185#endif
184 186
@@ -198,25 +200,25 @@
198 * MHD_SCKT_OPT_BOOL_ is type for bool parameters for setsockopt()/getsockopt() 200 * MHD_SCKT_OPT_BOOL_ is type for bool parameters for setsockopt()/getsockopt()
199 */ 201 */
200#ifdef MHD_POSIX_SOCKETS 202#ifdef MHD_POSIX_SOCKETS
201 typedef int MHD_SCKT_OPT_BOOL_; 203typedef int MHD_SCKT_OPT_BOOL_;
202#else /* MHD_WINSOCK_SOCKETS */ 204#else /* MHD_WINSOCK_SOCKETS */
203 typedef BOOL MHD_SCKT_OPT_BOOL_; 205typedef BOOL MHD_SCKT_OPT_BOOL_;
204#endif /* MHD_WINSOCK_SOCKETS */ 206#endif /* MHD_WINSOCK_SOCKETS */
205 207
206/** 208/**
207 * MHD_SCKT_SEND_SIZE_ is type used to specify size for send and recv 209 * MHD_SCKT_SEND_SIZE_ is type used to specify size for send and recv
208 * functions 210 * functions
209 */ 211 */
210#if !defined(MHD_WINSOCK_SOCKETS) 212#if ! defined(MHD_WINSOCK_SOCKETS)
211 typedef size_t MHD_SCKT_SEND_SIZE_; 213typedef size_t MHD_SCKT_SEND_SIZE_;
212#else 214#else
213 typedef int MHD_SCKT_SEND_SIZE_; 215typedef int MHD_SCKT_SEND_SIZE_;
214#endif 216#endif
215 217
216/** 218/**
217 * MHD_SCKT_SEND_MAX_SIZE_ is maximum send()/recv() size value. 219 * MHD_SCKT_SEND_MAX_SIZE_ is maximum send()/recv() size value.
218 */ 220 */
219#if !defined(MHD_WINSOCK_SOCKETS) 221#if ! defined(MHD_WINSOCK_SOCKETS)
220# define MHD_SCKT_SEND_MAX_SIZE_ SSIZE_MAX 222# define MHD_SCKT_SEND_MAX_SIZE_ SSIZE_MAX
221#else 223#else
222# define MHD_SCKT_SEND_MAX_SIZE_ INT_MAX 224# define MHD_SCKT_SEND_MAX_SIZE_ INT_MAX
@@ -232,10 +234,10 @@
232 * counted as success, only EBADF counts as an error!), 234 * counted as success, only EBADF counts as an error!),
233 * boolean false otherwise. 235 * boolean false otherwise.
234 */ 236 */
235#if !defined(MHD_WINSOCK_SOCKETS) 237#if ! defined(MHD_WINSOCK_SOCKETS)
236# define MHD_socket_close_(fd) ((0 == close((fd))) || (EBADF != errno)) 238# define MHD_socket_close_(fd) ((0 == close ((fd))) || (EBADF != errno))
237#else 239#else
238# define MHD_socket_close_(fd) (0 == closesocket((fd))) 240# define MHD_socket_close_(fd) (0 == closesocket ((fd)))
239#endif 241#endif
240 242
241/** 243/**
@@ -244,9 +246,9 @@
244 * @param fd socket to close 246 * @param fd socket to close
245 */ 247 */
246#define MHD_socket_close_chk_(fd) do { \ 248#define MHD_socket_close_chk_(fd) do { \
247 if (!MHD_socket_close_(fd)) \ 249 if (! MHD_socket_close_ (fd)) \
248 MHD_PANIC(_("Close socket failed.\n")); \ 250 MHD_PANIC (_ ("Close socket failed.\n")); \
249 } while(0) 251} while (0)
250 252
251 253
252/** 254/**
@@ -257,7 +259,8 @@
257 * @return ssize_t type value 259 * @return ssize_t type value
258 */ 260 */
259#define MHD_send_(s,b,l) \ 261#define MHD_send_(s,b,l) \
260 ((ssize_t)send((s),(const void*)(b),((MHD_SCKT_SEND_SIZE_)l), MAYBE_MSG_NOSIGNAL)) 262 ((ssize_t) send ((s),(const void*) (b),((MHD_SCKT_SEND_SIZE_) l), \
263 MAYBE_MSG_NOSIGNAL))
261 264
262 265
263/** 266/**
@@ -268,7 +271,7 @@
268 * @return ssize_t type value 271 * @return ssize_t type value
269 */ 272 */
270#define MHD_recv_(s,b,l) \ 273#define MHD_recv_(s,b,l) \
271 ((ssize_t)recv((s),(void*)(b),((MHD_SCKT_SEND_SIZE_)l), 0)) 274 ((ssize_t) recv ((s),(void*) (b),((MHD_SCKT_SEND_SIZE_) l), 0))
272 275
273 276
274/** 277/**
@@ -281,11 +284,18 @@
281 * boolean false otherwise. 284 * boolean false otherwise.
282 */ 285 */
283#if defined(MHD_POSIX_SOCKETS) 286#if defined(MHD_POSIX_SOCKETS)
284# define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ((fd) < ((MHD_socket)setsize)) 287# define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ((fd) < \
288 ((MHD_socket) \
289 setsize))
285#elif defined(MHD_WINSOCK_SOCKETS) 290#elif defined(MHD_WINSOCK_SOCKETS)
286# define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ( ((void*)(pset)==(void*)0) || \ 291# define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ( ((void*) (pset)== \
287 (((fd_set*)(pset))->fd_count < ((unsigned)setsize)) || \ 292 (void*) 0) || \
288 (FD_ISSET((fd),(pset))) ) 293 (((fd_set*) (pset)) \
294 ->fd_count < \
295 ((unsigned) \
296 setsize)) || \
297 (FD_ISSET ((fd), \
298 (pset))) )
289#endif 299#endif
290 300
291/** 301/**
@@ -296,7 +306,9 @@
296 * @return boolean true if FD can be added to fd_set, 306 * @return boolean true if FD can be added to fd_set,
297 * boolean false otherwise. 307 * boolean false otherwise.
298 */ 308 */
299#define MHD_SCKT_FD_FITS_FDSET_(fd,pset) MHD_SCKT_FD_FITS_FDSET_SETSIZE_((fd),(pset),FD_SETSIZE) 309#define MHD_SCKT_FD_FITS_FDSET_(fd,pset) MHD_SCKT_FD_FITS_FDSET_SETSIZE_ ((fd), \
310 (pset), \
311 FD_SETSIZE)
300 312
301/** 313/**
302 * Add FD to fd_set with specified FD_SETSIZE. 314 * Add FD to fd_set with specified FD_SETSIZE.
@@ -307,34 +319,35 @@
307 * system definition of FD_SET() is not used. 319 * system definition of FD_SET() is not used.
308 */ 320 */
309#if defined(MHD_POSIX_SOCKETS) 321#if defined(MHD_POSIX_SOCKETS)
310# define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) FD_SET((fd),(pset)) 322# define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) FD_SET ((fd), \
323 (pset))
311#elif defined(MHD_WINSOCK_SOCKETS) 324#elif defined(MHD_WINSOCK_SOCKETS)
312# define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) \ 325# define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) \
313 do { \ 326 do { \
314 u_int _i_ = 0; \ 327 u_int _i_ = 0; \
315 fd_set* const _s_ = (fd_set*)(pset); \ 328 fd_set*const _s_ = (fd_set*) (pset); \
316 while((_i_ < _s_->fd_count) && ((fd) != _s_->fd_array[_i_])) {++_i_;} \ 329 while ((_i_ < _s_->fd_count) && ((fd) != _s_->fd_array [_i_])) {++_i_;} \
317 if ((_i_ == _s_->fd_count)) {_s_->fd_array[_s_->fd_count++] = (fd);} \ 330 if ((_i_ == _s_->fd_count)) {_s_->fd_array [_s_->fd_count ++] = (fd);} \
318 } while(0) 331 } while (0)
319#endif 332#endif
320 333
321 /* MHD_SYS_select_ is wrapper macro for system select() function */ 334/* MHD_SYS_select_ is wrapper macro for system select() function */
322#if !defined(MHD_WINSOCK_SOCKETS) 335#if ! defined(MHD_WINSOCK_SOCKETS)
323# define MHD_SYS_select_(n,r,w,e,t) select((n),(r),(w),(e),(t)) 336# define MHD_SYS_select_(n,r,w,e,t) select ((n),(r),(w),(e),(t))
324#else 337#else
325# define MHD_SYS_select_(n,r,w,e,t) \ 338# define MHD_SYS_select_(n,r,w,e,t) \
326( ( (((void*)(r) == (void*)0) || ((fd_set*)(r))->fd_count == 0) && \ 339 ( ( (((void*) (r) == (void*) 0) || ((fd_set*) (r))->fd_count == 0) && \
327 (((void*)(w) == (void*)0) || ((fd_set*)(w))->fd_count == 0) && \ 340 (((void*) (w) == (void*) 0) || ((fd_set*) (w))->fd_count == 0) && \
328 (((void*)(e) == (void*)0) || ((fd_set*)(e))->fd_count == 0) ) ? \ 341 (((void*) (e) == (void*) 0) || ((fd_set*) (e))->fd_count == 0) ) ? \
329 ( ((void*)(t) == (void*)0) ? 0 : \ 342 ( ((void*) (t) == (void*) 0) ? 0 : \
330 (Sleep(((struct timeval*)(t))->tv_sec * 1000 + \ 343 (Sleep (((struct timeval*) (t))->tv_sec * 1000 \
331 ((struct timeval*)(t))->tv_usec / 1000), 0) ) : \ 344 + ((struct timeval*) (t))->tv_usec / 1000), 0) ) : \
332 (select((int)0,(r),(w),(e),(t))) ) 345 (select ((int) 0,(r),(w),(e),(t))) )
333#endif 346#endif
334 347
335#if defined(HAVE_POLL) 348#if defined(HAVE_POLL)
336/* MHD_sys_poll_ is wrapper macro for system poll() function */ 349/* MHD_sys_poll_ is wrapper macro for system poll() function */
337# if !defined(MHD_WINSOCK_SOCKETS) 350# if ! defined(MHD_WINSOCK_SOCKETS)
338# define MHD_sys_poll_ poll 351# define MHD_sys_poll_ poll
339# else /* MHD_WINSOCK_SOCKETS */ 352# else /* MHD_WINSOCK_SOCKETS */
340# define MHD_sys_poll_ WSAPoll 353# define MHD_sys_poll_ WSAPoll
@@ -363,16 +376,19 @@
363# elif defined(__linux__) 376# elif defined(__linux__)
364# define MHD_POLL_EVENTS_ERR_DISC POLLPRI 377# define MHD_POLL_EVENTS_ERR_DISC POLLPRI
365# else /* ! __linux__ */ 378# else /* ! __linux__ */
366# define MHD_POLL_EVENTS_ERR_DISC (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO) 379# define MHD_POLL_EVENTS_ERR_DISC (MHD_POLLPRI_OR_ZERO \
380 | MHD_POLLRDBAND_OR_ZERO)
367# endif /* ! __linux__ */ 381# endif /* ! __linux__ */
368/* MHD_POLL_REVENTS_ERR_DISC is 'revents' mask for errors and disconnect. 382/* MHD_POLL_REVENTS_ERR_DISC is 'revents' mask for errors and disconnect.
369 * Note: Out-of-band data is treated as error. */ 383 * Note: Out-of-band data is treated as error. */
370# define MHD_POLL_REVENTS_ERR_DISC \ 384# define MHD_POLL_REVENTS_ERR_DISC \
371 (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO | POLLERR | POLLHUP) 385 (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO \
386 | POLLERR | POLLHUP)
372/* MHD_POLL_REVENTS_ERRROR is 'revents' mask for errors. 387/* MHD_POLL_REVENTS_ERRROR is 'revents' mask for errors.
373 * Note: Out-of-band data is treated as error. */ 388 * Note: Out-of-band data is treated as error. */
374# define MHD_POLL_REVENTS_ERRROR \ 389# define MHD_POLL_REVENTS_ERRROR \
375 (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO | POLLERR) 390 (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO \
391 | POLLERR)
376#endif /* HAVE_POLL */ 392#endif /* HAVE_POLL */
377 393
378#define MHD_SCKT_MISSING_ERR_CODE_ 31450 394#define MHD_SCKT_MISSING_ERR_CODE_ 31450
@@ -506,30 +522,30 @@
506#if defined(MHD_POSIX_SOCKETS) 522#if defined(MHD_POSIX_SOCKETS)
507# define MHD_socket_get_error_() (errno) 523# define MHD_socket_get_error_() (errno)
508#elif defined(MHD_WINSOCK_SOCKETS) 524#elif defined(MHD_WINSOCK_SOCKETS)
509# define MHD_socket_get_error_() WSAGetLastError() 525# define MHD_socket_get_error_() WSAGetLastError ()
510#endif 526#endif
511 527
512#ifdef MHD_WINSOCK_SOCKETS 528#ifdef MHD_WINSOCK_SOCKETS
513 /* POSIX-W32 sockets compatibility functions */ 529/* POSIX-W32 sockets compatibility functions */
514 530
515/** 531/**
516 * Return pointer to string description of specified WinSock error 532 * Return pointer to string description of specified WinSock error
517 * @param err the WinSock error code. 533 * @param err the WinSock error code.
518 * @return pointer to string description of specified WinSock error. 534 * @return pointer to string description of specified WinSock error.
519 */ 535 */
520 const char* MHD_W32_strerror_winsock_(int err); 536const char*MHD_W32_strerror_winsock_ (int err);
521#endif /* MHD_WINSOCK_SOCKETS */ 537#endif /* MHD_WINSOCK_SOCKETS */
522 538
523/* MHD_socket_last_strerr_ is description string of specified socket error code */ 539/* MHD_socket_last_strerr_ is description string of specified socket error code */
524#if defined(MHD_POSIX_SOCKETS) 540#if defined(MHD_POSIX_SOCKETS)
525# define MHD_socket_strerr_(err) strerror((err)) 541# define MHD_socket_strerr_(err) strerror ((err))
526#elif defined(MHD_WINSOCK_SOCKETS) 542#elif defined(MHD_WINSOCK_SOCKETS)
527# define MHD_socket_strerr_(err) MHD_W32_strerror_winsock_((err)) 543# define MHD_socket_strerr_(err) MHD_W32_strerror_winsock_ ((err))
528#endif 544#endif
529 545
530/* MHD_socket_last_strerr_ is description string of last errno (non-W32) / 546/* MHD_socket_last_strerr_ is description string of last errno (non-W32) /
531 * description string of last socket error (W32) */ 547 * description string of last socket error (W32) */
532#define MHD_socket_last_strerr_() MHD_socket_strerr_(MHD_socket_get_error_()) 548#define MHD_socket_last_strerr_() MHD_socket_strerr_ (MHD_socket_get_error_ ())
533 549
534/** 550/**
535 * MHD_socket_fset_error_() set socket system native error code. 551 * MHD_socket_fset_error_() set socket system native error code.
@@ -537,7 +553,7 @@
537#if defined(MHD_POSIX_SOCKETS) 553#if defined(MHD_POSIX_SOCKETS)
538# define MHD_socket_fset_error_(err) (errno = (err)) 554# define MHD_socket_fset_error_(err) (errno = (err))
539#elif defined(MHD_WINSOCK_SOCKETS) 555#elif defined(MHD_WINSOCK_SOCKETS)
540# define MHD_socket_fset_error_(err) (WSASetLastError((err))) 556# define MHD_socket_fset_error_(err) (WSASetLastError ((err)))
541#endif 557#endif
542 558
543/** 559/**
@@ -549,7 +565,8 @@
549 * and error was not set. 565 * and error was not set.
550 */ 566 */
551#define MHD_socket_try_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ != (err)) ? \ 567#define MHD_socket_try_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ != (err)) ? \
552 (MHD_socket_fset_error_((err)), !0) : 0 ) 568 (MHD_socket_fset_error_ ((err)), ! 0) : \
569 0)
553 570
554/** 571/**
555 * MHD_socket_set_error_() set socket system native error code to 572 * MHD_socket_set_error_() set socket system native error code to
@@ -562,7 +579,8 @@
562 (errno = ENOSYS) : (errno = (err)) ) 579 (errno = ENOSYS) : (errno = (err)) )
563# elif defined(EOPNOTSUPP) 580# elif defined(EOPNOTSUPP)
564# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ 581# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
565 (errno = EOPNOTSUPP) : (errno = (err)) ) 582 (errno = EOPNOTSUPP) : (errno = \
583 (err)) )
566# elif defined (EFAULT) 584# elif defined (EFAULT)
567# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ 585# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
568 (errno = EFAULT) : (errno = (err)) ) 586 (errno = EFAULT) : (errno = (err)) )
@@ -570,13 +588,14 @@
570# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ 588# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
571 (errno = EINVAL) : (errno = (err)) ) 589 (errno = EINVAL) : (errno = (err)) )
572# else /* !EOPNOTSUPP && !EFAULT && !EINVAL */ 590# else /* !EOPNOTSUPP && !EFAULT && !EINVAL */
573# warning No suitable replacement for missing socket error code is found. Edit this file and add replacement code which is defined on system. 591# warning \
592 No suitable replacement for missing socket error code is found. Edit this file and add replacement code which is defined on system.
574# define MHD_socket_set_error_(err) (errno = (err)) 593# define MHD_socket_set_error_(err) (errno = (err))
575# endif /* !EOPNOTSUPP && !EFAULT && !EINVAL*/ 594# endif /* !EOPNOTSUPP && !EFAULT && !EINVAL*/
576#elif defined(MHD_WINSOCK_SOCKETS) 595#elif defined(MHD_WINSOCK_SOCKETS)
577# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ 596# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
578 (WSASetLastError((WSAEOPNOTSUPP))) : \ 597 (WSASetLastError ((WSAEOPNOTSUPP))) : \
579 (WSASetLastError((err))) ) 598 (WSASetLastError ((err))) )
580#endif 599#endif
581 600
582/** 601/**
@@ -600,7 +619,8 @@
600 * last socket error equals to MHD_SCKT_E*_ @a code; 619 * last socket error equals to MHD_SCKT_E*_ @a code;
601 * boolean false otherwise 620 * boolean false otherwise
602 */ 621 */
603#define MHD_SCKT_LAST_ERR_IS_(code) MHD_SCKT_ERR_IS_(MHD_socket_get_error_() ,(code)) 622#define MHD_SCKT_LAST_ERR_IS_(code) MHD_SCKT_ERR_IS_ (MHD_socket_get_error_ (), \
623 (code))
604 624
605/* Specific error code checks */ 625/* Specific error code checks */
606 626
@@ -610,7 +630,7 @@
610 * @return boolean true if @a err is equal to sockets' EINTR code; 630 * @return boolean true if @a err is equal to sockets' EINTR code;
611 * boolean false otherwise. 631 * boolean false otherwise.
612 */ 632 */
613#define MHD_SCKT_ERR_IS_EINTR_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_EINTR_) 633#define MHD_SCKT_ERR_IS_EINTR_(err) MHD_SCKT_ERR_IS_ ((err),MHD_SCKT_EINTR_)
614 634
615/** 635/**
616 * Check whether given socket error is equal to system's 636 * Check whether given socket error is equal to system's
@@ -619,10 +639,12 @@
619 * boolean false otherwise. 639 * boolean false otherwise.
620 */ 640 */
621#if MHD_SCKT_EAGAIN_ == MHD_SCKT_EWOULDBLOCK_ 641#if MHD_SCKT_EAGAIN_ == MHD_SCKT_EWOULDBLOCK_
622# define MHD_SCKT_ERR_IS_EAGAIN_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_EAGAIN_) 642# define MHD_SCKT_ERR_IS_EAGAIN_(err) MHD_SCKT_ERR_IS_ ((err),MHD_SCKT_EAGAIN_)
623#else /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ 643#else /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */
624# define MHD_SCKT_ERR_IS_EAGAIN_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_EAGAIN_) || \ 644# define MHD_SCKT_ERR_IS_EAGAIN_(err) (MHD_SCKT_ERR_IS_ ((err), \
625 MHD_SCKT_ERR_IS_((err),MHD_SCKT_EWOULDBLOCK_) ) 645 MHD_SCKT_EAGAIN_) || \
646 MHD_SCKT_ERR_IS_ ((err), \
647 MHD_SCKT_EWOULDBLOCK_) )
626#endif /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ 648#endif /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */
627 649
628/** 650/**
@@ -630,10 +652,17 @@
630 * @return boolean true if @a err is any kind of "low resource" error, 652 * @return boolean true if @a err is any kind of "low resource" error,
631 * boolean false otherwise. 653 * boolean false otherwise.
632 */ 654 */
633#define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_EMFILE_) || \ 655#define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err) (MHD_SCKT_ERR_IS_ ((err), \
634 MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENFILE_) || \ 656 MHD_SCKT_EMFILE_) \
635 MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENOMEM_) || \ 657 || \
636 MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENOBUFS_) ) 658 MHD_SCKT_ERR_IS_ ((err), \
659 MHD_SCKT_ENFILE_) \
660 || \
661 MHD_SCKT_ERR_IS_ ((err), \
662 MHD_SCKT_ENOMEM_) \
663 || \
664 MHD_SCKT_ERR_IS_ ((err), \
665 MHD_SCKT_ENOBUFS_) )
637 666
638/** 667/**
639 * Check whether is given socket error is type of "incoming connection 668 * Check whether is given socket error is type of "incoming connection
@@ -642,9 +671,11 @@
642 * boolean false otherwise. 671 * boolean false otherwise.
643 */ 672 */
644#if defined(MHD_POSIX_SOCKETS) 673#if defined(MHD_POSIX_SOCKETS)
645# define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNABORTED_) 674# define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_ ((err), \
675 MHD_SCKT_ECONNABORTED_)
646#elif defined(MHD_WINSOCK_SOCKETS) 676#elif defined(MHD_WINSOCK_SOCKETS)
647# define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNRESET_) 677# define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_ ((err), \
678 MHD_SCKT_ECONNRESET_)
648#endif 679#endif
649 680
650/** 681/**
@@ -653,8 +684,11 @@
653 * @return boolean true is @a err match described socket error code, 684 * @return boolean true is @a err match described socket error code,
654 * boolean false otherwise. 685 * boolean false otherwise.
655 */ 686 */
656#define MHD_SCKT_ERR_IS_REMOTE_DISCNN_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNRESET_) || \ 687#define MHD_SCKT_ERR_IS_REMOTE_DISCNN_(err) (MHD_SCKT_ERR_IS_ ((err), \
657 MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNABORTED_)) 688 MHD_SCKT_ECONNRESET_) \
689 || \
690 MHD_SCKT_ERR_IS_ ((err), \
691 MHD_SCKT_ECONNABORTED_))
658 692
659/* Specific error code set */ 693/* Specific error code set */
660 694
@@ -663,12 +697,16 @@
663 * available on platform. 697 * available on platform.
664 */ 698 */
665#if MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOMEM_ 699#if MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOMEM_
666# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_) 700# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \
701 MHD_SCKT_ENOMEM_)
667#elif MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOBUFS_ 702#elif MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOBUFS_
668# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOBUFS_) 703# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \
704 MHD_SCKT_ENOBUFS_)
669#else 705#else
670# warning No suitable replacement for ENOMEM error codes is found. Edit this file and add replacement code which is defined on system. 706# warning \
671# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_) 707 No suitable replacement for ENOMEM error codes is found. Edit this file and add replacement code which is defined on system.
708# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \
709 MHD_SCKT_ENOMEM_)
672#endif 710#endif
673 711
674/* Socket functions */ 712/* Socket functions */
@@ -680,22 +718,26 @@
680#endif /* AF_UNIX */ 718#endif /* AF_UNIX */
681 719
682#if defined(MHD_POSIX_SOCKETS) && defined(MHD_SCKT_LOCAL) 720#if defined(MHD_POSIX_SOCKETS) && defined(MHD_SCKT_LOCAL)
683# define MHD_socket_pair_(fdarr) (!socketpair(MHD_SCKT_LOCAL, SOCK_STREAM, 0, (fdarr))) 721# define MHD_socket_pair_(fdarr) (! socketpair (MHD_SCKT_LOCAL, SOCK_STREAM, 0, \
722 (fdarr)))
684# if defined(HAVE_SOCK_NONBLOCK) 723# if defined(HAVE_SOCK_NONBLOCK)
685# define MHD_socket_pair_nblk_(fdarr) (!socketpair(MHD_SCKT_LOCAL, SOCK_STREAM | SOCK_NONBLOCK, 0, (fdarr))) 724# define MHD_socket_pair_nblk_(fdarr) (! socketpair (MHD_SCKT_LOCAL, \
725 SOCK_STREAM \
726 | SOCK_NONBLOCK, 0, \
727 (fdarr)))
686# endif /* HAVE_SOCK_NONBLOCK*/ 728# endif /* HAVE_SOCK_NONBLOCK*/
687#elif defined(MHD_WINSOCK_SOCKETS) 729#elif defined(MHD_WINSOCK_SOCKETS)
688 /** 730/**
689 * Create pair of mutually connected TCP/IP sockets on loopback address 731 * Create pair of mutually connected TCP/IP sockets on loopback address
690 * @param sockets_pair array to receive resulted sockets 732 * @param sockets_pair array to receive resulted sockets
691 * @param non_blk if set to non-zero value, sockets created in non-blocking mode 733 * @param non_blk if set to non-zero value, sockets created in non-blocking mode
692 * otherwise sockets will be in blocking mode 734 * otherwise sockets will be in blocking mode
693 * @return non-zero if succeeded, zero otherwise 735 * @return non-zero if succeeded, zero otherwise
694 */ 736 */
695 int MHD_W32_socket_pair_(SOCKET sockets_pair[2], int non_blk); 737int MHD_W32_socket_pair_ (SOCKET sockets_pair[2], int non_blk);
696 738
697# define MHD_socket_pair_(fdarr) MHD_W32_socket_pair_((fdarr), 0) 739# define MHD_socket_pair_(fdarr) MHD_W32_socket_pair_ ((fdarr), 0)
698# define MHD_socket_pair_nblk_(fdarr) MHD_W32_socket_pair_((fdarr), 1) 740# define MHD_socket_pair_nblk_(fdarr) MHD_W32_socket_pair_ ((fdarr), 1)
699#endif 741#endif
700 742
701/** 743/**
@@ -737,7 +779,7 @@ MHD_socket_noninheritable_ (MHD_socket sock);
737 779
738 780
739#if defined(SOL_SOCKET) && defined(SO_NOSIGPIPE) 781#if defined(SOL_SOCKET) && defined(SO_NOSIGPIPE)
740 static const int _MHD_socket_int_one = 1; 782static const int _MHD_socket_int_one = 1;
741/** 783/**
742 * Change socket options to no signal on remote disconnect. 784 * Change socket options to no signal on remote disconnect.
743 * 785 *
@@ -745,7 +787,8 @@ MHD_socket_noninheritable_ (MHD_socket sock);
745 * @return non-zero if succeeded, zero otherwise 787 * @return non-zero if succeeded, zero otherwise
746 */ 788 */
747# define MHD_socket_nosignal_(sock) \ 789# define MHD_socket_nosignal_(sock) \
748 (!setsockopt((sock),SOL_SOCKET,SO_NOSIGPIPE,&_MHD_socket_int_one,sizeof(_MHD_socket_int_one))) 790 (! setsockopt ((sock),SOL_SOCKET,SO_NOSIGPIPE,&_MHD_socket_int_one, \
791 sizeof(_MHD_socket_int_one)))
749#endif /* SOL_SOCKET && SO_NOSIGPIPE */ 792#endif /* SOL_SOCKET && SO_NOSIGPIPE */
750 793
751/** 794/**