libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 6e4a434cfc0d5eac721b0adafbdda3829d68102b
parent 50a6102ff3d2d437c256d179c72c3e9fb16040f3
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sat, 21 Nov 2015 19:43:06 +0000

Add and use _MHD_SOCKOPT_BOOL_TYPE for simplify usage of setsockopt() on W32/POSIX sockets.

Diffstat:
Msrc/include/platform.h | 9+++++++++
Msrc/microhttpd/connection.c | 4++--
Msrc/microhttpd/daemon.c | 14+++-----------
3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/include/platform.h b/src/include/platform.h @@ -189,6 +189,15 @@ typedef SOCKET MHD_socket; #define MHD_SOCKET_DEFINED 1 #endif /* MHD_SOCKET_DEFINED */ +/** + * _MHD_SOCKOPT_BOOL_TYPE is type for bool parameters for setsockopt()/getsockopt() + */ +#ifdef MHD_POSIX_SOCKETS +typedef int _MHD_SOCKOPT_BOOL_TYPE; +#else /* MHD_WINSOCK_SOCKETS */ +typedef BOOL _MHD_SOCKOPT_BOOL_TYPE; +#endif /* MHD_WINSOCK_SOCKETS */ + #ifndef _WIN32 typedef time_t _MHD_TIMEVAL_TV_SEC_TYPE; #else /* _WIN32 */ diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -2425,7 +2425,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) #if HAVE_DECL_TCP_CORK /* starting header send, set TCP cork */ { - const int val = 1; + const _MHD_SOCKOPT_BOOL_TYPE val = 1; setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, &val, sizeof (val)); } @@ -2509,7 +2509,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) #if HAVE_DECL_TCP_CORK /* done sending, uncork */ { - const int val = 0; + const _MHD_SOCKOPT_BOOL_TYPE = 0; setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, &val, sizeof (val)); } diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -3619,11 +3619,7 @@ MHD_start_daemon_va (unsigned int flags, MHD_AccessHandlerCallback dh, void *dh_cls, va_list ap) { -#if defined(MHD_POSIX_SOCKETS) - const int on = 1; -#elif defined(MHD_WINSOCK_SOCKETS) - const uint32_t on = 1; -#endif /* MHD_WINSOCK_SOCKETS */ + const _MHD_SOCKOPT_BOOL_TYPE on = 1; struct MHD_Daemon *daemon; MHD_socket socket_fd; struct sockaddr_in servaddr4; @@ -3995,12 +3991,8 @@ MHD_start_daemon_va (unsigned int flags, (http://msdn.microsoft.com/en-us/library/ms738574%28v=VS.85%29.aspx); and may also be missing on older POSIX systems; good luck if you have any of those, your IPv6 socket may then also bind against IPv4 anyway... */ -#ifndef MHD_WINSOCK_SOCKETS - const int -#else - const uint32_t -#endif - v6_only = (MHD_USE_DUAL_STACK != (flags & MHD_USE_DUAL_STACK)); + const _MHD_SOCKOPT_BOOL_TYPE v6_only = + (MHD_USE_DUAL_STACK != (flags & MHD_USE_DUAL_STACK)); if (0 > setsockopt (socket_fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void*)&v6_only, sizeof (v6_only)))