diff options
Diffstat (limited to 'src/lib/mhd_itc.c')
-rw-r--r-- | src/lib/mhd_itc.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/lib/mhd_itc.c b/src/lib/mhd_itc.c new file mode 100644 index 00000000..8aeee576 --- /dev/null +++ b/src/lib/mhd_itc.c | |||
@@ -0,0 +1,70 @@ | |||
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_itc.c | ||
23 | * @brief Implementation of inter-thread communication functions | ||
24 | * @author Karlson2k (Evgeny Grin) | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #include "mhd_itc.h" | ||
29 | #ifdef HAVE_UNISTD_H | ||
30 | #include <unistd.h> | ||
31 | #endif /* HAVE_UNISTD_H */ | ||
32 | #include <fcntl.h> | ||
33 | #include "internal.h" | ||
34 | |||
35 | |||
36 | #if defined(_MHD_ITC_PIPE) | ||
37 | #if !defined(_WIN32) || defined(__CYGWIN__) | ||
38 | |||
39 | #ifndef HAVE_PIPE2_FUNC | ||
40 | /** | ||
41 | * Change itc FD options to be non-blocking. | ||
42 | * | ||
43 | * @param itc the inter-thread communication primitive to manipulate | ||
44 | * @return non-zero if succeeded, zero otherwise | ||
45 | */ | ||
46 | int | ||
47 | MHD_itc_nonblocking_ (struct MHD_itc_ itc) | ||
48 | { | ||
49 | unsigned int i; | ||
50 | |||
51 | for (i=0;i<2;i++) | ||
52 | { | ||
53 | int flags; | ||
54 | |||
55 | flags = fcntl (itc.fd[i], | ||
56 | F_GETFL); | ||
57 | if (-1 == flags) | ||
58 | return 0; | ||
59 | |||
60 | if ( ((flags | O_NONBLOCK) != flags) && | ||
61 | (0 != fcntl (itc.fd[i], | ||
62 | F_SETFL, | ||
63 | flags | O_NONBLOCK)) ) | ||
64 | return 0; | ||
65 | } | ||
66 | return !0; | ||
67 | } | ||
68 | #endif /* ! HAVE_PIPE2_FUNC */ | ||
69 | #endif /* !_WIN32 || __CYGWIN__ */ | ||
70 | #endif /* _MHD_ITC_EVENTFD || _MHD_ITC_PIPE */ | ||