aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_itc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_itc.c')
-rw-r--r--src/microhttpd/mhd_itc.c81
1 files changed, 0 insertions, 81 deletions
diff --git a/src/microhttpd/mhd_itc.c b/src/microhttpd/mhd_itc.c
index 71e54a0d..553bfcf5 100644
--- a/src/microhttpd/mhd_itc.c
+++ b/src/microhttpd/mhd_itc.c
@@ -31,87 +31,6 @@
31#endif /* HAVE_UNISTD_H */ 31#endif /* HAVE_UNISTD_H */
32#include <fcntl.h> 32#include <fcntl.h>
33 33
34#if defined(_WIN32) && !defined(__CYGWIN__)
35/**
36 * Create pair of mutually connected TCP/IP sockets on loopback address
37 * @param sockets_pair array to receive resulted sockets
38 * @return zero on success, -1 otherwise
39 */
40int MHD_W32_pair_of_sockets_(SOCKET sockets_pair[2])
41{
42 int i;
43 if (!sockets_pair)
44 {
45 errno = EINVAL;
46 return -1;
47 }
48
49#define PAIRMAXTRYIES 800
50 for (i = 0; i < PAIRMAXTRYIES; i++)
51 {
52 struct sockaddr_in listen_addr;
53 SOCKET listen_s;
54 static const int c_addinlen = sizeof(struct sockaddr_in); /* help compiler to optimize */
55 int addr_len = c_addinlen;
56 int opt = 1;
57
58 listen_s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
59 if (INVALID_SOCKET == listen_s)
60 break; /* can't create even single socket */
61
62 listen_addr.sin_family = AF_INET;
63 listen_addr.sin_port = htons(0);
64 listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
65 if (0 == bind(listen_s, (struct sockaddr*) &listen_addr, c_addinlen)
66 && 0 == listen(listen_s, 1)
67 && 0 == getsockname(listen_s, (struct sockaddr*) &listen_addr,
68 &addr_len))
69 {
70 SOCKET client_s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
71 if (INVALID_SOCKET != client_s)
72 {
73 if (0 == ioctlsocket(client_s, FIONBIO, (u_long*) &opt)
74 && (0 == connect(client_s, (struct sockaddr*) &listen_addr, c_addinlen)
75 || WSAGetLastError() == WSAEWOULDBLOCK))
76 {
77 struct sockaddr_in accepted_from_addr;
78 SOCKET server_s;
79 addr_len = c_addinlen;
80 server_s = accept(listen_s,
81 (struct sockaddr*) &accepted_from_addr, &addr_len);
82 if (INVALID_SOCKET != server_s)
83 {
84 struct sockaddr_in client_addr;
85 addr_len = c_addinlen;
86 opt = 0;
87 if (0 == getsockname(client_s, (struct sockaddr*) &client_addr, &addr_len)
88 && accepted_from_addr.sin_family == client_addr.sin_family
89 && accepted_from_addr.sin_port == client_addr.sin_port
90 && accepted_from_addr.sin_addr.s_addr == client_addr.sin_addr.s_addr
91 && 0 == ioctlsocket(client_s, FIONBIO, (u_long*) &opt)
92 && 0 == ioctlsocket(server_s, FIONBIO, (u_long*) &opt))
93 {
94 closesocket(listen_s);
95 sockets_pair[0] = client_s;
96 sockets_pair[1] = server_s;
97 return 0;
98 }
99 closesocket(server_s);
100 }
101 }
102 closesocket(client_s);
103 }
104 }
105 closesocket(listen_s);
106 }
107
108 sockets_pair[0] = INVALID_SOCKET;
109 sockets_pair[1] = INVALID_SOCKET;
110 return -1;
111}
112
113#endif /* _WIN32 && ! __CYGWIN__ */
114
115#ifndef MHD_DONT_USE_PIPES 34#ifndef MHD_DONT_USE_PIPES
116#if !defined(_WIN32) || defined(__CYGWIN__) 35#if !defined(_WIN32) || defined(__CYGWIN__)
117 36