diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2023-11-08 10:28:19 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2023-11-08 10:28:19 +0300 |
commit | cec5aed907524f47ee06ebc4f9704441df5d1023 (patch) | |
tree | bb7bbb8756caa2c471592d421c17094c668a2598 | |
parent | ce1ca4cf4e73af58ceb2d1887e4dbb2bb417cf6a (diff) | |
download | libmicrohttpd-cec5aed907524f47ee06ebc4f9704441df5d1023.tar.gz libmicrohttpd-cec5aed907524f47ee06ebc4f9704441df5d1023.zip |
mhd_itc.h: cosmetics
-rw-r--r-- | src/microhttpd/mhd_itc.h | 93 |
1 files changed, 47 insertions, 46 deletions
diff --git a/src/microhttpd/mhd_itc.h b/src/microhttpd/mhd_itc.h index 780a6c53..55f82664 100644 --- a/src/microhttpd/mhd_itc.h +++ b/src/microhttpd/mhd_itc.h | |||
@@ -42,10 +42,11 @@ | |||
42 | # include <stdlib.h> | 42 | # include <stdlib.h> |
43 | # endif /* HAVE_STDLIB_H */ | 43 | # endif /* HAVE_STDLIB_H */ |
44 | /* Simple implementation of MHD_PANIC, to be used outside lib */ | 44 | /* Simple implementation of MHD_PANIC, to be used outside lib */ |
45 | # define MHD_PANIC(msg) do { fprintf (stderr, \ | 45 | # define MHD_PANIC(msg) \ |
46 | "Abnormal termination at %d line in file %s: %s\n", \ | 46 | do { fprintf (stderr, \ |
47 | (int) __LINE__, __FILE__, msg); abort (); \ | 47 | "Abnormal termination at %d line in file %s: %s\n", \ |
48 | } while (0) | 48 | (int) __LINE__, __FILE__, msg); abort (); \ |
49 | } while (0) | ||
49 | #endif /* ! MHD_PANIC */ | 50 | #endif /* ! MHD_PANIC */ |
50 | 51 | ||
51 | #if defined(_MHD_ITC_EVENTFD) | 52 | #if defined(_MHD_ITC_EVENTFD) |
@@ -71,8 +72,8 @@ | |||
71 | * @param itc the itc to initialise | 72 | * @param itc the itc to initialise |
72 | * @return non-zero if succeeded, zero otherwise | 73 | * @return non-zero if succeeded, zero otherwise |
73 | */ | 74 | */ |
74 | #define MHD_itc_init_(itc) (-1 != ((itc).fd = eventfd (0, EFD_CLOEXEC \ | 75 | #define MHD_itc_init_(itc) \ |
75 | | EFD_NONBLOCK))) | 76 | (-1 != ((itc).fd = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK))) |
76 | 77 | ||
77 | /** | 78 | /** |
78 | * Get description string of last errno for itc operations. | 79 | * Get description string of last errno for itc operations. |
@@ -90,9 +91,9 @@ static const uint64_t _MHD_itc_wr_data = 1; | |||
90 | * @param str ignored | 91 | * @param str ignored |
91 | * @return non-zero if succeeded, zero otherwise | 92 | * @return non-zero if succeeded, zero otherwise |
92 | */ | 93 | */ |
93 | #define MHD_itc_activate_(itc, str) \ | 94 | #define MHD_itc_activate_(itc, str) \ |
94 | ((write ((itc).fd, (const void*) &_MHD_itc_wr_data, 8) > 0) || (EAGAIN == \ | 95 | ((write ((itc).fd, (const void*) &_MHD_itc_wr_data, \ |
95 | errno)) | 96 | sizeof(_MHD_itc_wr_data)) > 0) || (EAGAIN == errno)) |
96 | 97 | ||
97 | /** | 98 | /** |
98 | * Return read FD of @a itc which can be used for poll(), select() etc. | 99 | * Return read FD of @a itc which can be used for poll(), select() etc. |
@@ -112,9 +113,9 @@ static const uint64_t _MHD_itc_wr_data = 1; | |||
112 | * Clear signaled state on @a itc | 113 | * Clear signaled state on @a itc |
113 | * @param itc the itc to clear | 114 | * @param itc the itc to clear |
114 | */ | 115 | */ |
115 | #define MHD_itc_clear_(itc) \ | 116 | #define MHD_itc_clear_(itc) \ |
116 | do { uint64_t __b; \ | 117 | do { uint64_t __b; \ |
117 | (void) read ((itc).fd, &__b, sizeof(__b)); \ | 118 | (void) read ((itc).fd, (void*)&__b, sizeof(__b)); \ |
118 | } while (0) | 119 | } while (0) |
119 | 120 | ||
120 | /** | 121 | /** |
@@ -124,7 +125,8 @@ static const uint64_t _MHD_itc_wr_data = 1; | |||
124 | * @param itc the itc to destroy | 125 | * @param itc the itc to destroy |
125 | * @return non-zero if succeeded, zero otherwise | 126 | * @return non-zero if succeeded, zero otherwise |
126 | */ | 127 | */ |
127 | #define MHD_itc_destroy_(itc) ((0 == close ((itc).fd)) || (EBADF != errno)) | 128 | #define MHD_itc_destroy_(itc) \ |
129 | ((0 == close ((itc).fd)) || (EBADF != errno)) | ||
128 | 130 | ||
129 | /** | 131 | /** |
130 | * Check whether ITC has valid value. | 132 | * Check whether ITC has valid value. |
@@ -172,11 +174,11 @@ static const uint64_t _MHD_itc_wr_data = 1; | |||
172 | #ifdef HAVE_PIPE2_FUNC | 174 | #ifdef HAVE_PIPE2_FUNC |
173 | # define MHD_itc_init_(itc) (! pipe2 ((itc).fd, O_CLOEXEC | O_NONBLOCK)) | 175 | # define MHD_itc_init_(itc) (! pipe2 ((itc).fd, O_CLOEXEC | O_NONBLOCK)) |
174 | #else /* ! HAVE_PIPE2_FUNC */ | 176 | #else /* ! HAVE_PIPE2_FUNC */ |
175 | # define MHD_itc_init_(itc) \ | 177 | # define MHD_itc_init_(itc) \ |
176 | ( (! pipe ((itc).fd)) ? \ | 178 | ( (! pipe ((itc).fd)) ? \ |
177 | (MHD_itc_nonblocking_ ((itc)) ? \ | 179 | (MHD_itc_nonblocking_ ((itc)) ? \ |
178 | (! 0) : \ | 180 | (! 0) : \ |
179 | (MHD_itc_destroy_ ((itc)), 0) ) \ | 181 | (MHD_itc_destroy_ ((itc)), 0) ) \ |
180 | : (0) ) | 182 | : (0) ) |
181 | #endif /* ! HAVE_PIPE2_FUNC */ | 183 | #endif /* ! HAVE_PIPE2_FUNC */ |
182 | 184 | ||
@@ -213,19 +215,19 @@ static const uint64_t _MHD_itc_wr_data = 1; | |||
213 | * Clear signaled state on @a itc | 215 | * Clear signaled state on @a itc |
214 | * @param itc the itc to clear | 216 | * @param itc the itc to clear |
215 | */ | 217 | */ |
216 | #define MHD_itc_clear_(itc) do \ | 218 | #define MHD_itc_clear_(itc) do \ |
217 | { long __b; \ | 219 | { long __b; \ |
218 | while (0 < read ((itc).fd[0], &__b, sizeof(__b))) \ | 220 | while (0 < read ((itc).fd[0], (void*) &__b, sizeof(__b))) \ |
219 | {} } while (0) | 221 | {(void)0;} } while (0) |
220 | 222 | ||
221 | /** | 223 | /** |
222 | * Destroy previously initialised ITC | 224 | * Destroy previously initialised ITC |
223 | * @param itc the itc to destroy | 225 | * @param itc the itc to destroy |
224 | * @return non-zero if succeeded, zero otherwise | 226 | * @return non-zero if succeeded, zero otherwise |
225 | */ | 227 | */ |
226 | #define MHD_itc_destroy_(itc) \ | 228 | #define MHD_itc_destroy_(itc) \ |
227 | ( (0 == close ((itc).fd[0])) ? \ | 229 | ( (0 == close ((itc).fd[0])) ? \ |
228 | (0 == close ((itc).fd[1])) : \ | 230 | (0 == close ((itc).fd[1])) : \ |
229 | ((close ((itc).fd[1])), 0) ) | 231 | ((close ((itc).fd[1])), 0) ) |
230 | 232 | ||
231 | /** | 233 | /** |
@@ -278,11 +280,11 @@ MHD_itc_nonblocking_ (struct MHD_itc_ itc); | |||
278 | #ifdef MHD_socket_pair_nblk_ | 280 | #ifdef MHD_socket_pair_nblk_ |
279 | # define MHD_itc_init_(itc) MHD_socket_pair_nblk_ ((itc).sk) | 281 | # define MHD_itc_init_(itc) MHD_socket_pair_nblk_ ((itc).sk) |
280 | #else /* ! MHD_socket_pair_nblk_ */ | 282 | #else /* ! MHD_socket_pair_nblk_ */ |
281 | # define MHD_itc_init_(itc) \ | 283 | # define MHD_itc_init_(itc) \ |
282 | (MHD_socket_pair_ ((itc).sk) ? \ | 284 | (MHD_socket_pair_ ((itc).sk) ? \ |
283 | (MHD_itc_nonblocking_ ((itc)) ? \ | 285 | (MHD_itc_nonblocking_ ((itc)) ? \ |
284 | (! 0) : \ | 286 | (! 0) : \ |
285 | (MHD_itc_destroy_ ((itc)), 0) ) \ | 287 | (MHD_itc_destroy_ ((itc)), 0) ) \ |
286 | : (0)) | 288 | : (0)) |
287 | #endif /* ! MHD_socket_pair_nblk_ */ | 289 | #endif /* ! MHD_socket_pair_nblk_ */ |
288 | 290 | ||
@@ -297,8 +299,8 @@ MHD_itc_nonblocking_ (struct MHD_itc_ itc); | |||
297 | * @param str one-symbol string, useful only for strace debug | 299 | * @param str one-symbol string, useful only for strace debug |
298 | * @return non-zero if succeeded, zero otherwise | 300 | * @return non-zero if succeeded, zero otherwise |
299 | */ | 301 | */ |
300 | #define MHD_itc_activate_(itc, str) \ | 302 | #define MHD_itc_activate_(itc, str) \ |
301 | ((MHD_send_ ((itc).sk[1], (str), 1) > 0) || \ | 303 | ((MHD_send_ ((itc).sk[1], (str), 1) > 0) || \ |
302 | (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ()))) | 304 | (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ()))) |
303 | 305 | ||
304 | /** | 306 | /** |
@@ -319,21 +321,19 @@ MHD_itc_nonblocking_ (struct MHD_itc_ itc); | |||
319 | * Clear signaled state on @a itc | 321 | * Clear signaled state on @a itc |
320 | * @param itc the itc to clear | 322 | * @param itc the itc to clear |
321 | */ | 323 | */ |
322 | #define MHD_itc_clear_(itc) do \ | 324 | #define MHD_itc_clear_(itc) do \ |
323 | { long __b; \ | 325 | { long __b; \ |
324 | while (0 < recv ((itc).sk[0], \ | 326 | while (0 < recv ((itc).sk[0], (void*) &__b, sizeof(__b), 0)) \ |
325 | (char*) &__b, \ | 327 | {(void)0;} } while (0) |
326 | sizeof(__b), 0)) \ | ||
327 | {} } while (0) | ||
328 | 328 | ||
329 | /** | 329 | /** |
330 | * Destroy previously initialised ITC | 330 | * Destroy previously initialised ITC |
331 | * @param itc the itc to destroy | 331 | * @param itc the itc to destroy |
332 | * @return non-zero if succeeded, zero otherwise | 332 | * @return non-zero if succeeded, zero otherwise |
333 | */ | 333 | */ |
334 | #define MHD_itc_destroy_(itc) \ | 334 | #define MHD_itc_destroy_(itc) \ |
335 | (MHD_socket_close_ ((itc).sk[0]) ? \ | 335 | (MHD_socket_close_ ((itc).sk[0]) ? \ |
336 | MHD_socket_close_ ((itc).sk[1]) : \ | 336 | MHD_socket_close_ ((itc).sk[1]) : \ |
337 | ((void) MHD_socket_close_ ((itc).sk[1]), 0) ) | 337 | ((void) MHD_socket_close_ ((itc).sk[1]), 0) ) |
338 | 338 | ||
339 | 339 | ||
@@ -352,12 +352,13 @@ MHD_itc_nonblocking_ (struct MHD_itc_ itc); | |||
352 | * Set @a itc to invalid value. | 352 | * Set @a itc to invalid value. |
353 | * @param itc the itc to set | 353 | * @param itc the itc to set |
354 | */ | 354 | */ |
355 | #define MHD_itc_set_invalid_(itc) ((itc).sk[0] = (itc).sk[1] = \ | 355 | #define MHD_itc_set_invalid_(itc) \ |
356 | MHD_INVALID_SOCKET) | 356 | ((itc).sk[0] = (itc).sk[1] = MHD_INVALID_SOCKET) |
357 | 357 | ||
358 | #ifndef MHD_socket_pair_nblk_ | 358 | #ifndef MHD_socket_pair_nblk_ |
359 | # define MHD_itc_nonblocking_(pip) (MHD_socket_nonblocking_ ((pip).sk[0]) && \ | 359 | # define MHD_itc_nonblocking_(pip) \ |
360 | MHD_socket_nonblocking_ ((pip).sk[1])) | 360 | (MHD_socket_nonblocking_ ((pip).sk[0]) && \ |
361 | MHD_socket_nonblocking_ ((pip).sk[1])) | ||
361 | #endif /* ! MHD_socket_pair_nblk_ */ | 362 | #endif /* ! MHD_socket_pair_nblk_ */ |
362 | 363 | ||
363 | #endif /* _MHD_ITC_SOCKETPAIR */ | 364 | #endif /* _MHD_ITC_SOCKETPAIR */ |
@@ -367,9 +368,9 @@ MHD_itc_nonblocking_ (struct MHD_itc_ itc); | |||
367 | * if error is detected. | 368 | * if error is detected. |
368 | * @param itc the itc to destroy | 369 | * @param itc the itc to destroy |
369 | */ | 370 | */ |
370 | #define MHD_itc_destroy_chk_(itc) do { \ | 371 | #define MHD_itc_destroy_chk_(itc) do { \ |
371 | if (! MHD_itc_destroy_ (itc)) \ | 372 | if (! MHD_itc_destroy_ (itc)) \ |
372 | MHD_PANIC (_ ("Failed to destroy ITC.\n")); \ | 373 | MHD_PANIC (_ ("Failed to destroy ITC.\n")); \ |
373 | } while (0) | 374 | } while (0) |
374 | 375 | ||
375 | /** | 376 | /** |