diff options
Diffstat (limited to 'src/microhttpd/mhd_sockets.h')
-rw-r--r-- | src/microhttpd/mhd_sockets.h | 122 |
1 files changed, 53 insertions, 69 deletions
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h index a53037ec..d46f10a9 100644 --- a/src/microhttpd/mhd_sockets.h +++ b/src/microhttpd/mhd_sockets.h | |||
@@ -141,9 +141,10 @@ typedef intptr_t ssize_t; | |||
141 | # include <stdio.h> | 141 | # include <stdio.h> |
142 | # include <stdlib.h> | 142 | # include <stdlib.h> |
143 | /* Simple implementation of MHD_PANIC, to be used outside lib */ | 143 | /* Simple implementation of MHD_PANIC, to be used outside lib */ |
144 | # define MHD_PANIC(msg) do { fprintf (stderr, \ | 144 | # define MHD_PANIC(msg) \ |
145 | "Abnormal termination at %d line in file %s: %s\n", \ | 145 | do { fprintf (stderr, \ |
146 | (int) __LINE__, __FILE__, msg); abort (); \ | 146 | "Abnormal termination at %d line in file %s: %s\n", \ |
147 | (int) __LINE__, __FILE__, msg); abort (); \ | ||
147 | } while (0) | 148 | } while (0) |
148 | #endif /* ! MHD_PANIC */ | 149 | #endif /* ! MHD_PANIC */ |
149 | 150 | ||
@@ -386,18 +387,13 @@ typedef int MHD_SCKT_SEND_SIZE_; | |||
386 | * boolean false otherwise. | 387 | * boolean false otherwise. |
387 | */ | 388 | */ |
388 | #if defined(MHD_POSIX_SOCKETS) | 389 | #if defined(MHD_POSIX_SOCKETS) |
389 | # define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ((fd) < \ | 390 | # define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) \ |
390 | ((MHD_socket) \ | 391 | ((fd) < ((MHD_socket) setsize)) |
391 | setsize)) | ||
392 | #elif defined(MHD_WINSOCK_SOCKETS) | 392 | #elif defined(MHD_WINSOCK_SOCKETS) |
393 | # define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ( ((void*) (pset)== \ | 393 | # define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) \ |
394 | (void*) 0) || \ | 394 | ( ((void*) (pset)== (void*) 0) || \ |
395 | (((fd_set*) (pset)) \ | 395 | (((fd_set*) (pset))->fd_count < ((unsigned) setsize)) || \ |
396 | ->fd_count < \ | 396 | (FD_ISSET ((fd), (pset))) ) |
397 | ((unsigned) \ | ||
398 | setsize)) || \ | ||
399 | (FD_ISSET ((fd), \ | ||
400 | (pset))) ) | ||
401 | #endif | 397 | #endif |
402 | 398 | ||
403 | /** | 399 | /** |
@@ -408,9 +404,8 @@ typedef int MHD_SCKT_SEND_SIZE_; | |||
408 | * @return boolean true if FD can be added to fd_set, | 404 | * @return boolean true if FD can be added to fd_set, |
409 | * boolean false otherwise. | 405 | * boolean false otherwise. |
410 | */ | 406 | */ |
411 | #define MHD_SCKT_FD_FITS_FDSET_(fd,pset) MHD_SCKT_FD_FITS_FDSET_SETSIZE_ ((fd), \ | 407 | #define MHD_SCKT_FD_FITS_FDSET_(fd,pset) \ |
412 | (pset), \ | 408 | MHD_SCKT_FD_FITS_FDSET_SETSIZE_ ((fd), (pset), FD_SETSIZE) |
413 | FD_SETSIZE) | ||
414 | 409 | ||
415 | /** | 410 | /** |
416 | * Add FD to fd_set with specified FD_SETSIZE. | 411 | * Add FD to fd_set with specified FD_SETSIZE. |
@@ -421,13 +416,13 @@ typedef int MHD_SCKT_SEND_SIZE_; | |||
421 | * system definition of FD_SET() is not used. | 416 | * system definition of FD_SET() is not used. |
422 | */ | 417 | */ |
423 | #if defined(MHD_POSIX_SOCKETS) | 418 | #if defined(MHD_POSIX_SOCKETS) |
424 | # define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) FD_SET ((fd), \ | 419 | # define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) \ |
425 | (pset)) | 420 | FD_SET ((fd), (pset)) |
426 | #elif defined(MHD_WINSOCK_SOCKETS) | 421 | #elif defined(MHD_WINSOCK_SOCKETS) |
427 | # define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) \ | 422 | # define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) \ |
428 | do { \ | 423 | do { \ |
429 | u_int _i_ = 0; \ | 424 | u_int _i_ = 0; \ |
430 | fd_set*const _s_ = (fd_set*) (pset); \ | 425 | fd_set*const _s_ = (fd_set*) (pset); \ |
431 | while ((_i_ < _s_->fd_count) && ((fd) != _s_->fd_array [_i_])) {++_i_;} \ | 426 | while ((_i_ < _s_->fd_count) && ((fd) != _s_->fd_array [_i_])) {++_i_;} \ |
432 | if ((_i_ == _s_->fd_count)) {_s_->fd_array [_s_->fd_count ++] = (fd);} \ | 427 | if ((_i_ == _s_->fd_count)) {_s_->fd_array [_s_->fd_count ++] = (fd);} \ |
433 | } while (0) | 428 | } while (0) |
@@ -441,9 +436,9 @@ typedef int MHD_SCKT_SEND_SIZE_; | |||
441 | ( ( (((void*) (r) == (void*) 0) || ((fd_set*) (r))->fd_count == 0) && \ | 436 | ( ( (((void*) (r) == (void*) 0) || ((fd_set*) (r))->fd_count == 0) && \ |
442 | (((void*) (w) == (void*) 0) || ((fd_set*) (w))->fd_count == 0) && \ | 437 | (((void*) (w) == (void*) 0) || ((fd_set*) (w))->fd_count == 0) && \ |
443 | (((void*) (e) == (void*) 0) || ((fd_set*) (e))->fd_count == 0) ) ? \ | 438 | (((void*) (e) == (void*) 0) || ((fd_set*) (e))->fd_count == 0) ) ? \ |
444 | ( ((void*) (t) == (void*) 0) ? 0 : \ | 439 | ( ((void*) (t) == (void*) 0) ? 0 : \ |
445 | (Sleep (((struct timeval*) (t))->tv_sec * 1000 \ | 440 | (Sleep (((struct timeval*) (t))->tv_sec * 1000 \ |
446 | + ((struct timeval*) (t))->tv_usec / 1000), 0) ) : \ | 441 | + ((struct timeval*) (t))->tv_usec / 1000), 0) ) : \ |
447 | (select ((int) 0,(r),(w),(e),(t))) ) | 442 | (select ((int) 0,(r),(w),(e),(t))) ) |
448 | #endif | 443 | #endif |
449 | 444 | ||
@@ -478,8 +473,8 @@ typedef int MHD_SCKT_SEND_SIZE_; | |||
478 | # elif defined(__linux__) | 473 | # elif defined(__linux__) |
479 | # define MHD_POLL_EVENTS_ERR_DISC POLLPRI | 474 | # define MHD_POLL_EVENTS_ERR_DISC POLLPRI |
480 | # else /* ! __linux__ */ | 475 | # else /* ! __linux__ */ |
481 | # define MHD_POLL_EVENTS_ERR_DISC (MHD_POLLPRI_OR_ZERO \ | 476 | # define MHD_POLL_EVENTS_ERR_DISC \ |
482 | | MHD_POLLRDBAND_OR_ZERO) | 477 | (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO) |
483 | # endif /* ! __linux__ */ | 478 | # endif /* ! __linux__ */ |
484 | /* MHD_POLL_REVENTS_ERR_DISC is 'revents' mask for errors and disconnect. | 479 | /* MHD_POLL_REVENTS_ERR_DISC is 'revents' mask for errors and disconnect. |
485 | * Note: Out-of-band data is treated as error. */ | 480 | * Note: Out-of-band data is treated as error. */ |
@@ -697,9 +692,9 @@ const char *MHD_W32_strerror_winsock_ (int err); | |||
697 | * zero if specified @a err code is not defined on system | 692 | * zero if specified @a err code is not defined on system |
698 | * and error was not set. | 693 | * and error was not set. |
699 | */ | 694 | */ |
700 | #define MHD_socket_try_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ != (err)) ? \ | 695 | #define MHD_socket_try_set_error_(err) \ |
701 | (MHD_socket_fset_error_ ((err)), ! 0) : \ | 696 | ( (MHD_SCKT_MISSING_ERR_CODE_ != (err)) ? \ |
702 | 0) | 697 | (MHD_socket_fset_error_ ((err)), ! 0) : 0) |
703 | 698 | ||
704 | /** | 699 | /** |
705 | * MHD_socket_set_error_() set socket system native error code to | 700 | * MHD_socket_set_error_() set socket system native error code to |
@@ -740,8 +735,8 @@ const char *MHD_W32_strerror_winsock_ (int err); | |||
740 | * @a err equals to MHD_SCKT_E*_ @a code; | 735 | * @a err equals to MHD_SCKT_E*_ @a code; |
741 | * boolean false otherwise | 736 | * boolean false otherwise |
742 | */ | 737 | */ |
743 | #define MHD_SCKT_ERR_IS_(err,code) ( (MHD_SCKT_MISSING_ERR_CODE_ != (code)) && \ | 738 | #define MHD_SCKT_ERR_IS_(err,code) \ |
744 | ((code) == (err)) ) | 739 | ( (MHD_SCKT_MISSING_ERR_CODE_ != (code)) && ((code) == (err)) ) |
745 | 740 | ||
746 | /** | 741 | /** |
747 | * Check whether last socket error is equal to specified system | 742 | * Check whether last socket error is equal to specified system |
@@ -752,8 +747,8 @@ const char *MHD_W32_strerror_winsock_ (int err); | |||
752 | * last socket error equals to MHD_SCKT_E*_ @a code; | 747 | * last socket error equals to MHD_SCKT_E*_ @a code; |
753 | * boolean false otherwise | 748 | * boolean false otherwise |
754 | */ | 749 | */ |
755 | #define MHD_SCKT_LAST_ERR_IS_(code) MHD_SCKT_ERR_IS_ (MHD_socket_get_error_ (), \ | 750 | #define MHD_SCKT_LAST_ERR_IS_(code) \ |
756 | (code)) | 751 | MHD_SCKT_ERR_IS_ (MHD_socket_get_error_ (), (code)) |
757 | 752 | ||
758 | /* Specific error code checks */ | 753 | /* Specific error code checks */ |
759 | 754 | ||
@@ -774,10 +769,9 @@ const char *MHD_W32_strerror_winsock_ (int err); | |||
774 | #if MHD_SCKT_EAGAIN_ == MHD_SCKT_EWOULDBLOCK_ | 769 | #if MHD_SCKT_EAGAIN_ == MHD_SCKT_EWOULDBLOCK_ |
775 | # define MHD_SCKT_ERR_IS_EAGAIN_(err) MHD_SCKT_ERR_IS_ ((err),MHD_SCKT_EAGAIN_) | 770 | # define MHD_SCKT_ERR_IS_EAGAIN_(err) MHD_SCKT_ERR_IS_ ((err),MHD_SCKT_EAGAIN_) |
776 | #else /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ | 771 | #else /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ |
777 | # define MHD_SCKT_ERR_IS_EAGAIN_(err) (MHD_SCKT_ERR_IS_ ((err), \ | 772 | # define MHD_SCKT_ERR_IS_EAGAIN_(err) \ |
778 | MHD_SCKT_EAGAIN_) || \ | 773 | ( MHD_SCKT_ERR_IS_ ((err), MHD_SCKT_EAGAIN_) || \ |
779 | MHD_SCKT_ERR_IS_ ((err), \ | 774 | MHD_SCKT_ERR_IS_ ((err), MHD_SCKT_EWOULDBLOCK_) ) |
780 | MHD_SCKT_EWOULDBLOCK_) ) | ||
781 | #endif /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ | 775 | #endif /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ |
782 | 776 | ||
783 | /** | 777 | /** |
@@ -785,17 +779,11 @@ const char *MHD_W32_strerror_winsock_ (int err); | |||
785 | * @return boolean true if @a err is any kind of "low resource" error, | 779 | * @return boolean true if @a err is any kind of "low resource" error, |
786 | * boolean false otherwise. | 780 | * boolean false otherwise. |
787 | */ | 781 | */ |
788 | #define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err) (MHD_SCKT_ERR_IS_ ((err), \ | 782 | #define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err) \ |
789 | MHD_SCKT_EMFILE_) \ | 783 | ( MHD_SCKT_ERR_IS_ ((err), MHD_SCKT_EMFILE_) || \ |
790 | || \ | 784 | MHD_SCKT_ERR_IS_ ((err), MHD_SCKT_ENFILE_) || \ |
791 | MHD_SCKT_ERR_IS_ ((err), \ | 785 | MHD_SCKT_ERR_IS_ ((err), MHD_SCKT_ENOMEM_) || \ |
792 | MHD_SCKT_ENFILE_) \ | 786 | MHD_SCKT_ERR_IS_ ((err), MHD_SCKT_ENOBUFS_) ) |
793 | || \ | ||
794 | MHD_SCKT_ERR_IS_ ((err), \ | ||
795 | MHD_SCKT_ENOMEM_) \ | ||
796 | || \ | ||
797 | MHD_SCKT_ERR_IS_ ((err), \ | ||
798 | MHD_SCKT_ENOBUFS_) ) | ||
799 | 787 | ||
800 | /** | 788 | /** |
801 | * Check whether is given socket error is type of "incoming connection | 789 | * Check whether is given socket error is type of "incoming connection |
@@ -804,11 +792,11 @@ const char *MHD_W32_strerror_winsock_ (int err); | |||
804 | * boolean false otherwise. | 792 | * boolean false otherwise. |
805 | */ | 793 | */ |
806 | #if defined(MHD_POSIX_SOCKETS) | 794 | #if defined(MHD_POSIX_SOCKETS) |
807 | # define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_ ((err), \ | 795 | # define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) \ |
808 | MHD_SCKT_ECONNABORTED_) | 796 | MHD_SCKT_ERR_IS_ ((err), MHD_SCKT_ECONNABORTED_) |
809 | #elif defined(MHD_WINSOCK_SOCKETS) | 797 | #elif defined(MHD_WINSOCK_SOCKETS) |
810 | # define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_ ((err), \ | 798 | # define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) \ |
811 | MHD_SCKT_ECONNRESET_) | 799 | MHD_SCKT_ERR_IS_ ((err), MHD_SCKT_ECONNRESET_) |
812 | #endif | 800 | #endif |
813 | 801 | ||
814 | /** | 802 | /** |
@@ -817,11 +805,9 @@ const char *MHD_W32_strerror_winsock_ (int err); | |||
817 | * @return boolean true is @a err match described socket error code, | 805 | * @return boolean true is @a err match described socket error code, |
818 | * boolean false otherwise. | 806 | * boolean false otherwise. |
819 | */ | 807 | */ |
820 | #define MHD_SCKT_ERR_IS_REMOTE_DISCNN_(err) (MHD_SCKT_ERR_IS_ ((err), \ | 808 | #define MHD_SCKT_ERR_IS_REMOTE_DISCNN_(err) \ |
821 | MHD_SCKT_ECONNRESET_) \ | 809 | ( MHD_SCKT_ERR_IS_ ((err), MHD_SCKT_ECONNRESET_) || \ |
822 | || \ | 810 | MHD_SCKT_ERR_IS_ ((err), MHD_SCKT_ECONNABORTED_) ) |
823 | MHD_SCKT_ERR_IS_ ((err), \ | ||
824 | MHD_SCKT_ECONNABORTED_)) | ||
825 | 811 | ||
826 | /* Specific error code set */ | 812 | /* Specific error code set */ |
827 | 813 | ||
@@ -830,11 +816,11 @@ const char *MHD_W32_strerror_winsock_ (int err); | |||
830 | * available on platform. | 816 | * available on platform. |
831 | */ | 817 | */ |
832 | #if MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOMEM_ | 818 | #if MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOMEM_ |
833 | # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \ | 819 | # define MHD_socket_set_error_to_ENOMEM() \ |
834 | MHD_SCKT_ENOMEM_) | 820 | MHD_socket_set_error_ (MHD_SCKT_ENOMEM_) |
835 | #elif MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOBUFS_ | 821 | #elif MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOBUFS_ |
836 | # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \ | 822 | # define MHD_socket_set_error_to_ENOMEM() \ |
837 | MHD_SCKT_ENOBUFS_) | 823 | MHD_socket_set_error_ (MHD_SCKT_ENOBUFS_) |
838 | #else | 824 | #else |
839 | # warning \ | 825 | # warning \ |
840 | No suitable replacement for ENOMEM error codes is found. Edit this file and add replacement code which is defined on system. | 826 | No suitable replacement for ENOMEM error codes is found. Edit this file and add replacement code which is defined on system. |
@@ -851,13 +837,11 @@ const char *MHD_W32_strerror_winsock_ (int err); | |||
851 | #endif /* AF_UNIX */ | 837 | #endif /* AF_UNIX */ |
852 | 838 | ||
853 | #if defined(MHD_POSIX_SOCKETS) && defined(MHD_SCKT_LOCAL) | 839 | #if defined(MHD_POSIX_SOCKETS) && defined(MHD_SCKT_LOCAL) |
854 | # define MHD_socket_pair_(fdarr) (! socketpair (MHD_SCKT_LOCAL, SOCK_STREAM, 0, \ | 840 | # define MHD_socket_pair_(fdarr) \ |
855 | (fdarr))) | 841 | (! socketpair (MHD_SCKT_LOCAL, SOCK_STREAM, 0, (fdarr))) |
856 | # if defined(HAVE_SOCK_NONBLOCK) | 842 | # if defined(HAVE_SOCK_NONBLOCK) |
857 | # define MHD_socket_pair_nblk_(fdarr) (! socketpair (MHD_SCKT_LOCAL, \ | 843 | # define MHD_socket_pair_nblk_(fdarr) \ |
858 | SOCK_STREAM \ | 844 | (! socketpair (MHD_SCKT_LOCAL, SOCK_STREAM | SOCK_NONBLOCK, 0, (fdarr))) |
859 | | SOCK_NONBLOCK, 0, \ | ||
860 | (fdarr))) | ||
861 | # endif /* HAVE_SOCK_NONBLOCK*/ | 845 | # endif /* HAVE_SOCK_NONBLOCK*/ |
862 | #elif defined(MHD_WINSOCK_SOCKETS) | 846 | #elif defined(MHD_WINSOCK_SOCKETS) |
863 | /** | 847 | /** |