diff options
Diffstat (limited to 'src/microhttpd/mhd_itc.h')
-rw-r--r-- | src/microhttpd/mhd_itc.h | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/src/microhttpd/mhd_itc.h b/src/microhttpd/mhd_itc.h new file mode 100644 index 00000000..169bbb03 --- /dev/null +++ b/src/microhttpd/mhd_itc.h | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2016 Karlson2k (Evgeny Grin) | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file microhttpd/mhd_sockets.c | ||
23 | * @brief Header for platform-independent inter-thread communication | ||
24 | * @author Karlson2k (Evgeny Grin) | ||
25 | * | ||
26 | * Provides basic abstraction for inter-thread communication. | ||
27 | * Any functions can be implemented as macro on some platforms | ||
28 | * unless explicitly marked otherwise. | ||
29 | * Any function argument can be skipped in macro, so avoid | ||
30 | * variable modification in function parameters. | ||
31 | */ | ||
32 | |||
33 | #ifndef MHD_ITC_H | ||
34 | #define MHD_ITC_H 1 | ||
35 | #include "mhd_options.h" | ||
36 | |||
37 | /* Force don't use pipes on W32 */ | ||
38 | #if defined(_WIN32) && !defined(MHD_DONT_USE_PIPES) | ||
39 | #define MHD_DONT_USE_PIPES 1 | ||
40 | #endif /* defined(_WIN32) && !defined(MHD_DONT_USE_PIPES) */ | ||
41 | |||
42 | #ifndef MHD_DONT_USE_PIPES | ||
43 | # ifdef HAVE_STRING_H | ||
44 | # include <string.h> /* for strerror() */ | ||
45 | # endif | ||
46 | #else | ||
47 | # include "mhd_sockets.h" | ||
48 | #endif /* MHD_DONT_USE_PIPES */ | ||
49 | |||
50 | /* MHD_pipe is type for pipe FDs*/ | ||
51 | #ifndef MHD_DONT_USE_PIPES | ||
52 | typedef int MHD_pipe; | ||
53 | #else /* ! MHD_DONT_USE_PIPES */ | ||
54 | typedef MHD_socket MHD_pipe; | ||
55 | #endif /* ! MHD_DONT_USE_PIPES */ | ||
56 | |||
57 | /* MHD_pipe_ create pipe (!MHD_DONT_USE_PIPES) / | ||
58 | * create two connected sockets (MHD_DONT_USE_PIPES) */ | ||
59 | #ifndef MHD_DONT_USE_PIPES | ||
60 | # define MHD_pipe_(fdarr) pipe((fdarr)) | ||
61 | #else /* MHD_DONT_USE_PIPES */ | ||
62 | # if !defined(_WIN32) || defined(__CYGWIN__) | ||
63 | # define MHD_pipe_(fdarr) socketpair(AF_LOCAL, SOCK_STREAM, 0, (fdarr)) | ||
64 | # else /* !defined(_WIN32) || defined(__CYGWIN__) */ | ||
65 | # define MHD_pipe_(fdarr) MHD_W32_pair_of_sockets_((fdarr)) | ||
66 | # endif /* !defined(_WIN32) || defined(__CYGWIN__) */ | ||
67 | #endif /* MHD_DONT_USE_PIPES */ | ||
68 | |||
69 | /* MHD_pipe_last_strerror_ is description string of last errno (!MHD_DONT_USE_PIPES) / | ||
70 | * description string of last pipe error (MHD_DONT_USE_PIPES) */ | ||
71 | #ifndef MHD_DONT_USE_PIPES | ||
72 | # define MHD_pipe_last_strerror_() strerror(errno) | ||
73 | #else | ||
74 | # define MHD_pipe_last_strerror_() MHD_socket_last_strerr_() | ||
75 | #endif | ||
76 | |||
77 | /* MHD_pipe_write_ write data to real pipe (!MHD_DONT_USE_PIPES) / | ||
78 | * write data to emulated pipe (MHD_DONT_USE_PIPES) */ | ||
79 | #ifndef MHD_DONT_USE_PIPES | ||
80 | # define MHD_pipe_write_(fd, ptr, sz) write((fd), (const void*)(ptr), (sz)) | ||
81 | #else | ||
82 | # define MHD_pipe_write_(fd, ptr, sz) send((fd), (const char*)(ptr), (sz), 0) | ||
83 | #endif | ||
84 | |||
85 | /* MHD_pipe_drain_ drain data from real pipe (!MHD_DONT_USE_PIPES) / | ||
86 | * drain data from emulated pipe (MHD_DONT_USE_PIPES) */ | ||
87 | #ifndef MHD_DONT_USE_PIPES | ||
88 | # define MHD_pipe_drain_(fd) do { long tmp; while (0 < read((fd), (void*)&tmp, sizeof (tmp))) ; } while (0) | ||
89 | #else | ||
90 | # define MHD_pipe_drain_(fd) do { long tmp; while (0 < recv((fd), (void*)&tmp, sizeof (tmp), 0)) ; } while (0) | ||
91 | #endif | ||
92 | |||
93 | /* MHD_pipe_close_(fd) close any FDs (non-W32) / | ||
94 | * close emulated pipe FDs (W32) */ | ||
95 | #ifndef MHD_DONT_USE_PIPES | ||
96 | # define MHD_pipe_close_(fd) close((fd)) | ||
97 | #else | ||
98 | # define MHD_pipe_close_(fd) MHD_socket_close_((fd)) | ||
99 | #endif | ||
100 | |||
101 | /* MHD_INVALID_PIPE_ is a value of bad pipe FD */ | ||
102 | #ifndef MHD_DONT_USE_PIPES | ||
103 | # define MHD_INVALID_PIPE_ (-1) | ||
104 | #else | ||
105 | # define MHD_INVALID_PIPE_ MHD_INVALID_SOCKET | ||
106 | #endif | ||
107 | |||
108 | #if defined(_WIN32) && !defined(__CYGWIN__) | ||
109 | /** | ||
110 | * Create pair of mutually connected TCP/IP sockets on loopback address | ||
111 | * @param sockets_pair array to receive resulted sockets | ||
112 | * @return zero on success, -1 otherwise | ||
113 | */ | ||
114 | int MHD_W32_pair_of_sockets_(SOCKET sockets_pair[2]); | ||
115 | #endif /* _WIN32 && ! __CYGWIN__ */ | ||
116 | |||
117 | |||
118 | #endif /* MHD_ITC_H */ | ||