[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r38105 - libmicrohttpd/src/microhttpd
From: |
gnunet |
Subject: |
[GNUnet-SVN] r38105 - libmicrohttpd/src/microhttpd |
Date: |
Tue, 11 Oct 2016 17:20:44 +0200 |
Author: Karlson2k
Date: 2016-10-11 17:20:44 +0200 (Tue, 11 Oct 2016)
New Revision: 38105
Modified:
libmicrohttpd/src/microhttpd/mhd_sockets.c
libmicrohttpd/src/microhttpd/mhd_sockets.h
Log:
Added socketpair creation in non-blocking mode to save system calls where
supported
Modified: libmicrohttpd/src/microhttpd/mhd_sockets.c
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_sockets.c 2016-10-11 15:20:40 UTC (rev
38104)
+++ libmicrohttpd/src/microhttpd/mhd_sockets.c 2016-10-11 15:20:44 UTC (rev
38105)
@@ -241,10 +241,12 @@
/**
* Create pair of mutually connected TCP/IP sockets on loopback address
* @param sockets_pair array to receive resulted sockets
+ * @param non_blk if set to non-zero value, sockets created in non-blocking
mode
+ * otherwise sockets will be in blocking mode
* @return non-zero if succeeded, zero otherwise
*/
int
-MHD_W32_socket_pair_(SOCKET sockets_pair[2])
+MHD_W32_socket_pair_(SOCKET sockets_pair[2], int non_blk)
{
int i;
@@ -261,7 +263,8 @@
SOCKET listen_s;
static const int c_addinlen = sizeof(struct sockaddr_in); /* help
compiler to optimize */
int addr_len = c_addinlen;
- int opt = 1;
+ unsigned long on_val = 1;
+ unsigned long off_val = 0;
listen_s = socket (AF_INET,
SOCK_STREAM,
@@ -297,7 +300,7 @@
if ( (0 != ioctlsocket (client_s,
FIONBIO,
- (u_long*) &opt)) ||
+ &on_val)) ||
( (0 != connect (client_s,
(struct sockaddr*) &listen_addr,
c_addinlen)) &&
@@ -322,7 +325,6 @@
}
addr_len = c_addinlen;
- opt = 0;
if ( (0 == getsockname (client_s,
(struct sockaddr*) &client_addr,
&addr_len)) &&
@@ -329,16 +331,17 @@
(accepted_from_addr.sin_family == client_addr.sin_family) &&
(accepted_from_addr.sin_port == client_addr.sin_port) &&
(accepted_from_addr.sin_addr.s_addr ==
client_addr.sin_addr.s_addr) &&
- (0 == ioctlsocket(client_s,
- FIONBIO,
- (u_long*) &opt)) &&
- (0 == ioctlsocket(server_s,
- FIONBIO,
- (u_long*) &opt)) )
+ ( (0 != non_blk) ?
+ (0 == ioctlsocket(server_s,
+ FIONBIO,
+ &on_val)) :
+ (0 == ioctlsocket(client_s,
+ FIONBIO,
+ &off_val)) ) )
{
closesocket (listen_s);
- sockets_pair[0] = client_s;
- sockets_pair[1] = server_s;
+ sockets_pair[0] = server_s;
+ sockets_pair[1] = client_s;
return !0;
}
closesocket (server_s);
Modified: libmicrohttpd/src/microhttpd/mhd_sockets.h
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_sockets.h 2016-10-11 15:20:40 UTC (rev
38104)
+++ libmicrohttpd/src/microhttpd/mhd_sockets.h 2016-10-11 15:20:44 UTC (rev
38105)
@@ -594,17 +594,26 @@
#if defined(MHD_POSIX_SOCKETS) && defined(AF_LOCAL)
# define MHD_socket_pair_(fdarr) (!socketpair(AF_LOCAL, SOCK_STREAM, 0,
(fdarr)))
+# if defined(HAVE_SOCK_NONBLOCK)
+# define MHD_socket_pair_nblk_(fdarr) (!socketpair(AF_LOCAL, SOCK_STREAM |
SOCK_NONBLOCK, 0, (fdarr)))
+# endif /* HAVE_SOCK_NONBLOCK*/
#elif defined(MHD_POSIX_SOCKETS) && defined(AF_UNIX)
# define MHD_socket_pair_(fdarr) (!socketpair(AF_UNIX, SOCK_STREAM, 0,
(fdarr)))
+# if defined(HAVE_SOCK_NONBLOCK)
+# define MHD_socket_pair_nblk_(fdarr) (!socketpair(AF_UNIX, SOCK_STREAM |
SOCK_NONBLOCK, 0, (fdarr)))
+# endif /* HAVE_SOCK_NONBLOCK*/
#elif defined(MHD_WINSOCK_SOCKETS)
/**
* Create pair of mutually connected TCP/IP sockets on loopback address
* @param sockets_pair array to receive resulted sockets
+ * @param non_blk if set to non-zero value, sockets created in non-blocking
mode
+ * otherwise sockets will be in blocking mode
* @return non-zero if succeeded, zero otherwise
*/
- int MHD_W32_socket_pair_(SOCKET sockets_pair[2]);
+ int MHD_W32_socket_pair_(SOCKET sockets_pair[2], int non_blk);
-# define MHD_socket_pair_(fdarr) MHD_W32_socket_pair_((fdarr))
+# define MHD_socket_pair_(fdarr) MHD_W32_socket_pair_((fdarr), 0)
+# define MHD_socket_pair_nblk_(fdarr) MHD_W32_socket_pair_((fdarr), 1)
#endif
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r38105 - libmicrohttpd/src/microhttpd,
gnunet <=