aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/microhttpd/Makefile.am2
-rw-r--r--src/microhttpd/connection.c5
-rw-r--r--src/microhttpd/daemon.c22
-rw-r--r--src/microhttpd/internal.h2
-rw-r--r--src/microhttpd/mhd_itc.c18
-rw-r--r--src/microhttpd/mhd_itc.h81
-rw-r--r--src/microhttpd/mhd_itc_types.h83
-rw-r--r--w32/common/libmicrohttpd-files.vcxproj1
-rw-r--r--w32/common/libmicrohttpd-filters.vcxproj3
9 files changed, 137 insertions, 80 deletions
diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am
index 4d0f81ce..11030731 100644
--- a/src/microhttpd/Makefile.am
+++ b/src/microhttpd/Makefile.am
@@ -67,7 +67,7 @@ libmicrohttpd_la_SOURCES = \
67 mhd_threads.c mhd_threads.h \ 67 mhd_threads.c mhd_threads.h \
68 mhd_locks.h mhd_sem.c \ 68 mhd_locks.h mhd_sem.c \
69 mhd_sockets.c mhd_sockets.h \ 69 mhd_sockets.c mhd_sockets.h \
70 mhd_itc.c mhd_itc.h \ 70 mhd_itc.c mhd_itc.h mhd_itc_types.h \
71 mhd_compat.h \ 71 mhd_compat.h \
72 response.c response.h 72 response.c response.h
73if HAVE_W32 73if HAVE_W32
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 10e0551d..b480dd4d 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -34,6 +34,7 @@
34#include "mhd_locks.h" 34#include "mhd_locks.h"
35#include "mhd_sockets.h" 35#include "mhd_sockets.h"
36#include "mhd_compat.h" 36#include "mhd_compat.h"
37#include "mhd_itc.h"
37 38
38 39
39/** 40/**
@@ -521,9 +522,7 @@ MHD_connection_close_ (struct MHD_Connection *connection,
521 to resume accepting connections */ 522 to resume accepting connections */
522 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 523 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
523 (! MHD_INVALID_PIPE_ (daemon->itc)) && 524 (! MHD_INVALID_PIPE_ (daemon->itc)) &&
524 (1 != MHD_pipe_write_ (daemon->itc, 525 (! MHD_itc_activate_ (daemon->itc, "c")) )
525 "c",
526 1)) )
527 { 526 {
528#ifdef HAVE_MESSAGES 527#ifdef HAVE_MESSAGES
529 MHD_DLOG (daemon, 528 MHD_DLOG (daemon,
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 26a87782..cad0ed53 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2029,9 +2029,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
2029 else 2029 else
2030 if ( (MHD_YES == external_add) && 2030 if ( (MHD_YES == external_add) &&
2031 (! MHD_INVALID_PIPE_(daemon->itc)) && 2031 (! MHD_INVALID_PIPE_(daemon->itc)) &&
2032 (1 != MHD_pipe_write_ (daemon->itc, 2032 (! MHD_itc_activate_ (daemon->itc, "n")) )
2033 "n",
2034 1)) )
2035 { 2033 {
2036#ifdef HAVE_MESSAGES 2034#ifdef HAVE_MESSAGES
2037 MHD_DLOG (daemon, 2035 MHD_DLOG (daemon,
@@ -2212,7 +2210,7 @@ MHD_resume_connection (struct MHD_Connection *connection)
2212 connection->resuming = MHD_YES; 2210 connection->resuming = MHD_YES;
2213 daemon->resuming = MHD_YES; 2211 daemon->resuming = MHD_YES;
2214 if ( (! MHD_INVALID_PIPE_(daemon->itc)) && 2212 if ( (! MHD_INVALID_PIPE_(daemon->itc)) &&
2215 (1 != MHD_pipe_write_ (daemon->itc, "r", 1)) ) 2213 (! MHD_itc_activate_ (daemon->itc, "r")) )
2216 { 2214 {
2217#ifdef HAVE_MESSAGES 2215#ifdef HAVE_MESSAGES
2218 MHD_DLOG (daemon, 2216 MHD_DLOG (daemon,
@@ -3792,9 +3790,7 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon)
3792#endif 3790#endif
3793 if (! MHD_INVALID_PIPE_(daemon->worker_pool[i].itc)) 3791 if (! MHD_INVALID_PIPE_(daemon->worker_pool[i].itc))
3794 { 3792 {
3795 if (1 != MHD_pipe_write_ (daemon->worker_pool[i].itc, 3793 if (! MHD_itc_activate_ (daemon->worker_pool[i].itc, "q"))
3796 "q",
3797 1))
3798 MHD_PANIC (_("Failed to signal quiesce via pipe")); 3794 MHD_PANIC (_("Failed to signal quiesce via pipe"));
3799 } 3795 }
3800 } 3796 }
@@ -3815,9 +3811,7 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon)
3815#endif 3811#endif
3816 if (! MHD_INVALID_PIPE_(daemon->itc)) 3812 if (! MHD_INVALID_PIPE_(daemon->itc))
3817 { 3813 {
3818 if (1 != MHD_pipe_write_ (daemon->itc, 3814 if (! MHD_itc_activate_ (daemon->itc, "q"))
3819 "q",
3820 1))
3821 MHD_PANIC (_("failed to signal quiesce via pipe")); 3815 MHD_PANIC (_("failed to signal quiesce via pipe"));
3822 } 3816 }
3823 3817
@@ -5186,7 +5180,7 @@ close_all_connections (struct MHD_Daemon *daemon)
5186#if MHD_WINSOCK_SOCKETS 5180#if MHD_WINSOCK_SOCKETS
5187 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 5181 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
5188 (! MHD_INVALID_PIPE_(daemon->itc)) && 5182 (! MHD_INVALID_PIPE_(daemon->itc)) &&
5189 (1 != MHD_pipe_write_ (daemon->itc, "e", 1)) ) 5183 (! MHD_itc_activate_ (daemon->itc, "e")) )
5190 MHD_PANIC (_("Failed to signal shutdown via pipe")); 5184 MHD_PANIC (_("Failed to signal shutdown via pipe"));
5191#endif 5185#endif
5192 } 5186 }
@@ -5289,7 +5283,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
5289 } 5283 }
5290 if (! MHD_INVALID_PIPE_(daemon->itc)) 5284 if (! MHD_INVALID_PIPE_(daemon->itc))
5291 { 5285 {
5292 if (1 != MHD_pipe_write_ (daemon->itc, "e", 1)) 5286 if (! MHD_itc_activate_ (daemon->itc, "e"))
5293 MHD_PANIC (_("Failed to signal shutdown via pipe")); 5287 MHD_PANIC (_("Failed to signal shutdown via pipe"));
5294 } 5288 }
5295#ifdef HAVE_LISTEN_SHUTDOWN 5289#ifdef HAVE_LISTEN_SHUTDOWN
@@ -5325,9 +5319,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
5325 { 5319 {
5326 if (! MHD_INVALID_PIPE_(daemon->worker_pool[i].itc)) 5320 if (! MHD_INVALID_PIPE_(daemon->worker_pool[i].itc))
5327 { 5321 {
5328 if (1 != MHD_pipe_write_ (daemon->worker_pool[i].itc, 5322 if (! MHD_itc_activate_ (daemon->worker_pool[i].itc, "e"))
5329 "e",
5330 1))
5331 MHD_PANIC (_("Failed to signal shutdown via pipe.")); 5323 MHD_PANIC (_("Failed to signal shutdown via pipe."));
5332 } 5324 }
5333 if (!MHD_join_thread_ (daemon->worker_pool[i].pid)) 5325 if (!MHD_join_thread_ (daemon->worker_pool[i].pid))
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index cfaee781..0545e902 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -62,7 +62,7 @@
62#include "mhd_threads.h" 62#include "mhd_threads.h"
63#include "mhd_locks.h" 63#include "mhd_locks.h"
64#include "mhd_sockets.h" 64#include "mhd_sockets.h"
65#include "mhd_itc.h" 65#include "mhd_itc_types.h"
66 66
67 67
68/** 68/**
diff --git a/src/microhttpd/mhd_itc.c b/src/microhttpd/mhd_itc.c
index 14e474d8..e98c607a 100644
--- a/src/microhttpd/mhd_itc.c
+++ b/src/microhttpd/mhd_itc.c
@@ -33,24 +33,6 @@
33#include "internal.h" 33#include "internal.h"
34 34
35 35
36#ifdef _MHD_ITC_EVENTFD
37
38int
39MHD_pipe_write_ (MHD_itc_ pip,
40 const void *ptr,
41 size_t sz)
42{
43 uint64_t val = 1;
44 if (sizeof (val) !=
45 write (pip,
46 &val,
47 sizeof (val)))
48 MHD_PANIC (_("Failed to write to eventfd\n"));
49 return sz;
50}
51
52#endif /* _MHD_ITC_EVENTFD */
53
54#if defined(_MHD_ITC_PIPE) 36#if defined(_MHD_ITC_PIPE)
55#if !defined(_WIN32) || defined(__CYGWIN__) 37#if !defined(_WIN32) || defined(__CYGWIN__)
56 38
diff --git a/src/microhttpd/mhd_itc.h b/src/microhttpd/mhd_itc.h
index 9f77dcc4..c30fc632 100644
--- a/src/microhttpd/mhd_itc.h
+++ b/src/microhttpd/mhd_itc.h
@@ -32,27 +32,22 @@
32 */ 32 */
33#ifndef MHD_ITC_H 33#ifndef MHD_ITC_H
34#define MHD_ITC_H 1 34#define MHD_ITC_H 1
35#include "mhd_options.h" 35#include "mhd_itc_types.h"
36 36
37/* Force socketpair on native W32 */
38#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(_MHD_ITC_SOCKETPAIR)
39#error _MHD_ITC_SOCKETPAIR is not defined on naitive W32 platform
40#endif /* _WIN32 && !__CYGWIN__ && !_MHD_ITC_SOCKETPAIR */
41
42#ifdef HAVE_UNISTD_H
43#include <unistd.h>
44#endif /* HAVE_UNISTD_H */
45#include <fcntl.h> 37#include <fcntl.h>
46 38
47#if defined(_MHD_ITC_EVENTFD) 39#if defined(_MHD_ITC_EVENTFD)
48#include <sys/eventfd.h>
49 40
50/* **************** Optimized GNU/Linux ITC implementation by eventfd ********** */ 41/* **************** Optimized GNU/Linux ITC implementation by eventfd ********** */
42#include <sys/eventfd.h>
43#include <stdint.h> /* for uint64_t */
44#ifdef HAVE_UNISTD_H
45#include <unistd.h> /* for read(), write(), errno */
46#endif /* HAVE_UNISTD_H */
47#ifdef HAVE_STRING_H
48#include <string.h> /* for strerror() */
49#endif
51 50
52/**
53 * Data type for a MHD ITC.
54 */
55typedef int MHD_itc_;
56 51
57/** 52/**
58 * Initialise ITC by generating eventFD 53 * Initialise ITC by generating eventFD
@@ -67,12 +62,18 @@ typedef int MHD_itc_;
67#define MHD_itc_last_strerror_() strerror(errno) 62#define MHD_itc_last_strerror_() strerror(errno)
68 63
69/** 64/**
70 * write data to real pipe 65 * Internal static const helper for MHD_itc_activate_()
71 */ 66 */
72int 67static const uint64_t _MHD_itc_wr_data = 1;
73MHD_pipe_write_ (MHD_itc_ pip, 68
74 const void *ptr, 69/**
75 size_t sz); 70 * Activate signal on @a itc
71 * @param itc the itc to use
72 * @param str ignored
73 * @return non-zero if succeeded, zero otherwise
74 */
75#define MHD_itc_activate_(itc, str) \
76 ((write((itc), (const void*)&_MHD_itc_wr_data, 8) > 0) || (EAGAIN == errno))
76 77
77#define MHD_pipe_get_read_fd_(pip) (pip) 78#define MHD_pipe_get_read_fd_(pip) (pip)
78 79
@@ -122,18 +123,13 @@ MHD_pipe_write_ (MHD_itc_ pip,
122 123
123/* **************** Standard UNIX ITC implementation by pipe ********** */ 124/* **************** Standard UNIX ITC implementation by pipe ********** */
124 125
125# ifdef HAVE_STRING_H 126#ifdef HAVE_UNISTD_H
126# include <string.h> /* for strerror() */ 127#include <unistd.h> /* for read(), write(), errno */
127# endif 128#endif /* HAVE_UNISTD_H */
129#ifdef HAVE_STRING_H
130#include <string.h> /* for strerror() */
131#endif
128 132
129/**
130 * Data type for a MHD ITC.
131 */
132struct MHD_Itc
133{
134 int fd[2];
135};
136typedef struct MHD_Itc MHD_itc_;
137 133
138/** 134/**
139 * Initialise ITC by generating pipe 135 * Initialise ITC by generating pipe
@@ -148,9 +144,13 @@ typedef struct MHD_Itc MHD_itc_;
148#define MHD_itc_last_strerror_() strerror(errno) 144#define MHD_itc_last_strerror_() strerror(errno)
149 145
150/** 146/**
151 * write data to real pipe 147 * Activate signal on @a itc
148 * @param itc the itc to use
149 * @param str one-symbol string, useful only for strace debug
150 * @return non-zero if succeeded, zero otherwise
152 */ 151 */
153#define MHD_pipe_write_(pip, ptr, sz) write((pip).fd[1], (const void*)(ptr), (sz)) 152#define MHD_itc_activate_(itc, str) \
153 ((write((itc).fd[1], (const void*)(str), 1) > 0) || (EAGAIN == errno))
154 154
155 155
156#define MHD_pipe_get_read_fd_(pip) ((pip).fd[0]) 156#define MHD_pipe_get_read_fd_(pip) ((pip).fd[0])
@@ -205,14 +205,6 @@ MHD_itc_nonblocking_ (MHD_itc_ itc);
205 205
206#include "mhd_sockets.h" 206#include "mhd_sockets.h"
207 207
208/**
209 * Data type for a MHD pipe.
210 */
211struct MHD_Itc
212{
213 MHD_socket sk[2];
214};
215typedef struct MHD_Itc MHD_itc_;
216 208
217/** 209/**
218 * Initialise ITC by generating socketpair 210 * Initialise ITC by generating socketpair
@@ -227,9 +219,14 @@ typedef struct MHD_Itc MHD_itc_;
227#define MHD_itc_last_strerror_() MHD_socket_last_strerr_() 219#define MHD_itc_last_strerror_() MHD_socket_last_strerr_()
228 220
229/** 221/**
230 * Write data to emulated pipe 222 * Activate signal on @a itc
223 * @param itc the itc to use
224 * @param str one-symbol string, useful only for strace debug
225 * @return non-zero if succeeded, zero otherwise
231 */ 226 */
232#define MHD_pipe_write_(pip, ptr, sz) send((pip).sk[1], (const char*)(ptr), (sz), 0) 227#define MHD_itc_activate_(itc, str) \
228 ((send((itc).sk[1], (const char*)(str), 1, 0) > 0) || \
229 (MHD_SCKT_ERR_IS_EAGAIN_(MHD_socket_get_error_())))
233 230
234#define MHD_pipe_get_read_fd_(pip) ((pip).sk[0]) 231#define MHD_pipe_get_read_fd_(pip) ((pip).sk[0])
235 232
diff --git a/src/microhttpd/mhd_itc_types.h b/src/microhttpd/mhd_itc_types.h
new file mode 100644
index 00000000..f91e9383
--- /dev/null
+++ b/src/microhttpd/mhd_itc_types.h
@@ -0,0 +1,83 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2016 Karlson2k (Evgeny Grin), Christian Grothoff
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_types.h
23 * @brief Types for platform-independent inter-thread communication
24 * @author Karlson2k (Evgeny Grin)
25 * @author Christian Grothoff
26 *
27 * Provides basic types for inter-thread communication.
28 * Designed to be included by other headers.
29 */
30#ifndef MHD_ITC_TYPES_H
31#define MHD_ITC_TYPES_H 1
32#include "mhd_options.h"
33
34/* Force socketpair on native W32 */
35#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(_MHD_ITC_SOCKETPAIR)
36#error _MHD_ITC_SOCKETPAIR is not defined on naitive W32 platform
37#endif /* _WIN32 && !__CYGWIN__ && !_MHD_ITC_SOCKETPAIR */
38
39#if defined(_MHD_ITC_EVENTFD)
40/* **************** Optimized GNU/Linux ITC implementation by eventfd ********** */
41
42/**
43 * Data type for a MHD ITC.
44 */
45typedef int MHD_itc_;
46
47#elif defined(_MHD_ITC_PIPE)
48/* **************** Standard UNIX ITC implementation by pipe ********** */
49
50/**
51 * Base data type for a MHD ITC.
52 */
53struct MHD_Itc
54{
55 int fd[2];
56};
57
58/**
59 * Data type for a MHD ITC.
60 */
61typedef struct MHD_Itc MHD_itc_;
62
63#elif defined(_MHD_ITC_SOCKETPAIR)
64/* **************** ITC implementation by socket pair ********** */
65
66#include "mhd_sockets.h"
67
68/**
69 * Base data type for a MHD ITC.
70 */
71struct MHD_Itc
72{
73 MHD_socket sk[2];
74};
75
76/**
77 * Data type for a MHD ITC.
78 */
79typedef struct MHD_Itc MHD_itc_;
80
81#endif /* _MHD_ITC_SOCKETPAIR */
82
83#endif /* ! MHD_ITC_TYPES_H */
diff --git a/w32/common/libmicrohttpd-files.vcxproj b/w32/common/libmicrohttpd-files.vcxproj
index 2a615196..6f1e03bc 100644
--- a/w32/common/libmicrohttpd-files.vcxproj
+++ b/w32/common/libmicrohttpd-files.vcxproj
@@ -42,6 +42,7 @@
42 <ClInclude Include="$(MhdSrc)microhttpd\mhd_locks.h" /> 42 <ClInclude Include="$(MhdSrc)microhttpd\mhd_locks.h" />
43 <ClInclude Include="$(MhdSrc)microhttpd\mhd_sockets.h" /> 43 <ClInclude Include="$(MhdSrc)microhttpd\mhd_sockets.h" />
44 <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc.h" /> 44 <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc.h" />
45 <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc_types.h" />
45 <ClInclude Include="$(MhdSrc)microhttpd\mhd_compat.h" /> 46 <ClInclude Include="$(MhdSrc)microhttpd\mhd_compat.h" />
46 <ClInclude Include="$(MhdW32Common)MHD_config.h" /> 47 <ClInclude Include="$(MhdW32Common)MHD_config.h" />
47 </ItemGroup> 48 </ItemGroup>
diff --git a/w32/common/libmicrohttpd-filters.vcxproj b/w32/common/libmicrohttpd-filters.vcxproj
index 2bb47bfd..d0c47073 100644
--- a/w32/common/libmicrohttpd-filters.vcxproj
+++ b/w32/common/libmicrohttpd-filters.vcxproj
@@ -132,6 +132,9 @@
132 <ClCompile Include="$(MhdSrc)microhttpd\mhd_sockets.c"> 132 <ClCompile Include="$(MhdSrc)microhttpd\mhd_sockets.c">
133 <Filter>Source Files</Filter> 133 <Filter>Source Files</Filter>
134 </ClCompile> 134 </ClCompile>
135 <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc_types.h">
136 <Filter>Source Files</Filter>
137 </ClInclude>
135 <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc.h"> 138 <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc.h">
136 <Filter>Source Files</Filter> 139 <Filter>Source Files</Filter>
137 </ClInclude> 140 </ClInclude>