commit fa6909d5e18a70a8aa01da488634c3d1b643141d
parent 554018347f6bf94c9643e6d7edc3f5d0f0ad1d9e
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Mon, 17 Oct 2016 16:57:22 +0300
Simplify portability by using MHD_send_() wrapper macro
Diffstat:
4 files changed, 53 insertions(+), 31 deletions(-)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
@@ -269,10 +269,9 @@ socket_start_no_buffering_flush (struct MHD_Connection *connection)
/* Force flush data with zero send otherwise Darwin and some BSD systems
will add 5 seconds delay. Not required with TCP_CORK as switching off
TCP_CORK always flushes socket buffer. */
- res &= (0 <= send (connection->socket_fd,
- (const void *) &dummy,
- 0,
- 0))
+ res &= (0 <= MHD_send_ (connection->socket_fd,
+ &dummy,
+ 0))
? MHD_YES : MHD_NO;
#endif /* TCP_NOPUSH && !TCP_CORK*/
return res;
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
@@ -86,12 +86,6 @@
*/
#define DEBUG_CONNECT MHD_NO
-#ifndef LINUX
-#ifndef MSG_NOSIGNAL
-#define MSG_NOSIGNAL 0
-#endif
-#endif
-
/**
* Default implementation of the panic function,
@@ -1038,11 +1032,11 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->mhd.celi)) &&
(urh->in_buffer_off > 0) )
{
- size_t res;
+ ssize_t res;
- res = write (urh->mhd.socket,
- urh->in_buffer,
- urh->in_buffer_off);
+ res = MHD_send_ (urh->mhd.socket,
+ urh->in_buffer,
+ urh->in_buffer_off);
if (-1 == res)
{
int err = MHD_socket_get_error_ ();
@@ -1645,19 +1639,13 @@ send_param_adapter (struct MHD_Connection *connection,
MHD_socket_set_error_ (MHD_SCKT_ENOTCONN_);
return -1;
}
-#ifdef MHD_POSIX_SOCKETS
- if (i > SSIZE_MAX)
- i = SSIZE_MAX; /* return value limit */
-#else /* MHD_WINSOCK_SOCKETS */
- if (i > INT_MAX)
- i = INT_MAX; /* return value limit */
-#endif /* MHD_WINSOCK_SOCKETS */
+ if (i > MHD_SCKT_SEND_MAX_SIZE_)
+ i = MHD_SCKT_SEND_MAX_SIZE_; /* return value limit */
if (0 != (connection->daemon->options & MHD_USE_TLS))
- return (ssize_t) send (connection->socket_fd,
- other,
- (MHD_SCKT_SEND_SIZE_) i,
- MSG_NOSIGNAL);
+ return MHD_send_ (connection->socket_fd,
+ other,
+ i);
#if LINUX
if ( (connection->write_buffer_append_offset ==
connection->write_buffer_send_offset) &&
@@ -1716,10 +1704,9 @@ send_param_adapter (struct MHD_Connection *connection,
http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */
}
#endif
- ret = (ssize_t) send (connection->socket_fd,
- other,
- (MHD_SCKT_SEND_SIZE_) i,
- MSG_NOSIGNAL);
+ ret = MHD_send_ (connection->socket_fd,
+ other,
+ i);
err = MHD_socket_get_error_();
#ifdef EPOLL_SUPPORT
if ( (0 > ret) &&
diff --git a/src/microhttpd/mhd_itc.h b/src/microhttpd/mhd_itc.h
@@ -274,8 +274,8 @@ static const uint64_t _MHD_itc_wr_data = 1;
* @param str one-symbol string, useful only for strace debug
* @return non-zero if succeeded, zero otherwise
*/
-#define MHD_itc_activate_(itc, str) \
- ((send((itc).sk[1], (const char*)(str), 1, 0) > 0) || \
+#define MHD_itc_activate_(itc, str) \
+ ((MHD_send_((itc).sk[1], (str), 1) > 0) || \
(MHD_SCKT_ERR_IS_EAGAIN_(MHD_socket_get_error_())))
/**
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h
@@ -110,6 +110,15 @@
# include <poll.h>
#endif
+#include <stddef.h>
+#if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED)
+# include <stdint.h>
+# define _SSIZE_T_DEFINED
+ typedef intptr_t ssize_t;
+#endif /* !_SSIZE_T_DEFINED */
+
+#include "mhd_limits.h"
+
#ifdef _MHD_FD_SETSIZE_IS_DEFAULT
# define _MHD_SYS_DEFAULT_FD_SETSIZE FD_SETSIZE
#else /* ! _MHD_FD_SETSIZE_IS_DEFAULT */
@@ -153,6 +162,12 @@
# define MAYBE_SOCK_NONBLOCK 0
#endif /* ! HAVE_SOCK_NONBLOCK */
+#ifdef MSG_NOSIGNAL
+# define MAYBE_MSG_NOSIGNAL MSG_NOSIGNAL
+#else /* ! MSG_NOSIGNAL */
+# define MAYBE_MSG_NOSIGNAL 0
+#endif /* ! MSG_NOSIGNAL */
+
#if !defined(SHUT_WR) && defined(SD_SEND)
# define SHUT_WR SD_SEND
#endif
@@ -199,6 +214,15 @@
#endif
/**
+ * MHD_SCKT_SEND_MAX_SIZE_ is maximum send()/recv() size value.
+ */
+#if !defined(MHD_WINSOCK_SOCKETS)
+# define MHD_SCKT_SEND_MAX_SIZE_ SSIZE_MAX
+#else
+# define MHD_SCKT_SEND_MAX_SIZE_ INT_MAX
+#endif
+
+/**
* MHD_socket_close_(fd) close any FDs (non-W32) / close only socket
* FDs (W32). Note that on HP-UNIX, this function may leak the FD if
* errno is set to EINTR. Do not use HP-UNIX.
@@ -224,6 +248,18 @@
MHD_PANIC(_("Close socket failed.\n")); \
} while(0)
+
+/**
+ * MHD_send_ is wrapper for system's send()
+ * @param s the socket to use
+ * @param b the buffer with data to send
+ * @param l the length of data in @a b
+ * @return ssize_t type value
+ */
+#define MHD_send_(s,b,l) \
+ ((ssize_t)send((s),(const void*)(b),((MHD_SCKT_SEND_SIZE_)l), MAYBE_MSG_NOSIGNAL))
+
+
/**
* Check whether FD can be added to fd_set with specified FD_SETSIZE.
* @param fd the fd to check