diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-10-11 15:20:53 +0000 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-10-11 15:20:53 +0000 |
commit | 21ffb5e8420d6b4284932ae0eb6021f2118e21be (patch) | |
tree | b58520badf3dfc15c956e77af52e4e266ecb7df1 /src | |
parent | b6ae5bf9b70c867664daced6f24b6ba28ebc6c82 (diff) | |
download | libmicrohttpd-21ffb5e8420d6b4284932ae0eb6021f2118e21be.tar.gz libmicrohttpd-21ffb5e8420d6b4284932ae0eb6021f2118e21be.zip |
Renamed "pipe" to "itc" as it actually more some kind of channel, not always pipe.
Used typedef for "itc" type.
Diffstat (limited to 'src')
-rw-r--r-- | src/microhttpd/internal.h | 8 | ||||
-rw-r--r-- | src/microhttpd/mhd_itc.c | 8 | ||||
-rw-r--r-- | src/microhttpd/mhd_itc.h | 64 |
3 files changed, 35 insertions, 45 deletions
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index a72fcf65..c8c64698 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -1352,13 +1352,9 @@ struct MHD_Daemon | |||
1352 | #endif | 1352 | #endif |
1353 | 1353 | ||
1354 | /** | 1354 | /** |
1355 | * Pipe we use to signal shutdown, unless | 1355 | * Inter-thread communication channel. |
1356 | * 'HAVE_LISTEN_SHUTDOWN' is defined AND we have a listen | ||
1357 | * socket (which we can then 'shutdown' to stop listening). | ||
1358 | * MHD can be build with usage of socketpair instead of | ||
1359 | * pipe (forced on W32). | ||
1360 | */ | 1356 | */ |
1361 | struct MHD_Pipe wpipe; | 1357 | MHD_itc_ wpipe; |
1362 | 1358 | ||
1363 | /** | 1359 | /** |
1364 | * Are we shutting down? | 1360 | * Are we shutting down? |
diff --git a/src/microhttpd/mhd_itc.c b/src/microhttpd/mhd_itc.c index e6cbd875..14e474d8 100644 --- a/src/microhttpd/mhd_itc.c +++ b/src/microhttpd/mhd_itc.c | |||
@@ -36,13 +36,13 @@ | |||
36 | #ifdef _MHD_ITC_EVENTFD | 36 | #ifdef _MHD_ITC_EVENTFD |
37 | 37 | ||
38 | int | 38 | int |
39 | MHD_pipe_write_ (struct MHD_Pipe pip, | 39 | MHD_pipe_write_ (MHD_itc_ pip, |
40 | const void *ptr, | 40 | const void *ptr, |
41 | size_t sz) | 41 | size_t sz) |
42 | { | 42 | { |
43 | uint64_t val = 1; | 43 | uint64_t val = 1; |
44 | if (sizeof (val) != | 44 | if (sizeof (val) != |
45 | write (pip.event_fd, | 45 | write (pip, |
46 | &val, | 46 | &val, |
47 | sizeof (val))) | 47 | sizeof (val))) |
48 | MHD_PANIC (_("Failed to write to eventfd\n")); | 48 | MHD_PANIC (_("Failed to write to eventfd\n")); |
@@ -62,7 +62,7 @@ MHD_pipe_write_ (struct MHD_Pipe pip, | |||
62 | * @return non-zero if succeeded, zero otherwise | 62 | * @return non-zero if succeeded, zero otherwise |
63 | */ | 63 | */ |
64 | int | 64 | int |
65 | MHD_itc_nonblocking_ (struct MHD_Pipe pip) | 65 | MHD_itc_nonblocking_ (MHD_itc_ itc) |
66 | { | 66 | { |
67 | unsigned int i; | 67 | unsigned int i; |
68 | 68 | ||
@@ -70,7 +70,7 @@ MHD_itc_nonblocking_ (struct MHD_Pipe pip) | |||
70 | { | 70 | { |
71 | int flags; | 71 | int flags; |
72 | 72 | ||
73 | flags = fcntl (pip.fd[i], | 73 | flags = fcntl (itc.fd[i], |
74 | F_GETFL); | 74 | F_GETFL); |
75 | if (-1 == flags) | 75 | if (-1 == flags) |
76 | return 0; | 76 | return 0; |
diff --git a/src/microhttpd/mhd_itc.h b/src/microhttpd/mhd_itc.h index 49909516..d91ebccf 100644 --- a/src/microhttpd/mhd_itc.h +++ b/src/microhttpd/mhd_itc.h | |||
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file microhttpd/mhd_itc.h | 22 | * @file microhttpd/mhd_itc.h |
23 | * @brief Header for platform-independent inter-thread signaling via pipes | 23 | * @brief Header for platform-independent inter-thread communication |
24 | * @author Karlson2k (Evgeny Grin) | 24 | * @author Karlson2k (Evgeny Grin) |
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | * | 26 | * |
@@ -47,20 +47,17 @@ | |||
47 | #if defined(_MHD_ITC_EVENTFD) | 47 | #if defined(_MHD_ITC_EVENTFD) |
48 | #include <sys/eventfd.h> | 48 | #include <sys/eventfd.h> |
49 | 49 | ||
50 | /* **************** Optimized eventfd PIPE implementation ********** */ | 50 | /* **************** Optimized GNU/Linux ITC implementation by eventfd ********** */ |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Data type for a MHD pipe. | 53 | * Data type for a MHD ITC. |
54 | */ | 54 | */ |
55 | struct MHD_Pipe | 55 | typedef int MHD_itc_; |
56 | { | ||
57 | int event_fd; | ||
58 | }; | ||
59 | 56 | ||
60 | /** | 57 | /** |
61 | * create pipe | 58 | * create pipe |
62 | */ | 59 | */ |
63 | #define MHD_pipe_(pip) ((-1 == (pip.event_fd = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK))) ? 0 : !0) | 60 | #define MHD_pipe_(itc) ((-1 == (itc = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK))) ? 0 : !0) |
64 | 61 | ||
65 | /*** | 62 | /*** |
66 | * Get description string of last errno for pipe operations. | 63 | * Get description string of last errno for pipe operations. |
@@ -71,27 +68,27 @@ struct MHD_Pipe | |||
71 | * write data to real pipe | 68 | * write data to real pipe |
72 | */ | 69 | */ |
73 | int | 70 | int |
74 | MHD_pipe_write_ (struct MHD_Pipe pip, | 71 | MHD_pipe_write_ (MHD_itc_ pip, |
75 | const void *ptr, | 72 | const void *ptr, |
76 | size_t sz); | 73 | size_t sz); |
77 | 74 | ||
78 | #define MHD_pipe_get_read_fd_(pip) (pip.event_fd) | 75 | #define MHD_pipe_get_read_fd_(pip) (pip) |
79 | 76 | ||
80 | #define MHD_pipe_get_write_fd_(pip) (pip.event_fd) | 77 | #define MHD_pipe_get_write_fd_(pip) (pip) |
81 | 78 | ||
82 | /** | 79 | /** |
83 | * drain data from real pipe | 80 | * drain data from real pipe |
84 | */ | 81 | */ |
85 | #define MHD_pipe_drain_(pip) do { \ | 82 | #define MHD_pipe_drain_(pip) do { \ |
86 | uint64_t tmp; \ | 83 | uint64_t tmp; \ |
87 | read (pip.event_fd, &tmp, sizeof (tmp)); \ | 84 | read (pip, &tmp, sizeof (tmp)); \ |
88 | } while (0) | 85 | } while (0) |
89 | 86 | ||
90 | /** | 87 | /** |
91 | * Close any FDs of the pipe (non-W32) | 88 | * Close any FDs of the pipe (non-W32) |
92 | */ | 89 | */ |
93 | #define MHD_pipe_close_(pip) do { \ | 90 | #define MHD_pipe_close_(pip) do { \ |
94 | if ( (0 != close (pip.event_fd)) && \ | 91 | if ( (0 != close (pip)) && \ |
95 | (EBADF == errno) ) \ | 92 | (EBADF == errno) ) \ |
96 | MHD_PANIC (_("close failed")); \ | 93 | MHD_PANIC (_("close failed")); \ |
97 | } while (0) | 94 | } while (0) |
@@ -99,13 +96,13 @@ MHD_pipe_write_ (struct MHD_Pipe pip, | |||
99 | /** | 96 | /** |
100 | * Check if we have an uninitialized pipe | 97 | * Check if we have an uninitialized pipe |
101 | */ | 98 | */ |
102 | #define MHD_INVALID_PIPE_(pip) (-1 == pip.event_fd) | 99 | #define MHD_INVALID_PIPE_(pip) (-1 == pip) |
103 | 100 | ||
104 | /** | 101 | /** |
105 | * Setup uninitialized @a pip data structure. | 102 | * Setup uninitialized @a pip data structure. |
106 | */ | 103 | */ |
107 | #define MHD_make_invalid_pipe_(pip) do { \ | 104 | #define MHD_make_invalid_pipe_(pip) do { \ |
108 | pip.event_fd = -1; \ | 105 | pip = -1; \ |
109 | } while (0) | 106 | } while (0) |
110 | 107 | ||
111 | 108 | ||
@@ -121,24 +118,25 @@ MHD_pipe_write_ (struct MHD_Pipe pip, | |||
121 | 118 | ||
122 | #elif defined(_MHD_ITC_PIPE) | 119 | #elif defined(_MHD_ITC_PIPE) |
123 | 120 | ||
124 | /* **************** STANDARD UNIX PIPE implementation ********** */ | 121 | /* **************** Standard UNIX ITC implementation by pipe ********** */ |
125 | 122 | ||
126 | # ifdef HAVE_STRING_H | 123 | # ifdef HAVE_STRING_H |
127 | # include <string.h> /* for strerror() */ | 124 | # include <string.h> /* for strerror() */ |
128 | # endif | 125 | # endif |
129 | 126 | ||
130 | /** | 127 | /** |
131 | * Data type for a MHD pipe. | 128 | * Data type for a MHD ITC. |
132 | */ | 129 | */ |
133 | struct MHD_Pipe | 130 | struct MHD_Itc |
134 | { | 131 | { |
135 | int fd[2]; | 132 | int fd[2]; |
136 | }; | 133 | }; |
134 | typedef struct MHD_Itc MHD_itc_; | ||
137 | 135 | ||
138 | /** | 136 | /** |
139 | * create pipe | 137 | * create pipe |
140 | */ | 138 | */ |
141 | #define MHD_pipe_(pip) (!pipe((pip.fd))) | 139 | #define MHD_pipe_(pip) (!pipe((pip).fd)) |
142 | 140 | ||
143 | /*** | 141 | /*** |
144 | * Get description string of last errno for pipe operations. | 142 | * Get description string of last errno for pipe operations. |
@@ -148,29 +146,29 @@ struct MHD_Pipe | |||
148 | /** | 146 | /** |
149 | * write data to real pipe | 147 | * write data to real pipe |
150 | */ | 148 | */ |
151 | #define MHD_pipe_write_(pip, ptr, sz) write((pip.fd[1]), (const void*)(ptr), (sz)) | 149 | #define MHD_pipe_write_(pip, ptr, sz) write((pip).fd[1], (const void*)(ptr), (sz)) |
152 | 150 | ||
153 | 151 | ||
154 | #define MHD_pipe_get_read_fd_(pip) (pip.fd[0]) | 152 | #define MHD_pipe_get_read_fd_(pip) ((pip).fd[0]) |
155 | 153 | ||
156 | #define MHD_pipe_get_write_fd_(pip) (pip.fd[1]) | 154 | #define MHD_pipe_get_write_fd_(pip) ((pip).fd[1]) |
157 | 155 | ||
158 | /** | 156 | /** |
159 | * drain data from real pipe | 157 | * drain data from real pipe |
160 | */ | 158 | */ |
161 | #define MHD_pipe_drain_(pip) do { \ | 159 | #define MHD_pipe_drain_(pip) do { \ |
162 | long tmp; \ | 160 | long tmp; \ |
163 | while (0 < read((pip.fd[0]), (void*)&tmp, sizeof (tmp))) ; \ | 161 | while (0 < read((pip).fd[0], (void*)&tmp, sizeof (tmp))) ; \ |
164 | } while (0) | 162 | } while (0) |
165 | 163 | ||
166 | /** | 164 | /** |
167 | * Close any FDs of the pipe (non-W32) | 165 | * Close any FDs of the pipe (non-W32) |
168 | */ | 166 | */ |
169 | #define MHD_pipe_close_(pip) do { \ | 167 | #define MHD_pipe_close_(pip) do { \ |
170 | if ( (0 != close (pip.fd[0])) && \ | 168 | if ( (0 != close ((pip).fd[0])) && \ |
171 | (EBADF == errno) ) \ | 169 | (EBADF == errno) ) \ |
172 | MHD_PANIC (_("close failed")); \ | 170 | MHD_PANIC (_("close failed")); \ |
173 | if ( (0 != close (pip.fd[1])) && \ | 171 | if ( (0 != close ((pip).fd[1])) && \ |
174 | (EBADF == errno) ) \ | 172 | (EBADF == errno) ) \ |
175 | MHD_PANIC (_("close failed")); \ | 173 | MHD_PANIC (_("close failed")); \ |
176 | } while (0) | 174 | } while (0) |
@@ -178,13 +176,13 @@ struct MHD_Pipe | |||
178 | /** | 176 | /** |
179 | * Check if we have an uninitialized pipe | 177 | * Check if we have an uninitialized pipe |
180 | */ | 178 | */ |
181 | #define MHD_INVALID_PIPE_(pip) (-1 == pip.fd[0]) | 179 | #define MHD_INVALID_PIPE_(pip) (-1 == (pip).fd[0]) |
182 | 180 | ||
183 | /** | 181 | /** |
184 | * Setup uninitialized @a pip data structure. | 182 | * Setup uninitialized @a pip data structure. |
185 | */ | 183 | */ |
186 | #define MHD_make_invalid_pipe_(pip) do { \ | 184 | #define MHD_make_invalid_pipe_(pip) do { \ |
187 | pip.fd[0] = pip.fd[1] = -1; \ | 185 | (pip).fd[0] = (pip).fd[1] = -1; \ |
188 | } while (0) | 186 | } while (0) |
189 | 187 | ||
190 | /** | 188 | /** |
@@ -194,25 +192,23 @@ struct MHD_Pipe | |||
194 | * @return non-zero if succeeded, zero otherwise | 192 | * @return non-zero if succeeded, zero otherwise |
195 | */ | 193 | */ |
196 | int | 194 | int |
197 | MHD_itc_nonblocking_ (struct MHD_Pipe fd); | 195 | MHD_itc_nonblocking_ (MHD_itc_ itc); |
198 | |||
199 | 196 | ||
200 | /* **************** END OF STANDARD UNIX PIPE implementation ********** */ | ||
201 | 197 | ||
202 | #elif defined(_MHD_ITC_SOCKETPAIR) | 198 | #elif defined(_MHD_ITC_SOCKETPAIR) |
203 | 199 | ||
204 | /* **************** PIPE EMULATION by socket pairs ********** */ | 200 | /* **************** ITC implementation by socket pair ********** */ |
205 | 201 | ||
206 | #include "mhd_sockets.h" | 202 | #include "mhd_sockets.h" |
207 | 203 | ||
208 | /** | 204 | /** |
209 | * Data type for a MHD pipe. | 205 | * Data type for a MHD pipe. |
210 | */ | 206 | */ |
211 | struct MHD_Pipe | 207 | struct MHD_Itc |
212 | { | 208 | { |
213 | MHD_socket fd[2]; | 209 | MHD_socket fd[2]; |
214 | }; | 210 | }; |
215 | 211 | typedef struct MHD_Itc MHD_itc_; | |
216 | 212 | ||
217 | /** | 213 | /** |
218 | * Create two connected sockets to emulate a pipe. | 214 | * Create two connected sockets to emulate a pipe. |
@@ -262,8 +258,6 @@ struct MHD_Pipe | |||
262 | 258 | ||
263 | #define MHD_itc_nonblocking_(pip) (MHD_socket_nonblocking_((pip.fd[0])) && MHD_socket_nonblocking_((pip.fd[1]))) | 259 | #define MHD_itc_nonblocking_(pip) (MHD_socket_nonblocking_((pip.fd[0])) && MHD_socket_nonblocking_((pip.fd[1]))) |
264 | 260 | ||
265 | /* **************** END OF PIPE EMULATION by socket pairs ********** */ | ||
266 | |||
267 | #endif /* _MHD_ITC_SOCKETPAIR */ | 261 | #endif /* _MHD_ITC_SOCKETPAIR */ |
268 | 262 | ||
269 | #endif /* MHD_ITC_H */ | 263 | #endif /* MHD_ITC_H */ |