GNU libmicrohttpd  0.9.29
mhd_sockets.h
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  Copyright (C) 2014-2016 Karlson2k (Evgeny Grin)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 */
20 
33 #ifndef MHD_SOCKETS_H
34 #define MHD_SOCKETS_H 1
35 #include "mhd_options.h"
36 
37 #include <errno.h>
38 
39 #if !defined(MHD_POSIX_SOCKETS) && !defined(MHD_WINSOCK_SOCKETS)
40 # if !defined(_WIN32) || defined(__CYGWIN__)
41 # define MHD_POSIX_SOCKETS 1
42 # else /* defined(_WIN32) && !defined(__CYGWIN__) */
43 # define MHD_WINSOCK_SOCKETS 1
44 # endif /* defined(_WIN32) && !defined(__CYGWIN__) */
45 #endif /* !MHD_POSIX_SOCKETS && !MHD_WINSOCK_SOCKETS */
46 
47 /*
48  * MHD require headers that define socket type, socket basic functions
49  * (socket(), accept(), listen(), bind(), send(), recv(), select()), socket
50  * parameters like SOCK_CLOEXEC, SOCK_NONBLOCK, additional socket functions
51  * (poll(), epoll(), accept4()), struct timeval and other types, required
52  * for socket function.
53  */
54 #if defined(MHD_POSIX_SOCKETS)
55 # ifdef HAVE_SYS_TYPES_H
56 # include <sys/types.h> /* required on old platforms */
57 # endif
58 # ifdef HAVE_SYS_SOCKET_H
59 # include <sys/socket.h>
60 # endif
61 # if defined(__VXWORKS__) || defined(__vxworks) || defined(OS_VXWORKS)
62 # ifdef HAVE_SOCKLIB_H
63 # include <sockLib.h>
64 # endif /* HAVE_SOCKLIB_H */
65 # ifdef HAVE_INETLIB_H
66 # include <inetLib.h>
67 # endif /* HAVE_INETLIB_H */
68 # include <strings.h> /* required for FD_SET (bzero() function) */
69 # endif /* __VXWORKS__ || __vxworks || OS_VXWORKS */
70 # ifdef HAVE_NETINET_IN_H
71 # include <netinet/in.h>
72 # endif /* HAVE_NETINET_IN_H */
73 # ifdef HAVE_ARPA_INET_H
74 # include <arpa/inet.h>
75 # endif
76 # ifdef HAVE_NET_IF_H
77 # include <net/if.h>
78 # endif
79 # ifdef HAVE_SYS_TIME_H
80 # include <sys/time.h>
81 # endif
82 # ifdef HAVE_TIME_H
83 # include <time.h>
84 # endif
85 # ifdef HAVE_NETDB_H
86 # include <netdb.h>
87 # endif
88 # ifdef HAVE_SYS_SELECT_H
89 # include <sys/select.h>
90 # endif
91 # ifdef EPOLL_SUPPORT
92 # include <sys/epoll.h>
93 # endif
94 # ifdef HAVE_NETINET_TCP_H
95  /* for TCP_FASTOPEN and TCP_CORK */
96 # include <netinet/tcp.h>
97 # endif
98 # ifdef HAVE_STRING_H
99 # include <string.h> /* for strerror() */
100 # endif
101 #elif defined(MHD_WINSOCK_SOCKETS)
102 # ifndef WIN32_LEAN_AND_MEAN
103 # define WIN32_LEAN_AND_MEAN 1
104 # endif /* !WIN32_LEAN_AND_MEAN */
105 # include <winsock2.h>
106 # include <ws2tcpip.h>
107 #endif /* MHD_WINSOCK_SOCKETS */
108 
109 #if defined(HAVE_POLL_H) && defined(HAVE_POLL)
110 # include <poll.h>
111 #endif
112 
113 #include <stddef.h>
114 #if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED)
115 # include <stdint.h>
116 # define _SSIZE_T_DEFINED
117  typedef intptr_t ssize_t;
118 #endif /* !_SSIZE_T_DEFINED */
119 
120 #include "mhd_limits.h"
121 
122 #ifdef _MHD_FD_SETSIZE_IS_DEFAULT
123 # define _MHD_SYS_DEFAULT_FD_SETSIZE FD_SETSIZE
124 #else /* ! _MHD_FD_SETSIZE_IS_DEFAULT */
125 # include "sysfdsetsize.h"
126 # define _MHD_SYS_DEFAULT_FD_SETSIZE get_system_fdsetsize_value()
127 #endif /* ! _MHD_FD_SETSIZE_IS_DEFAULT */
128 
129 #ifndef MHD_PANIC
130 # include <stdio.h>
131 # include <stdlib.h>
132 /* Simple implementation of MHD_PANIC, to be used outside lib */
133 # define MHD_PANIC(msg) do { fprintf (stderr, \
134  "Abnormal termination at %d line in file %s: %s\n", \
135  (int)__LINE__, __FILE__, msg); abort();} while(0)
136 #endif /* ! MHD_PANIC */
137 
138 #ifndef MHD_SOCKET_DEFINED
139 
142 # if defined(MHD_POSIX_SOCKETS)
143  typedef int MHD_socket;
144 # define MHD_INVALID_SOCKET (-1)
145 # elif defined(MHD_WINSOCK_SOCKETS)
146  typedef SOCKET MHD_socket;
147 # define MHD_INVALID_SOCKET (INVALID_SOCKET)
148 # endif /* MHD_WINSOCK_SOCKETS */
149 
150 # define MHD_SOCKET_DEFINED 1
151 #endif /* ! MHD_SOCKET_DEFINED */
152 
153 #ifdef SOCK_CLOEXEC
154 # define MAYBE_SOCK_CLOEXEC SOCK_CLOEXEC
155 #else /* ! SOCK_CLOEXEC */
156 # define MAYBE_SOCK_CLOEXEC 0
157 #endif /* ! SOCK_CLOEXEC */
158 
159 #ifdef HAVE_SOCK_NONBLOCK
160 # define MAYBE_SOCK_NONBLOCK SOCK_NONBLOCK
161 #else /* ! HAVE_SOCK_NONBLOCK */
162 # define MAYBE_SOCK_NONBLOCK 0
163 #endif /* ! HAVE_SOCK_NONBLOCK */
164 
165 #ifdef MSG_NOSIGNAL
166 # define MAYBE_MSG_NOSIGNAL MSG_NOSIGNAL
167 #else /* ! MSG_NOSIGNAL */
168 # define MAYBE_MSG_NOSIGNAL 0
169 #endif /* ! MSG_NOSIGNAL */
170 
171 #if !defined(SHUT_WR) && defined(SD_SEND)
172 # define SHUT_WR SD_SEND
173 #endif
174 #if !defined(SHUT_RD) && defined(SD_RECEIVE)
175 # define SHUT_RD SD_RECEIVE
176 #endif
177 #if !defined(SHUT_RDWR) && defined(SD_BOTH)
178 # define SHUT_RDWR SD_BOTH
179 #endif
180 
181 #if HAVE_ACCEPT4+0 != 0 && (defined(HAVE_SOCK_NONBLOCK) || defined(SOCK_CLOEXEC))
182 # define USE_ACCEPT4 1
183 #endif
184 
185 #if defined(HAVE_EPOLL_CREATE1) && defined(EPOLL_CLOEXEC)
186 # define USE_EPOLL_CREATE1 1
187 #endif /* HAVE_EPOLL_CREATE1 && EPOLL_CLOEXEC */
188 
189 #ifdef TCP_FASTOPEN
190 
193 #define MHD_TCP_FASTOPEN_QUEUE_SIZE_DEFAULT 10
194 #endif
195 
196 
200 #ifdef MHD_POSIX_SOCKETS
201  typedef int MHD_SCKT_OPT_BOOL_;
202 #else /* MHD_WINSOCK_SOCKETS */
203  typedef BOOL MHD_SCKT_OPT_BOOL_;
204 #endif /* MHD_WINSOCK_SOCKETS */
205 
210 #if !defined(MHD_WINSOCK_SOCKETS)
211  typedef size_t MHD_SCKT_SEND_SIZE_;
212 #else
213  typedef int MHD_SCKT_SEND_SIZE_;
214 #endif
215 
219 #if !defined(MHD_WINSOCK_SOCKETS)
220 # define MHD_SCKT_SEND_MAX_SIZE_ SSIZE_MAX
221 #else
222 # define MHD_SCKT_SEND_MAX_SIZE_ INT_MAX
223 #endif
224 
235 #if !defined(MHD_WINSOCK_SOCKETS)
236 # define MHD_socket_close_(fd) ((0 == close((fd))) || (EBADF != errno))
237 #else
238 # define MHD_socket_close_(fd) (0 == closesocket((fd)))
239 #endif
240 
246 #define MHD_socket_close_chk_(fd) do { \
247  if (!MHD_socket_close_(fd)) \
248  MHD_PANIC(_("Close socket failed.\n")); \
249  } while(0)
250 
251 
259 #define MHD_send_(s,b,l) \
260  ((ssize_t)send((s),(const void*)(b),((MHD_SCKT_SEND_SIZE_)l), MAYBE_MSG_NOSIGNAL))
261 
262 
270 #define MHD_recv_(s,b,l) \
271  ((ssize_t)recv((s),(void*)(b),((MHD_SCKT_SEND_SIZE_)l), 0))
272 
273 
283 #if defined(MHD_POSIX_SOCKETS)
284 # define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ((fd) < (setsize))
285 #elif defined(MHD_WINSOCK_SOCKETS)
286 # define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ( ((void*)(pset)==(void*)0) || \
287  (((fd_set*)(pset))->fd_count < (setsize)) || \
288  (FD_ISSET((fd),(pset))) )
289 #endif
290 
299 #define MHD_SCKT_FD_FITS_FDSET_(fd,pset) MHD_SCKT_FD_FITS_FDSET_SETSIZE_((fd),(pset),FD_SETSIZE)
300 
309 #if defined(MHD_POSIX_SOCKETS)
310 # define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) FD_SET((fd),(pset))
311 #elif defined(MHD_WINSOCK_SOCKETS)
312 # define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) \
313  do { \
314  u_int _i_ = 0; \
315  fd_set* const _s_ = (fd_set*)(pset); \
316  while((_i_ < _s_->fd_count) && ((fd) != _s_->fd_array[_i_])) {++_i_;} \
317  if ((_i_ == _s_->fd_count)) {_s_->fd_array[_s_->fd_count++] = (fd);} \
318  } while(0)
319 #endif
320 
321  /* MHD_SYS_select_ is wrapper macro for system select() function */
322 #if !defined(MHD_WINSOCK_SOCKETS)
323 # define MHD_SYS_select_(n,r,w,e,t) select((n),(r),(w),(e),(t))
324 #else
325 # define MHD_SYS_select_(n,r,w,e,t) \
326 ( ( (((void*)(r) == (void*)0) || ((fd_set*)(r))->fd_count == 0) && \
327  (((void*)(w) == (void*)0) || ((fd_set*)(w))->fd_count == 0) && \
328  (((void*)(e) == (void*)0) || ((fd_set*)(e))->fd_count == 0) ) ? \
329  ( ((void*)(t) == (void*)0) ? 0 : \
330  (Sleep(((struct timeval*)(t))->tv_sec * 1000 + \
331  ((struct timeval*)(t))->tv_usec / 1000), 0) ) : \
332  (select((int)0,(r),(w),(e),(t))) )
333 #endif
334 
335 #if defined(HAVE_POLL)
336 /* MHD_sys_poll_ is wrapper macro for system poll() function */
337 # if !defined(MHD_WINSOCK_SOCKETS)
338 # define MHD_sys_poll_ poll
339 # else /* MHD_WINSOCK_SOCKETS */
340 # define MHD_sys_poll_ WSAPoll
341 # endif /* MHD_WINSOCK_SOCKETS */
342 #endif /* HAVE_POLL */
343 
344 #define MHD_SCKT_MISSING_ERR_CODE_ 31450
345 
346 #if defined(MHD_POSIX_SOCKETS)
347 # if defined(EAGAIN)
348 # define MHD_SCKT_EAGAIN_ EAGAIN
349 # elif defined(EWOULDBLOCK)
350 # define MHD_SCKT_EAGAIN_ EWOULDBLOCK
351 # else /* !EAGAIN && !EWOULDBLOCK */
352 # define MHD_SCKT_EAGAIN_ MHD_SCKT_MISSING_ERR_CODE_
353 # endif /* !EAGAIN && !EWOULDBLOCK */
354 # if defined(EWOULDBLOCK)
355 # define MHD_SCKT_EWOULDBLOCK_ EWOULDBLOCK
356 # elif defined(EAGAIN)
357 # define MHD_SCKT_EWOULDBLOCK_ EAGAIN
358 # else /* !EWOULDBLOCK && !EAGAIN */
359 # define MHD_SCKT_EWOULDBLOCK_ MHD_SCKT_MISSING_ERR_CODE_
360 # endif /* !EWOULDBLOCK && !EAGAIN */
361 # ifdef EINTR
362 # define MHD_SCKT_EINTR_ EINTR
363 # else /* ! EINTR */
364 # define MHD_SCKT_EINTR_ MHD_SCKT_MISSING_ERR_CODE_
365 # endif /* ! EINTR */
366 # ifdef ECONNRESET
367 # define MHD_SCKT_ECONNRESET_ ECONNRESET
368 # else /* ! ECONNRESET */
369 # define MHD_SCKT_ECONNRESET_ MHD_SCKT_MISSING_ERR_CODE_
370 # endif /* ! ECONNRESET */
371 # ifdef ECONNABORTED
372 # define MHD_SCKT_ECONNABORTED_ ECONNABORTED
373 # else /* ! ECONNABORTED */
374 # define MHD_SCKT_ECONNABORTED_ MHD_SCKT_MISSING_ERR_CODE_
375 # endif /* ! ECONNABORTED */
376 # ifdef ENOTCONN
377 # define MHD_SCKT_ENOTCONN_ ENOTCONN
378 # else /* ! ENOTCONN */
379 # define MHD_SCKT_ENOTCONN_ MHD_SCKT_MISSING_ERR_CODE_
380 # endif /* ! ENOTCONN */
381 # ifdef EMFILE
382 # define MHD_SCKT_EMFILE_ EMFILE
383 # else /* ! EMFILE */
384 # define MHD_SCKT_EMFILE_ MHD_SCKT_MISSING_ERR_CODE_
385 # endif /* ! EMFILE */
386 # ifdef ENFILE
387 # define MHD_SCKT_ENFILE_ ENFILE
388 # else /* ! ENFILE */
389 # define MHD_SCKT_ENFILE_ MHD_SCKT_MISSING_ERR_CODE_
390 # endif /* ! ENFILE */
391 # ifdef ENOMEM
392 # define MHD_SCKT_ENOMEM_ ENOMEM
393 # else /* ! ENOMEM */
394 # define MHD_SCKT_ENOMEM_ MHD_SCKT_MISSING_ERR_CODE_
395 # endif /* ! ENOMEM */
396 # ifdef ENOBUFS
397 # define MHD_SCKT_ENOBUFS_ ENOBUFS
398 # else /* ! ENOBUFS */
399 # define MHD_SCKT_ENOBUFS_ MHD_SCKT_MISSING_ERR_CODE_
400 # endif /* ! ENOBUFS */
401 # ifdef EBADF
402 # define MHD_SCKT_EBADF_ EBADF
403 # else /* ! EBADF */
404 # define MHD_SCKT_EBADF_ MHD_SCKT_MISSING_ERR_CODE_
405 # endif /* ! EBADF */
406 # ifdef ENOTSOCK
407 # define MHD_SCKT_ENOTSOCK_ ENOTSOCK
408 # else /* ! ENOTSOCK */
409 # define MHD_SCKT_ENOTSOCK_ MHD_SCKT_MISSING_ERR_CODE_
410 # endif /* ! ENOTSOCK */
411 # ifdef EINVAL
412 # define MHD_SCKT_EINVAL_ EINVAL
413 # else /* ! EINVAL */
414 # define MHD_SCKT_EINVAL_ MHD_SCKT_MISSING_ERR_CODE_
415 # endif /* ! EINVAL */
416 # ifdef EFAULT
417 # define MHD_SCKT_EFAUL_ EFAULT
418 # else /* ! EFAULT */
419 # define MHD_SCKT_EFAUL_ MHD_SCKT_MISSING_ERR_CODE_
420 # endif /* ! EFAULT */
421 # ifdef ENOSYS
422 # define MHD_SCKT_ENOSYS_ ENOSYS
423 # else /* ! ENOSYS */
424 # define MHD_SCKT_ENOSYS_ MHD_SCKT_MISSING_ERR_CODE_
425 # endif /* ! ENOSYS */
426 # ifdef ENOTSUP
427 # define MHD_SCKT_ENOTSUP_ ENOTSUP
428 # else /* ! ENOTSUP */
429 # define MHD_SCKT_ENOTSUP_ MHD_SCKT_MISSING_ERR_CODE_
430 # endif /* ! ENOTSUP */
431 # ifdef EOPNOTSUPP
432 # define MHD_SCKT_EOPNOTSUPP_ EOPNOTSUPP
433 # else /* ! EOPNOTSUPP */
434 # define MHD_SCKT_EOPNOTSUPP_ MHD_SCKT_MISSING_ERR_CODE_
435 # endif /* ! EOPNOTSUPP */
436 # ifdef EACCES
437 # define MHD_SCKT_EACCESS_ EACCES
438 # else /* ! EACCES */
439 # define MHD_SCKT_EACCESS_ MHD_SCKT_MISSING_ERR_CODE_
440 # endif /* ! EACCES */
441 # ifdef ENETDOWN
442 # define MHD_SCKT_ENETDOWN_ ENETDOWN
443 # else /* ! ENETDOWN */
444 # define MHD_SCKT_ENETDOWN_ MHD_SCKT_MISSING_ERR_CODE_
445 # endif /* ! ENETDOWN */
446 #elif defined(MHD_WINSOCK_SOCKETS)
447 # define MHD_SCKT_EAGAIN_ WSAEWOULDBLOCK
448 # define MHD_SCKT_EWOULDBLOCK_ WSAEWOULDBLOCK
449 # define MHD_SCKT_EINTR_ WSAEINTR
450 # define MHD_SCKT_ECONNRESET_ WSAECONNRESET
451 # define MHD_SCKT_ECONNABORTED_ WSAECONNABORTED
452 # define MHD_SCKT_ENOTCONN_ WSAENOTCONN
453 # define MHD_SCKT_EMFILE_ WSAEMFILE
454 # define MHD_SCKT_ENFILE_ MHD_SCKT_MISSING_ERR_CODE_
455 # define MHD_SCKT_ENOMEM_ MHD_SCKT_MISSING_ERR_CODE_
456 # define MHD_SCKT_ENOBUFS_ WSAENOBUFS
457 # define MHD_SCKT_EBADF_ WSAEBADF
458 # define MHD_SCKT_ENOTSOCK_ WSAENOTSOCK
459 # define MHD_SCKT_EINVAL_ WSAEINVAL
460 # define MHD_SCKT_EFAUL_ WSAEFAULT
461 # define MHD_SCKT_ENOSYS_ MHD_SCKT_MISSING_ERR_CODE_
462 # define MHD_SCKT_ENOTSUP_ MHD_SCKT_MISSING_ERR_CODE_
463 # define MHD_SCKT_EOPNOTSUPP_ WSAEOPNOTSUPP
464 # define MHD_SCKT_EACCESS_ WSAEACCES
465 # define MHD_SCKT_ENETDOWN_ WSAENETDOWN
466 #endif
467 
472 #if defined(MHD_POSIX_SOCKETS)
473 # define MHD_socket_get_error_() (errno)
474 #elif defined(MHD_WINSOCK_SOCKETS)
475 # define MHD_socket_get_error_() WSAGetLastError()
476 #endif
477 
478 #ifdef MHD_WINSOCK_SOCKETS
479  /* POSIX-W32 sockets compatibility functions */
480 
486  const char* MHD_W32_strerror_winsock_(int err);
487 #endif /* MHD_WINSOCK_SOCKETS */
488 
489 /* MHD_socket_last_strerr_ is description string of specified socket error code */
490 #if defined(MHD_POSIX_SOCKETS)
491 # define MHD_socket_strerr_(err) strerror((err))
492 #elif defined(MHD_WINSOCK_SOCKETS)
493 # define MHD_socket_strerr_(err) MHD_W32_strerror_winsock_((err))
494 #endif
495 
496 /* MHD_socket_last_strerr_ is description string of last errno (non-W32) /
497  * description string of last socket error (W32) */
498 #define MHD_socket_last_strerr_() MHD_socket_strerr_(MHD_socket_get_error_())
499 
503 #if defined(MHD_POSIX_SOCKETS)
504 # define MHD_socket_fset_error_(err) (errno = (err))
505 #elif defined(MHD_WINSOCK_SOCKETS)
506 # define MHD_socket_fset_error_(err) (WSASetLastError((err)))
507 #endif
508 
517 #define MHD_socket_try_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ != (err)) ? \
518  (MHD_socket_fset_error_((err)), !0) : 0 )
519 
525 #if defined(MHD_POSIX_SOCKETS)
526 # if defined(ENOSYS)
527 # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
528  (errno = ENOSYS) : (errno = (err)) )
529 # elif defined(EOPNOTSUPP)
530 # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
531  (errno = EOPNOTSUPP) : (errno = (err)) )
532 # elif defined (EFAULT)
533 # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
534  (errno = EFAULT) : (errno = (err)) )
535 # elif defined (EINVAL)
536 # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
537  (errno = EINVAL) : (errno = (err)) )
538 # else /* !EOPNOTSUPP && !EFAULT && !EINVAL */
539 # warning No suitable replacement for missing socket error code is found. Edit this file and add replacement code which is defined on system.
540 # define MHD_socket_set_error_(err) (errno = (err))
541 # endif /* !EOPNOTSUPP && !EFAULT && !EINVAL*/
542 #elif defined(MHD_WINSOCK_SOCKETS)
543 # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
544  (WSASetLastError((WSAEOPNOTSUPP))) : \
545  (WSASetLastError((err))) )
546 #endif
547 
557 #define MHD_SCKT_ERR_IS_(err,code) ( (MHD_SCKT_MISSING_ERR_CODE_ != (code)) && \
558  ((code) == (err)) )
559 
569 #define MHD_SCKT_LAST_ERR_IS_(code) MHD_SCKT_ERR_IS_(MHD_socket_get_error_() ,(code))
570 
571 /* Specific error code checks */
572 
579 #define MHD_SCKT_ERR_IS_EINTR_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_EINTR_)
580 
587 #if MHD_SCKT_EAGAIN_ == MHD_SCKT_EWOULDBLOCK_
588 # define MHD_SCKT_ERR_IS_EAGAIN_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_EAGAIN_)
589 #else /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */
590 # define MHD_SCKT_ERR_IS_EAGAIN_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_EAGAIN_) || \
591  MHD_SCKT_ERR_IS_((err),MHD_SCKT_EWOULDBLOCK_) )
592 #endif /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */
593 
599 #define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_EMFILE_) || \
600  MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENFILE_) || \
601  MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENOMEM_) || \
602  MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENOBUFS_) )
603 
610 #if defined(MHD_POSIX_SOCKETS)
611 # define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNABORTED_)
612 #elif defined(MHD_WINSOCK_SOCKETS)
613 # define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNRESET_)
614 #endif
615 
622 #define MHD_SCKT_ERR_IS_REMOTE_DISCNN_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNRESET_) || \
623  MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNABORTED_))
624 
625 /* Specific error code set */
626 
631 #if MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOMEM_
632 # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_)
633 #elif MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOBUFS_
634 # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOBUFS_)
635 #else
636 # warning No suitable replacement for ENOMEM error codes is found. Edit this file and add replacement code which is defined on system.
637 # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_)
638 #endif
639 
640 /* Socket functions */
641 
642 #if defined(MHD_POSIX_SOCKETS) && defined(AF_LOCAL)
643 # define MHD_socket_pair_(fdarr) (!socketpair(AF_LOCAL, SOCK_STREAM, 0, (fdarr)))
644 # if defined(HAVE_SOCK_NONBLOCK)
645 # define MHD_socket_pair_nblk_(fdarr) (!socketpair(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK, 0, (fdarr)))
646 # endif /* HAVE_SOCK_NONBLOCK*/
647 #elif defined(MHD_POSIX_SOCKETS) && defined(AF_UNIX)
648 # define MHD_socket_pair_(fdarr) (!socketpair(AF_UNIX, SOCK_STREAM, 0, (fdarr)))
649 # if defined(HAVE_SOCK_NONBLOCK)
650 # define MHD_socket_pair_nblk_(fdarr) (!socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, (fdarr)))
651 # endif /* HAVE_SOCK_NONBLOCK*/
652 #elif defined(MHD_WINSOCK_SOCKETS)
653 
660  int MHD_W32_socket_pair_(SOCKET sockets_pair[2], int non_blk);
661 
662 # define MHD_socket_pair_(fdarr) MHD_W32_socket_pair_((fdarr), 0)
663 # define MHD_socket_pair_nblk_(fdarr) MHD_W32_socket_pair_((fdarr), 1)
664 #endif
665 
676 int
678  fd_set *set,
679  MHD_socket *max_fd,
680  unsigned int fd_setsize);
681 
682 
689 int
691 
692 
700 int
702 
703 
711 MHD_socket_create_listen_ (int use_ipv6);
712 
713 #endif /* ! MHD_SOCKETS_H */
additional automatic macros for MHD_config.h
MHD_socket MHD_socket_create_listen_(int use_ipv6)
Definition: mhd_sockets.c:471
int MHD_socket
Definition: microhttpd.h:181
int MHD_socket_noninheritable_(MHD_socket sock)
Definition: mhd_sockets.c:439
Helper for obtaining FD_SETSIZE system default value.
int fd
Definition: microhttpd.h:2218
int MHD_SCKT_OPT_BOOL_
Definition: mhd_sockets.h:201
int MHD_socket
Definition: mhd_sockets.h:143
size_t MHD_SCKT_SEND_SIZE_
Definition: mhd_sockets.h:211
limits values definitions
int MHD_add_to_fd_set_(MHD_socket fd, fd_set *set, MHD_socket *max_fd, unsigned int fd_setsize)
Definition: mhd_sockets.c:374
int MHD_socket_nonblocking_(MHD_socket sock)
Definition: mhd_sockets.c:404