aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--doc/libmicrohttpd.texi239
-rw-r--r--src/include/microhttpd.h166
-rw-r--r--src/microhttpd/EXPORT.sym2
-rw-r--r--src/microhttpd/connection.c171
-rw-r--r--src/microhttpd/daemon.c614
6 files changed, 717 insertions, 479 deletions
diff --git a/ChangeLog b/ChangeLog
index 21259faa..ae249e8f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
1Thu Oct 24 10:40:03 CEST 2013
2 Adding support for connection flow control via
3 MHD_suspend_connection and MHD_resume_connection. -CG
4
1Sat Oct 19 16:40:32 CEST 2013 5Sat Oct 19 16:40:32 CEST 2013
2 Releasing libmicrohttpd 0.9.31. -CG 6 Releasing libmicrohttpd 0.9.31. -CG
3 7
diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi
index 3ff8c2ac..e18c3014 100644
--- a/doc/libmicrohttpd.texi
+++ b/doc/libmicrohttpd.texi
@@ -63,6 +63,7 @@ Free Documentation License".
63* microhttpd-inspect:: Implementing external @code{select}. 63* microhttpd-inspect:: Implementing external @code{select}.
64* microhttpd-requests:: Handling requests. 64* microhttpd-requests:: Handling requests.
65* microhttpd-responses:: Building responses to requests. 65* microhttpd-responses:: Building responses to requests.
66* microhttpd-flow:: Flow control.
66* microhttpd-dauth:: Utilizing Authentication. 67* microhttpd-dauth:: Utilizing Authentication.
67* microhttpd-post:: Adding a @code{POST} processor. 68* microhttpd-post:: Adding a @code{POST} processor.
68* microhttpd-info:: Obtaining and modifying status information. 69* microhttpd-info:: Obtaining and modifying status information.
@@ -132,7 +133,7 @@ used per connection to avoid resource exhaustion.
132 133
133@section Scope 134@section Scope
134 135
135MHD is currently used in a wide range of implementations. 136MHD is currently used in a wide range of implementations.
136Examples based on reports we've received from developers include: 137Examples based on reports we've received from developers include:
137@itemize 138@itemize
138@item Embedded HTTP server on a cortex M3 (128 KB code space) 139@item Embedded HTTP server on a cortex M3 (128 KB code space)
@@ -148,7 +149,7 @@ Examples based on reports we've received from developers include:
148@cindex select 149@cindex select
149 150
150MHD supports four basic thread modes and up to three event loop 151MHD supports four basic thread modes and up to three event loop
151styes. 152styes.
152 153
153The four basic thread modes are external (MHD creates no threads, 154The four basic thread modes are external (MHD creates no threads,
154event loop is fully managed by the application), internal (MHD creates 155event loop is fully managed by the application), internal (MHD creates
@@ -203,7 +204,7 @@ combinations.
203@item @b{external} @tab yes @tab no @tab yes 204@item @b{external} @tab yes @tab no @tab yes
204@item @b{internal} @tab yes @tab yes @tab yes 205@item @b{internal} @tab yes @tab yes @tab yes
205@item @b{thread pool} @tab yes @tab yes @tab yes 206@item @b{thread pool} @tab yes @tab yes @tab yes
206@item @b{thread-per-connection} @tab yes @tab yes @tab no 207@item @b{thread-per-connection} @tab yes @tab yes @tab no
207@end multitable 208@end multitable
208@caption{Supported combinations of event styles and thread modes.} 209@caption{Supported combinations of event styles and thread modes.}
209@end float 210@end float
@@ -239,7 +240,7 @@ full list of options run ``./configure --help''):
239@item ``--disable-curl'' 240@item ``--disable-curl''
240disable running testcases using libcurl 241disable running testcases using libcurl
241 242
242@item ``--disable-largefile'' 243@item ``--disable-largefile''
243disable support for 64-bit files 244disable support for 64-bit files
244 245
245@item ``--disable-messages'' 246@item ``--disable-messages''
@@ -285,7 +286,7 @@ conditional operations. For possible suggestions consult
285Once you have ensured that you manually (!) included the right headers 286Once you have ensured that you manually (!) included the right headers
286for your platform before "microhttpd.h", you should also add a line 287for your platform before "microhttpd.h", you should also add a line
287with @code{#define MHD_PLATFORM_H} which will prevent the 288with @code{#define MHD_PLATFORM_H} which will prevent the
288"microhttpd.h" header from trying (and, depending on your platform, 289"microhttpd.h" header from trying (and, depending on your platform,
289failing) to include the right headers. 290failing) to include the right headers.
290 291
291If you do not define MHD_PLATFORM_H, the "microhttpd.h" header will 292If you do not define MHD_PLATFORM_H, the "microhttpd.h" header will
@@ -297,12 +298,12 @@ causing problems when porting to other platforms).
297MHD does not install a signal handler for SIGPIPE. On platforms 298MHD does not install a signal handler for SIGPIPE. On platforms
298where this is possible (such as GNU/Linux), it disables SIGPIPE for 299where this is possible (such as GNU/Linux), it disables SIGPIPE for
299its I/O operations (by passing MSG_NOSIGNAL). On other platforms, 300its I/O operations (by passing MSG_NOSIGNAL). On other platforms,
300SIGPIPE signals may be generated from network operations by 301SIGPIPE signals may be generated from network operations by
301MHD and will cause the process to die unless the developer 302MHD and will cause the process to die unless the developer
302explicitly installs a signal handler for SIGPIPE. 303explicitly installs a signal handler for SIGPIPE.
303 304
304Hence portable code using MHD must install a SIGPIPE handler or 305Hence portable code using MHD must install a SIGPIPE handler or
305explicitly block the SIGPIPE signal. MHD does not do so in order 306explicitly block the SIGPIPE signal. MHD does not do so in order
306to avoid messing with other parts of the application that may 307to avoid messing with other parts of the application that may
307need to handle SIGPIPE in a particular way. You can make your application handle SIGPIPE by calling the following function in @code{main}: 308need to handle SIGPIPE in a particular way. You can make your application handle SIGPIPE by calling the following function in @code{main}:
308 309
@@ -422,8 +423,8 @@ No options selected.
422Run in debug mode. If this flag is used, the library should print error 423Run in debug mode. If this flag is used, the library should print error
423messages and warnings to stderr. Note that for this 424messages and warnings to stderr. Note that for this
424run-time option to have any effect, MHD needs to be 425run-time option to have any effect, MHD needs to be
425compiled with messages enabled. This is done by default except you ran 426compiled with messages enabled. This is done by default except you ran
426configure with the @code{--disable-messages} flag set. 427configure with the @code{--disable-messages} flag set.
427 428
428@item MHD_USE_SSL 429@item MHD_USE_SSL
429@cindex TLS 430@cindex TLS
@@ -519,7 +520,7 @@ ability to signal termination via the listen socket). In these modes,
519@code{MHD_quiesce_daemon} will fail if this option was not set. Also, 520@code{MHD_quiesce_daemon} will fail if this option was not set. Also,
520use of this option is automatic (as in, you do not even have to 521use of this option is automatic (as in, you do not even have to
521specify it), if @code{MHD_USE_NO_LISTEN_SOCKET} is specified. In 522specify it), if @code{MHD_USE_NO_LISTEN_SOCKET} is specified. In
522"external" select mode, this option is always simply ignored. 523"external" select mode, this option is always simply ignored.
523 524
524@end table 525@end table
525@end deftp 526@end deftp
@@ -533,7 +534,7 @@ MHD options. Passed in the varargs portion of
533@item MHD_OPTION_END 534@item MHD_OPTION_END
534No more options / last option. This is used to terminate the VARARGs 535No more options / last option. This is used to terminate the VARARGs
535list. 536list.
536 537
537@item MHD_OPTION_CONNECTION_MEMORY_LIMIT 538@item MHD_OPTION_CONNECTION_MEMORY_LIMIT
538@cindex memory, limiting memory utilization 539@cindex memory, limiting memory utilization
539Maximum memory size per connection (followed by a @code{size_t}). The 540Maximum memory size per connection (followed by a @code{size_t}). The
@@ -558,19 +559,19 @@ Maximum number of concurrent connections to accept (followed by an
558@code{unsigned int}). The default is @code{FD_SETSIZE - 4} (the 559@code{unsigned int}). The default is @code{FD_SETSIZE - 4} (the
559maximum number of file descriptors supported by @code{select} minus 560maximum number of file descriptors supported by @code{select} minus
560four for @code{stdin}, @code{stdout}, @code{stderr} and the server 561four for @code{stdin}, @code{stdout}, @code{stderr} and the server
561socket). In other words, the default is as large as possible. 562socket). In other words, the default is as large as possible.
562 563
563Note that if you set a low connection limit, you can easily get into 564Note that if you set a low connection limit, you can easily get into
564trouble with browsers doing request pipelining. For example, if your 565trouble with browsers doing request pipelining. For example, if your
565connection limit is ``1'', a browser may open a first connection to 566connection limit is ``1'', a browser may open a first connection to
566access your ``index.html'' file, keep it open but use a second 567access your ``index.html'' file, keep it open but use a second
567connection to retrieve CSS files, images and the like. In fact, modern 568connection to retrieve CSS files, images and the like. In fact, modern
568browsers are typically by default configured for up to 15 parallel 569browsers are typically by default configured for up to 15 parallel
569connections to a single server. If this happens, MHD will refuse to 570connections to a single server. If this happens, MHD will refuse to
570even accept the second connection until the first connection is 571even accept the second connection until the first connection is
571closed --- which does not happen until timeout. As a result, the 572closed --- which does not happen until timeout. As a result, the
572browser will fail to render the page and seem to hang. If you expect 573browser will fail to render the page and seem to hang. If you expect
573your server to operate close to the connection limit, you should 574your server to operate close to the connection limit, you should
574first consider using a lower timeout value and also possibly add 575first consider using a lower timeout value and also possibly add
575a ``Connection: close'' header to your response to ensure that 576a ``Connection: close'' header to your response to ensure that
576request pipelining is not used and connections are closed immediately 577request pipelining is not used and connections are closed immediately
@@ -613,8 +614,8 @@ from the same IP address.
613@item MHD_OPTION_SOCK_ADDR 614@item MHD_OPTION_SOCK_ADDR
614@cindex bind, restricting bind 615@cindex bind, restricting bind
615Bind daemon to the supplied socket address. This option should be followed by a 616Bind daemon to the supplied socket address. This option should be followed by a
616@code{struct sockaddr *}. If @code{MHD_USE_IPv6} is specified, 617@code{struct sockaddr *}. If @code{MHD_USE_IPv6} is specified,
617the @code{struct sockaddr*} should point to a @code{struct sockaddr_in6}, 618the @code{struct sockaddr*} should point to a @code{struct sockaddr_in6},
618otherwise to a @code{struct sockaddr_in}. If this option is not specified, 619otherwise to a @code{struct sockaddr_in}. If this option is not specified,
619the daemon will listen to incoming connections from anywhere. If you use this 620the daemon will listen to incoming connections from anywhere. If you use this
620option, the 'port' argument from @code{MHD_start_daemon} is ignored and the port 621option, the 'port' argument from @code{MHD_start_daemon} is ignored and the port
@@ -655,7 +656,7 @@ Memory pointer to the private key to be used by the
655HTTPS daemon. This option should be followed by an 656HTTPS daemon. This option should be followed by an
656"const char*" argument. 657"const char*" argument.
657This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_CERT'. 658This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_CERT'.
658 659
659@item MHD_OPTION_HTTPS_MEM_CERT 660@item MHD_OPTION_HTTPS_MEM_CERT
660@cindex SSL 661@cindex SSL
661@cindex TLS 662@cindex TLS
@@ -663,7 +664,7 @@ Memory pointer to the certificate to be used by the
663HTTPS daemon. This option should be followed by an 664HTTPS daemon. This option should be followed by an
664"const char*" argument. 665"const char*" argument.
665This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_KEY'. 666This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_KEY'.
666 667
667@item MHD_OPTION_HTTPS_MEM_TRUST 668@item MHD_OPTION_HTTPS_MEM_TRUST
668@cindex SSL 669@cindex SSL
669@cindex TLS 670@cindex TLS
@@ -677,14 +678,14 @@ of the certificate if needed.
677Note that most browsers will only present a client certificate 678Note that most browsers will only present a client certificate
678only if they have one matching the specified CA, not sending 679only if they have one matching the specified CA, not sending
679any certificate otherwise. 680any certificate otherwise.
680 681
681@item MHD_OPTION_HTTPS_CRED_TYPE 682@item MHD_OPTION_HTTPS_CRED_TYPE
682@cindex SSL 683@cindex SSL
683@cindex TLS 684@cindex TLS
684Daemon credentials type. Either certificate or anonymous, 685Daemon credentials type. Either certificate or anonymous,
685this option should be followed by one of the values listed in 686this option should be followed by one of the values listed in
686"enum gnutls_credentials_type_t". 687"enum gnutls_credentials_type_t".
687 688
688@item MHD_OPTION_HTTPS_PRIORITIES 689@item MHD_OPTION_HTTPS_PRIORITIES
689@cindex SSL 690@cindex SSL
690@cindex TLS 691@cindex TLS
@@ -706,7 +707,7 @@ type "size_t" which specifies the size of the buffer pointed to by the
706second argument in bytes. Note that the application must ensure that 707second argument in bytes. Note that the application must ensure that
707the buffer of the second argument remains allocated and unmodified 708the buffer of the second argument remains allocated and unmodified
708while the daemon is running. For security, you SHOULD provide a fresh 709while the daemon is running. For security, you SHOULD provide a fresh
709random nonce when using MHD with Digest Authentication. 710random nonce when using MHD with Digest Authentication.
710 711
711@item MHD_OPTION_NONCE_NC_SIZE 712@item MHD_OPTION_NONCE_NC_SIZE
712@cindex digest auth 713@cindex digest auth
@@ -737,7 +738,7 @@ Listen socket to use. Pass a listen socket for MHD to use
737(systemd-style). If this option is used, MHD will not open its own 738(systemd-style). If this option is used, MHD will not open its own
738listen socket(s). The argument passed must be of type "int" and refer 739listen socket(s). The argument passed must be of type "int" and refer
739to an existing socket that has been bound to a port and is listening. 740to an existing socket that has been bound to a port and is listening.
740 741
741@item MHD_OPTION_EXTERNAL_LOGGER 742@item MHD_OPTION_EXTERNAL_LOGGER
742@cindex logging 743@cindex logging
743Use the given function for logging error messages. 744Use the given function for logging error messages.
@@ -746,10 +747,10 @@ first must be a pointer to a function
746of type 'void fun(void * arg, const char * fmt, va_list ap)' 747of type 'void fun(void * arg, const char * fmt, va_list ap)'
747and the second a pointer of type 'void*' which will 748and the second a pointer of type 'void*' which will
748be passed as the "arg" argument to "fun". 749be passed as the "arg" argument to "fun".
749 750
750Note that MHD will not generate any log messages without 751Note that MHD will not generate any log messages without
751the MHD_USE_DEBUG flag set and if MHD was compiled 752the MHD_USE_DEBUG flag set and if MHD was compiled
752with the "--disable-messages" flag. 753with the "--disable-messages" flag.
753 754
754@item MHD_OPTION_THREAD_POOL_SIZE 755@item MHD_OPTION_THREAD_POOL_SIZE
755@cindex performance 756@cindex performance
@@ -806,7 +807,7 @@ updated. Note that the unescape function must not lengthen @code{s}
806@code{cls} will be set to the second argument following 807@code{cls} will be set to the second argument following
807MHD_OPTION_UNESCAPE_CALLBACK. 808MHD_OPTION_UNESCAPE_CALLBACK.
808 809
809 810
810@item MHD_OPTION_THREAD_STACK_SIZE 811@item MHD_OPTION_THREAD_STACK_SIZE
811@cindex stack 812@cindex stack
812@cindex thread 813@cindex thread
@@ -814,7 +815,7 @@ MHD_OPTION_UNESCAPE_CALLBACK.
814@cindex embedded systems 815@cindex embedded systems
815Maximum stack size for threads created by MHD. This option must be 816Maximum stack size for threads created by MHD. This option must be
816followed by a @code{size_t}). Not specifying this option or using 817followed by a @code{size_t}). Not specifying this option or using
817a value of zero means using the system default (which is likely to 818a value of zero means using the system default (which is likely to
818differ based on your platform). 819differ based on your platform).
819 820
820@end table 821@end table
@@ -823,7 +824,7 @@ differ based on your platform).
823 824
824@deftp {C Struct} MHD_OptionItem 825@deftp {C Struct} MHD_OptionItem
825Entry in an MHD_OPTION_ARRAY. See the @code{MHD_OPTION_ARRAY} option 826Entry in an MHD_OPTION_ARRAY. See the @code{MHD_OPTION_ARRAY} option
826argument for its use. 827argument for its use.
827 828
828The @code{option} member is used to specify which option is specified 829The @code{option} member is used to specify which option is specified
829in the array. The other members specify the respective argument. 830in the array. The other members specify the respective argument.
@@ -895,7 +896,7 @@ We had to close the session since MHD was being shut down.
895 896
896@deftp {Enumeration} MHD_ResponseMemoryMode 897@deftp {Enumeration} MHD_ResponseMemoryMode
897The @code{MHD_ResponeMemoryMode} specifies how MHD should treat 898The @code{MHD_ResponeMemoryMode} specifies how MHD should treat
898the memory buffer given for the response in 899the memory buffer given for the response in
899@code{MHD_create_response_from_buffer}. 900@code{MHD_create_response_from_buffer}.
900 901
901@table @code 902@table @code
@@ -903,12 +904,12 @@ the memory buffer given for the response in
903Buffer is a persistent (static/global) buffer that won't change 904Buffer is a persistent (static/global) buffer that won't change
904for at least the lifetime of the response, MHD should just use 905for at least the lifetime of the response, MHD should just use
905it, not free it, not copy it, just keep an alias to it. 906it, not free it, not copy it, just keep an alias to it.
906 907
907@item MHD_RESPMEM_MUST_FREE 908@item MHD_RESPMEM_MUST_FREE
908Buffer is heap-allocated with @code{malloc} (or equivalent) and 909Buffer is heap-allocated with @code{malloc} (or equivalent) and
909should be freed by MHD after processing the response has 910should be freed by MHD after processing the response has
910concluded (response reference counter reaches zero). 911concluded (response reference counter reaches zero).
911 912
912@item MHD_RESPMEM_MUST_COPY 913@item MHD_RESPMEM_MUST_COPY
913Buffer is in transient memory, but not on the heap (for example, 914Buffer is in transient memory, but not on the heap (for example,
914on the stack or non-malloc allocated) and only valid during the 915on the stack or non-malloc allocated) and only valid during the
@@ -1094,13 +1095,9 @@ Callback used by MHD in order to obtain content. The callback has to
1094copy at most @var{max} bytes of content into @var{buf}. The total 1095copy at most @var{max} bytes of content into @var{buf}. The total
1095number of bytes that has been placed into @var{buf} should be returned. 1096number of bytes that has been placed into @var{buf} should be returned.
1096 1097
1097Note that returning zero will cause MHD to try again, either 1098Note that returning zero will cause MHD to try again.
1098``immediately'' if in multi-threaded mode (in which case the callback 1099Thus, returning zero should only be used in conjunction
1099may want to do blocking operations to avoid busy waiting) or in the 1100with @code{MHD_suspend_connection()} to avoid busy waiting.
1100next round if @code{MHD_run} is used. Returning zero for a daemon
1101that runs in internal @code{select}-mode is an error (since it
1102would result in busy waiting) and cause the program to be aborted
1103(@code{abort()}).
1104 1101
1105While usually the callback simply returns the number of bytes written 1102While usually the callback simply returns the number of bytes written
1106into @var{buf}, there are two special return value: 1103into @var{buf}, there are two special return value:
@@ -1108,7 +1105,7 @@ into @var{buf}, there are two special return value:
1108@code{MHD_CONTENT_READER_END_OF_STREAM} (-1) should be returned 1105@code{MHD_CONTENT_READER_END_OF_STREAM} (-1) should be returned
1109for the regular end of transmission (with chunked encoding, MHD will then 1106for the regular end of transmission (with chunked encoding, MHD will then
1110terminate the chunk and send any HTTP footers that might be 1107terminate the chunk and send any HTTP footers that might be
1111present; without chunked encoding and given an unknown 1108present; without chunked encoding and given an unknown
1112response size, MHD will simply close the connection; note 1109response size, MHD will simply close the connection; note
1113that while returning @code{MHD_CONTENT_READER_END_OF_STREAM} is not technically 1110that while returning @code{MHD_CONTENT_READER_END_OF_STREAM} is not technically
1114legal if a response size was specified, MHD accepts this 1111legal if a response size was specified, MHD accepts this
@@ -1121,7 +1118,7 @@ given or if chunked encoding is in use, this will indicate
1121an error to the client. Note, however, that if the client 1118an error to the client. Note, however, that if the client
1122does not know a response size and chunked encoding is not in 1119does not know a response size and chunked encoding is not in
1123use, then clients will not be able to tell the difference between 1120use, then clients will not be able to tell the difference between
1124@code{MHD_CONTENT_READER_END_WITH_ERROR} and 1121@code{MHD_CONTENT_READER_END_WITH_ERROR} and
1125@code{MHD_CONTENT_READER_END_OF_STREAM}. 1122@code{MHD_CONTENT_READER_END_OF_STREAM}.
1126This is not a limitation of MHD but rather of the HTTP protocol. 1123This is not a limitation of MHD but rather of the HTTP protocol.
1127 1124
@@ -1198,7 +1195,7 @@ iteration.
1198Set a handler for fatal errors. 1195Set a handler for fatal errors.
1199 1196
1200@table @var 1197@table @var
1201@item cb 1198@item cb
1202function to call if MHD encounters a fatal internal error. If no handler was set explicitly, MHD will call @code{abort}. 1199function to call if MHD encounters a fatal internal error. If no handler was set explicitly, MHD will call @code{abort}.
1203 1200
1204@item cls 1201@item cls
@@ -1252,7 +1249,7 @@ is still using it).
1252 1249
1253This function is useful in the special case that a listen socket 1250This function is useful in the special case that a listen socket
1254is to be migrated to another process (i.e. a newer version of the 1251is to be migrated to another process (i.e. a newer version of the
1255HTTP server) while existing connections should continue to be 1252HTTP server) while existing connections should continue to be
1256processed until they are finished. 1253processed until they are finished.
1257 1254
1258Return @code{-1} on error (daemon not listening), the handle to the 1255Return @code{-1} on error (daemon not listening), the handle to the
@@ -1278,7 +1275,7 @@ However, if using external @code{select} mode, you may want to
1278instead use @code{MHD_run_from_select}, as it is more efficient. 1275instead use @code{MHD_run_from_select}, as it is more efficient.
1279 1276
1280@table @var 1277@table @var
1281@item daemon 1278@item daemon
1282daemon to process connections of 1279daemon to process connections of
1283@end table 1280@end table
1284 1281
@@ -1291,7 +1288,7 @@ started with the right options for this call.
1291Run webserver operations given sets of ready socket handles. 1288Run webserver operations given sets of ready socket handles.
1292@cindex select 1289@cindex select
1293 1290
1294This method should be called by clients in combination with 1291This method should be called by clients in combination with
1295@code{MHD_get_fdset} if the client-controlled (external) 1292@code{MHD_get_fdset} if the client-controlled (external)
1296select method is used. 1293select method is used.
1297 1294
@@ -1303,7 +1300,7 @@ not have to call @code{select} again to determine which operations are
1303ready. 1300ready.
1304 1301
1305@table @var 1302@table @var
1306@item daemon 1303@item daemon
1307daemon to process connections of 1304daemon to process connections of
1308@item read_fd_set 1305@item read_fd_set
1309set of descriptors that must be ready for reading without blocking 1306set of descriptors that must be ready for reading without blocking
@@ -1321,11 +1318,11 @@ errors.
1321 1318
1322 1319
1323@deftypefun void MHD_add_connection (struct MHD_Daemon *daemon, int client_socket, const struct sockaddr *addr, socklen_t addrlen) 1320@deftypefun void MHD_add_connection (struct MHD_Daemon *daemon, int client_socket, const struct sockaddr *addr, socklen_t addrlen)
1324Add another client connection to the set of connections 1321Add another client connection to the set of connections
1325managed by MHD. This API is usually not needed (since 1322managed by MHD. This API is usually not needed (since
1326MHD will accept inbound connections on the server socket). 1323MHD will accept inbound connections on the server socket).
1327Use this API in special cases, for example if your HTTP 1324Use this API in special cases, for example if your HTTP
1328server is behind NAT and needs to connect out to the 1325server is behind NAT and needs to connect out to the
1329HTTP client, or if you are building a proxy. 1326HTTP client, or if you are building a proxy.
1330 1327
1331If you use this API in conjunction with a internal select or a thread 1328If you use this API in conjunction with a internal select or a thread
@@ -1338,17 +1335,17 @@ this call and must no longer be used directly by the application
1338afterwards. 1335afterwards.
1339 1336
1340@table @var 1337@table @var
1341@item daemon 1338@item daemon
1342daemon that manages the connection 1339daemon that manages the connection
1343@item client_socket 1340@item client_socket
1344socket to manage (MHD will expect to receive an HTTP request from this socket next). 1341socket to manage (MHD will expect to receive an HTTP request from this socket next).
1345@item addr 1342@item addr
1346IP address of the client 1343IP address of the client
1347@item addrlen 1344@item addrlen
1348number of bytes in addr 1345number of bytes in addr
1349@end table 1346@end table
1350 1347
1351This function will return @code{MHD_YES} on success, 1348This function will return @code{MHD_YES} on success,
1352@code{MHD_NO} if this daemon could 1349@code{MHD_NO} if this daemon could
1353not handle the connection (i.e. malloc failed, etc). 1350not handle the connection (i.e. malloc failed, etc).
1354The socket will be closed in any case; 'errno' is set 1351The socket will be closed in any case; 'errno' is set
@@ -1387,7 +1384,7 @@ connection timeout is used). The returned value is how long
1387@code{select} should at most block, not the timeout value set for 1384@code{select} should at most block, not the timeout value set for
1388connections. This function must not be called if the 1385connections. This function must not be called if the
1389@code{MHD_USE_THREAD_PER_CONNECTION} mode is in use (since then it 1386@code{MHD_USE_THREAD_PER_CONNECTION} mode is in use (since then it
1390is not meaningful to ask for a timeout, after all, there is 1387is not meaningful to ask for a timeout, after all, there is
1391concurrenct activity). The function must also not be called by 1388concurrenct activity). The function must also not be called by
1392user-code if @code{MHD_USE_INTERNAL_SELECT} is in use. In the latter 1389user-code if @code{MHD_USE_INTERNAL_SELECT} is in use. In the latter
1393case, the behavior is undefined. 1390case, the behavior is undefined.
@@ -1411,7 +1408,7 @@ right now).
1411 1408
1412 1409
1413@deftypefun int MHD_get_connection_values (struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls) 1410@deftypefun int MHD_get_connection_values (struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls)
1414Get all the headers matching @var{kind} from the request. 1411Get all the headers matching @var{kind} from the request.
1415 1412
1416The @var{iterator} callback is invoked once for each header, with 1413The @var{iterator} callback is invoked once for each header, with
1417@var{iterator_cls} as first argument. After version 0.9.19, the 1414@var{iterator_cls} as first argument. After version 0.9.19, the
@@ -1439,9 +1436,9 @@ would contain the string ``key''.
1439 1436
1440@deftypefun int MHD_set_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char * key, const char * value) 1437@deftypefun int MHD_set_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char * key, const char * value)
1441This function can be used to append an entry to 1438This function can be used to append an entry to
1442the list of HTTP headers of a connection (so that the 1439the list of HTTP headers of a connection (so that the
1443@code{MHD_get_connection_values function} will return 1440@code{MHD_get_connection_values function} will return
1444them -- and the MHD PostProcessor will also 1441them -- and the MHD PostProcessor will also
1445see them). This maybe required in certain 1442see them). This maybe required in certain
1446situations (see Mantis #1399) where (broken) 1443situations (see Mantis #1399) where (broken)
1447HTTP implementations fail to supply values needed 1444HTTP implementations fail to supply values needed
@@ -1457,11 +1454,11 @@ are NOT freed until the connection is closed.
1457(The easiest way to do this is by passing only 1454(The easiest way to do this is by passing only
1458arguments to permanently allocated strings.). 1455arguments to permanently allocated strings.).
1459 1456
1460@var{connection} is the connection for which 1457@var{connection} is the connection for which
1461the entry for @var{key} of the given @var{kind} 1458the entry for @var{key} of the given @var{kind}
1462should be set to the given @var{value}. 1459should be set to the given @var{value}.
1463 1460
1464The function returns @code{MHD_NO} if the operation 1461The function returns @code{MHD_NO} if the operation
1465could not be performed due to insufficient memory 1462could not be performed due to insufficient memory
1466and @code{MHD_YES} on success. 1463and @code{MHD_YES} on success.
1467@end deftypefun 1464@end deftypefun
@@ -1636,8 +1633,8 @@ size of the file)
1636 1633
1637@item fd 1634@item fd
1638file descriptor referring to a file on disk with the data; will be 1635file descriptor referring to a file on disk with the data; will be
1639closed when response is destroyed; note that 'fd' must be an actual 1636closed when response is destroyed; note that 'fd' must be an actual
1640file descriptor (not a pipe or socket) since MHD might use 'sendfile' 1637file descriptor (not a pipe or socket) since MHD might use 'sendfile'
1641or 'seek' on it. The descriptor should be in blocking-IO mode. 1638or 'seek' on it. The descriptor should be in blocking-IO mode.
1642@end table 1639@end table
1643 1640
@@ -1678,8 +1675,8 @@ file starting at offset).
1678 1675
1679@item fd 1676@item fd
1680file descriptor referring to a file on disk with the data; will be 1677file descriptor referring to a file on disk with the data; will be
1681closed when response is destroyed; note that 'fd' must be an actual 1678closed when response is destroyed; note that 'fd' must be an actual
1682file descriptor (not a pipe or socket) since MHD might use 'sendfile' 1679file descriptor (not a pipe or socket) since MHD might use 'sendfile'
1683or 'seek' on it. The descriptor should be in blocking-IO mode. 1680or 'seek' on it. The descriptor should be in blocking-IO mode.
1684 1681
1685@item offset 1682@item offset
@@ -1701,8 +1698,8 @@ size of the data portion of the response;
1701@item buffer 1698@item buffer
1702the data itself; 1699the data itself;
1703 1700
1704@item mode 1701@item mode
1705memory management options for buffer; use 1702memory management options for buffer; use
1706MHD_RESPMEM_PERSISTENT if the buffer is static/global memory, 1703MHD_RESPMEM_PERSISTENT if the buffer is static/global memory,
1707use MHD_RESPMEM_MUST_FREE if the buffer is heap-allocated and 1704use MHD_RESPMEM_MUST_FREE if the buffer is heap-allocated and
1708should be freed by MHD and MHD_RESPMEM_MUST_COPY if the 1705should be freed by MHD and MHD_RESPMEM_MUST_COPY if the
@@ -1779,7 +1776,7 @@ memory allocation error).
1779@deftypefun int MHD_add_response_footer (struct MHD_Response *response, const char *footer, const char *content) 1776@deftypefun int MHD_add_response_footer (struct MHD_Response *response, const char *footer, const char *content)
1780Add a footer line to the response. The strings referenced by 1777Add a footer line to the response. The strings referenced by
1781@var{footer} and @var{content} must be zero-terminated and they are 1778@var{footer} and @var{content} must be zero-terminated and they are
1782duplicated into memory blocks embedded in @var{response}. 1779duplicated into memory blocks embedded in @var{response}.
1783 1780
1784Notice that the strings must not hold newlines, carriage returns or tab 1781Notice that the strings must not hold newlines, carriage returns or tab
1785chars. You can add response footers at any time before signalling the 1782chars. You can add response footers at any time before signalling the
@@ -1833,6 +1830,72 @@ We should not modify the value, unless we know what we are doing.
1833@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1830@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1834 1831
1835@c ------------------------------------------------------------ 1832@c ------------------------------------------------------------
1833@node microhttpd-flow
1834@chapter Flow control.
1835
1836@noindent
1837Sometimes it may be possible that clients upload data faster
1838than an application can process it, or that an application
1839needs an extended period of time to generate a response.
1840If @code{MHD_USE_THREAD_PER_CONNECTION} is used, applications
1841can simply deal with this by performing their logic within the
1842thread and thus effectively blocking connection processing
1843by MHD. In all other modes, blocking logic must not be
1844placed within the callbacks invoked by MHD as this would also
1845block processing of other requests, as a single thread may be
1846responsible for tens of thousands of connections.
1847
1848Instead, applications using thread modes other than
1849@code{MHD_USE_THREAD_PER_CONNECTION} should use the
1850following functions to perform flow control.
1851
1852@deftypefun int MHD_suspend_connection (struct MHD_Connection *connection)
1853Suspend handling of network data for a given connection. This can
1854be used to dequeue a connection from MHD's event loop (external
1855select, internal select or thread pool; not applicable to
1856thread-per-connection!) for a while.
1857
1858If you use this API in conjunction with a internal select or a
1859thread pool, you must set the option @code{MHD_USE_PIPE_FOR_SHUTDOWN} to
1860ensure that a resumed connection is immediately processed by MHD.
1861
1862Suspended connections continue to count against the total number of
1863connections allowed (per daemon, as well as per IP, if such limits
1864are set). Suspended connections will NOT time out; timeouts will
1865restart when the connection handling is resumed. While a
1866connection is suspended, MHD will not detect disconnects by the
1867client.
1868
1869The only safe time to suspend a connection is from the
1870@code{MHD_AccessHandlerCallback}.
1871
1872Finally, it is an API violation to call @code{MHD_stop_daemon} while
1873having suspended connections (this will at least create memory and
1874socket leaks or lead to undefined behavior). You must explicitly
1875resume all connections before stopping the daemon.
1876
1877@table @var
1878@item connection
1879the connection to suspend
1880@end table
1881@end deftypefun
1882
1883@deftypefun int MHD_resume_connection (struct MHD_Connection *connection)
1884Resume handling of network data for suspended connection. It is safe
1885to resume a suspended connection at any time. Calling this function
1886on a connection that was not previously suspended will result in
1887undefined behavior.
1888
1889@table @var
1890@item connection
1891the connection to resume
1892@end table
1893@end deftypefun
1894
1895
1896@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1897
1898@c ------------------------------------------------------------
1836@node microhttpd-dauth 1899@node microhttpd-dauth
1837@chapter Utilizing Authentication 1900@chapter Utilizing Authentication
1838 1901
@@ -1960,41 +2023,41 @@ ahc_echo (void *cls,
1960 int ret; 2023 int ret;
1961 2024
1962 username = MHD_digest_auth_get_username(connection); 2025 username = MHD_digest_auth_get_username(connection);
1963 if (username == NULL) 2026 if (username == NULL)
1964 @{ 2027 @{
1965 response = MHD_create_response_from_buffer(strlen (DENIED), 2028 response = MHD_create_response_from_buffer(strlen (DENIED),
1966 DENIED, 2029 DENIED,
1967 MHD_RESPMEM_PERSISTENT); 2030 MHD_RESPMEM_PERSISTENT);
1968 ret = MHD_queue_auth_fail_response(connection, realm, 2031 ret = MHD_queue_auth_fail_response(connection, realm,
1969 OPAQUE, 2032 OPAQUE,
1970 response, 2033 response,
1971 MHD_NO); 2034 MHD_NO);
1972 MHD_destroy_response(response); 2035 MHD_destroy_response(response);
1973 return ret; 2036 return ret;
1974 @} 2037 @}
1975 ret = MHD_digest_auth_check(connection, realm, 2038 ret = MHD_digest_auth_check(connection, realm,
1976 username, 2039 username,
1977 password, 2040 password,
1978 300); 2041 300);
1979 free(username); 2042 free(username);
1980 if ( (ret == MHD_INVALID_NONCE) || 2043 if ( (ret == MHD_INVALID_NONCE) ||
1981 (ret == MHD_NO) ) 2044 (ret == MHD_NO) )
1982 @{ 2045 @{
1983 response = MHD_create_response_from_buffer(strlen (DENIED), 2046 response = MHD_create_response_from_buffer(strlen (DENIED),
1984 DENIED, 2047 DENIED,
1985 MHD_RESPMEM_PERSISTENT); 2048 MHD_RESPMEM_PERSISTENT);
1986 if (NULL == response) 2049 if (NULL == response)
1987 return MHD_NO; 2050 return MHD_NO;
1988 ret = MHD_queue_auth_fail_response(connection, realm, 2051 ret = MHD_queue_auth_fail_response(connection, realm,
1989 OPAQUE, 2052 OPAQUE,
1990 response, 2053 response,
1991 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO); 2054 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);
1992 MHD_destroy_response(response); 2055 MHD_destroy_response(response);
1993 return ret; 2056 return ret;
1994 @} 2057 @}
1995 response = MHD_create_response_from_buffer (strlen(PAGE), PAGE, 2058 response = MHD_create_response_from_buffer (strlen(PAGE), PAGE,
1996 MHD_RESPMEM_PERSISTENT); 2059 MHD_RESPMEM_PERSISTENT);
1997 ret = MHD_queue_response(connection, MHD_HTTP_OK, response); 2060 ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
1998 MHD_destroy_response(response); 2061 MHD_destroy_response(response);
1999 return ret; 2062 return ret;
2000@} 2063@}
@@ -2026,7 +2089,7 @@ its @code{*@var{con_cls}} argument is set to @code{NULL}. When @code{POST}
2026data comes in the upload buffer it is @strong{mandatory} to use the 2089data comes in the upload buffer it is @strong{mandatory} to use the
2027@var{con_cls} to store a reference to per-connection data. The fact 2090@var{con_cls} to store a reference to per-connection data. The fact
2028that the pointer was initially @code{NULL} can be used to detect that 2091that the pointer was initially @code{NULL} can be used to detect that
2029this is a new request. 2092this is a new request.
2030 2093
2031One method to detect that a new connection was established is 2094One method to detect that a new connection was established is
2032to set @code{*con_cls} to an unused integer: 2095to set @code{*con_cls} to an unused integer:
@@ -2043,7 +2106,7 @@ access_handler (void *cls,
2043 static int old_connection_marker; 2106 static int old_connection_marker;
2044 int new_connection = (NULL == *con_cls); 2107 int new_connection = (NULL == *con_cls);
2045 2108
2046 if (new_connection) 2109 if (new_connection)
2047 @{ 2110 @{
2048 /* new connection with POST */ 2111 /* new connection with POST */
2049 *con_cls = &old_connection_marker; 2112 *con_cls = &old_connection_marker;
@@ -2070,13 +2133,13 @@ access_handler (void *cls,
2070@{ 2133@{
2071 struct MHD_PostProcessor * pp = *con_cls; 2134 struct MHD_PostProcessor * pp = *con_cls;
2072 2135
2073 if (pp == NULL) 2136 if (pp == NULL)
2074 @{ 2137 @{
2075 pp = MHD_create_post_processor(connection, ...); 2138 pp = MHD_create_post_processor(connection, ...);
2076 *con_cls = pp; 2139 *con_cls = pp;
2077 return MHD_YES; 2140 return MHD_YES;
2078 @} 2141 @}
2079 if (*upload_data_size) 2142 if (*upload_data_size)
2080 @{ 2143 @{
2081 MHD_post_process(pp, upload_data, *upload_data_size); 2144 MHD_post_process(pp, upload_data, *upload_data_size);
2082 *upload_data_size = 0; 2145 *upload_data_size = 0;
@@ -2161,7 +2224,7 @@ is no special call to the iterator to indicate the end of the post processing
2161stream. After destroying the PostProcessor, the programmer should 2224stream. After destroying the PostProcessor, the programmer should
2162perform any necessary work to complete the processing of the iterator. 2225perform any necessary work to complete the processing of the iterator.
2163 2226
2164Return @code{MHD_YES} if processing completed nicely, @code{MHD_NO} 2227Return @code{MHD_YES} if processing completed nicely, @code{MHD_NO}
2165if there were spurious characters or formatting problems with 2228if there were spurious characters or formatting problems with
2166the post request. It is common to ignore the return value 2229the post request. It is common to ignore the return value
2167of this function. 2230of this function.
@@ -2285,7 +2348,7 @@ connection is desired.
2285@table @code 2348@table @code
2286 2349
2287@item MHD_CONNECTION_INFO_CIPHER_ALGO 2350@item MHD_CONNECTION_INFO_CIPHER_ALGO
2288What cipher algorithm is being used (HTTPS connections only). 2351What cipher algorithm is being used (HTTPS connections only).
2289Takes no extra arguments. 2352Takes no extra arguments.
2290@code{NULL} is returned for non-HTTPS connections. 2353@code{NULL} is returned for non-HTTPS connections.
2291 2354
@@ -2295,7 +2358,7 @@ Takes no extra arguments. Allows finding out the TLS/SSL protocol used
2295@code{NULL} is returned for non-HTTPS connections. 2358@code{NULL} is returned for non-HTTPS connections.
2296 2359
2297@item MHD_CONNECTION_INFO_CLIENT_ADDRESS 2360@item MHD_CONNECTION_INFO_CLIENT_ADDRESS
2298Returns information about the address of the client. Returns 2361Returns information about the address of the client. Returns
2299essentially a @code{struct sockaddr **} (since the API returns 2362essentially a @code{struct sockaddr **} (since the API returns
2300a @code{union MHD_ConnectionInfo *} and that union contains 2363a @code{union MHD_ConnectionInfo *} and that union contains
2301a @code{struct sockaddr *}). 2364a @code{struct sockaddr *}).
@@ -2303,7 +2366,7 @@ a @code{struct sockaddr *}).
2303@item MHD_CONNECTION_INFO_GNUTLS_SESSION, 2366@item MHD_CONNECTION_INFO_GNUTLS_SESSION,
2304Takes no extra arguments. Allows access to the underlying GNUtls session, 2367Takes no extra arguments. Allows access to the underlying GNUtls session,
2305including access to the underlying GNUtls client certificate 2368including access to the underlying GNUtls client certificate
2306(HTTPS connections only). Takes no extra arguments. 2369(HTTPS connections only). Takes no extra arguments.
2307@code{NULL} is returned for non-HTTPS connections. 2370@code{NULL} is returned for non-HTTPS connections.
2308 2371
2309@item MHD_CONNECTION_INFO_GNUTLS_CLIENT_CERT, 2372@item MHD_CONNECTION_INFO_GNUTLS_CLIENT_CERT,
@@ -2367,7 +2430,7 @@ connection should be changed.
2367@item MHD_CONNECTION_OPTION_TIMEOUT 2430@item MHD_CONNECTION_OPTION_TIMEOUT
2368Set a custom timeout for the given connection. Specified 2431Set a custom timeout for the given connection. Specified
2369as the number of seconds, given as an @code{unsigned int}. Use 2432as the number of seconds, given as an @code{unsigned int}. Use
2370zero for no timeout. 2433zero for no timeout.
2371 2434
2372@end table 2435@end table
2373@end deftp 2436@end deftp
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index c6828aa9..96dc2f27 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -42,7 +42,7 @@
42 * 42 *
43 * MHD understands POST data and is able to decode certain formats 43 * MHD understands POST data and is able to decode certain formats
44 * (at the moment only "application/x-www-form-urlencoded" and 44 * (at the moment only "application/x-www-form-urlencoded" and
45 * "mulitpart/formdata"). Unsupported encodings and large POST 45 * "mulitpart/formdata"). Unsupported encodings and large POST
46 * submissions may require the application to manually process 46 * submissions may require the application to manually process
47 * the stream, which is provided to the main application (and thus can be 47 * the stream, which is provided to the main application (and thus can be
48 * processed, just not conveniently by MHD). 48 * processed, just not conveniently by MHD).
@@ -99,7 +99,7 @@ extern "C"
99 hence works on any platform, we use "standard" includes here 99 hence works on any platform, we use "standard" includes here
100 to build out-of-the-box for beginning users on common systems. 100 to build out-of-the-box for beginning users on common systems.
101 101
102 Once you have a proper build system and go for more exotic 102 Once you have a proper build system and go for more exotic
103 platforms, you should define MHD_PLATFORM_H in some header that 103 platforms, you should define MHD_PLATFORM_H in some header that
104 you always include *before* "microhttpd.h". Then the following 104 you always include *before* "microhttpd.h". Then the following
105 "standard" includes won't be used (which might be a good 105 "standard" includes won't be used (which might be a good
@@ -121,7 +121,7 @@ extern "C"
121 * Current version of the library. 121 * Current version of the library.
122 * 0x01093001 = 1.9.30-1. 122 * 0x01093001 = 1.9.30-1.
123 */ 123 */
124#define MHD_VERSION 0x00093100 124#define MHD_VERSION 0x00093101
125 125
126/** 126/**
127 * MHD-internal return code for "YES". 127 * MHD-internal return code for "YES".
@@ -254,7 +254,7 @@ extern "C"
254 * SHOUTcast. This will cause the response to begin 254 * SHOUTcast. This will cause the response to begin
255 * with the SHOUTcast "ICY" line instad of "HTTP". 255 * with the SHOUTcast "ICY" line instad of "HTTP".
256 * @ingroup specialized 256 * @ingroup specialized
257 */ 257 */
258#define MHD_ICY_FLAG ((uint32_t)(1 << 31)) 258#define MHD_ICY_FLAG ((uint32_t)(1 << 31))
259 259
260/** 260/**
@@ -319,7 +319,7 @@ extern "C"
319/** @} */ /* end of group headers */ 319/** @} */ /* end of group headers */
320 320
321/** 321/**
322 * @defgroup versions HTTP versions 322 * @defgroup versions HTTP versions
323 * These strings should be used to match against the first line of the 323 * These strings should be used to match against the first line of the
324 * HTTP header. 324 * HTTP header.
325 * @{ 325 * @{
@@ -367,7 +367,7 @@ struct MHD_Daemon;
367 * 367 *
368 * With HTTP/1.1, multiple requests can be run over the same 368 * With HTTP/1.1, multiple requests can be run over the same
369 * connection. However, MHD will only show one request per TCP 369 * connection. However, MHD will only show one request per TCP
370 * connection to the client at any given time. 370 * connection to the client at any given time.
371 * @ingroup request 371 * @ingroup request
372 */ 372 */
373struct MHD_Connection; 373struct MHD_Connection;
@@ -386,7 +386,7 @@ struct MHD_PostProcessor;
386 386
387 387
388/** 388/**
389 * @brief Flags for the `struct MHD_Daemon`. 389 * @brief Flags for the `struct MHD_Daemon`.
390 * 390 *
391 * Note that if neither #MHD_USE_THREAD_PER_CONNECTION nor 391 * Note that if neither #MHD_USE_THREAD_PER_CONNECTION nor
392 * #MHD_USE_SELECT_INTERNALLY is used, the client wants control over 392 * #MHD_USE_SELECT_INTERNALLY is used, the client wants control over
@@ -476,7 +476,7 @@ enum MHD_FLAG
476 MHD_USE_NO_LISTEN_SOCKET = 256, 476 MHD_USE_NO_LISTEN_SOCKET = 256,
477 477
478 /** 478 /**
479 * Use `epoll()` instead of `select()` or `poll()` for the event loop. 479 * Use `epoll()` instead of `select()` or `poll()` for the event loop.
480 * This option is only available on Linux; using the option on 480 * This option is only available on Linux; using the option on
481 * non-Linux systems will cause #MHD_start_daemon to fail. 481 * non-Linux systems will cause #MHD_start_daemon to fail.
482 */ 482 */
@@ -611,9 +611,9 @@ enum MHD_OPTION
611 * parsing will no longer contain the options, which maybe inconvenient for 611 * parsing will no longer contain the options, which maybe inconvenient for
612 * logging. This option should be followed by two arguments, the first 612 * logging. This option should be followed by two arguments, the first
613 * one must be of the form 613 * one must be of the form
614 * 614 *
615 * void * my_logger(void *cls, const char *uri, struct MHD_Connection *con) 615 * void * my_logger(void *cls, const char *uri, struct MHD_Connection *con)
616 * 616 *
617 * where the return value will be passed as 617 * where the return value will be passed as
618 * (`* con_cls`) in calls to the #MHD_AccessHandlerCallback 618 * (`* con_cls`) in calls to the #MHD_AccessHandlerCallback
619 * when this request is processed later; returning a 619 * when this request is processed later; returning a
@@ -675,7 +675,7 @@ enum MHD_OPTION
675 * a function of type #MHD_LogCallback and the second a pointer 675 * a function of type #MHD_LogCallback and the second a pointer
676 * `void *` which will be passed as the first argument to the log 676 * `void *` which will be passed as the first argument to the log
677 * callback. 677 * callback.
678 * 678 *
679 * Note that MHD will not generate any log messages 679 * Note that MHD will not generate any log messages
680 * if it was compiled without the "--enable-messages" 680 * if it was compiled without the "--enable-messages"
681 * flag being set. 681 * flag being set.
@@ -696,7 +696,7 @@ enum MHD_OPTION
696 * Additional options given in an array of `struct MHD_OptionItem`. 696 * Additional options given in an array of `struct MHD_OptionItem`.
697 * The array must be terminated with an entry `{MHD_OPTION_END, 0, NULL}`. 697 * The array must be terminated with an entry `{MHD_OPTION_END, 0, NULL}`.
698 * An example for code using #MHD_OPTION_ARRAY is: 698 * An example for code using #MHD_OPTION_ARRAY is:
699 * 699 *
700 * struct MHD_OptionItem ops[] = { 700 * struct MHD_OptionItem ops[] = {
701 * { MHD_OPTION_CONNECTION_LIMIT, 100, NULL }, 701 * { MHD_OPTION_CONNECTION_LIMIT, 100, NULL },
702 * { MHD_OPTION_CONNECTION_TIMEOUT, 10, NULL }, 702 * { MHD_OPTION_CONNECTION_TIMEOUT, 10, NULL },
@@ -705,7 +705,7 @@ enum MHD_OPTION
705 * d = MHD_start_daemon (0, 8080, NULL, NULL, dh, NULL, 705 * d = MHD_start_daemon (0, 8080, NULL, NULL, dh, NULL,
706 * MHD_OPTION_ARRAY, ops, 706 * MHD_OPTION_ARRAY, ops,
707 * MHD_OPTION_END); 707 * MHD_OPTION_END);
708 * 708 *
709 * For options that expect a single pointer argument, the 709 * For options that expect a single pointer argument, the
710 * second member of the `struct MHD_OptionItem` is ignored. 710 * second member of the `struct MHD_OptionItem` is ignored.
711 * For options that expect two pointer arguments, the first 711 * For options that expect two pointer arguments, the first
@@ -721,7 +721,7 @@ enum MHD_OPTION
721 * decodes escape sequences of the form "%HH". This option should 721 * decodes escape sequences of the form "%HH". This option should
722 * be followed by two arguments, the first one must be of the form 722 * be followed by two arguments, the first one must be of the form
723 * 723 *
724 * size_t my_unescaper(void *cls, 724 * size_t my_unescaper(void *cls,
725 * struct MHD_Connection *c, 725 * struct MHD_Connection *c,
726 * char *s) 726 * char *s)
727 * 727 *
@@ -737,7 +737,7 @@ enum MHD_OPTION
737 * Memory pointer for the random values to be used by the Digest 737 * Memory pointer for the random values to be used by the Digest
738 * Auth module. This option should be followed by two arguments. 738 * Auth module. This option should be followed by two arguments.
739 * First an integer of type `size_t` which specifies the size 739 * First an integer of type `size_t` which specifies the size
740 * of the buffer pointed to by the second argument in bytes. 740 * of the buffer pointed to by the second argument in bytes.
741 * Note that the application must ensure that the buffer of the 741 * Note that the application must ensure that the buffer of the
742 * second argument remains allocated and unmodified while the 742 * second argument remains allocated and unmodified while the
743 * deamon is running. 743 * deamon is running.
@@ -919,7 +919,7 @@ union MHD_ConnectionInfo
919 int /* enum gnutls_protocol */ protocol; 919 int /* enum gnutls_protocol */ protocol;
920 920
921 /** 921 /**
922 * Connect socket 922 * Connect socket
923 */ 923 */
924 int connect_fd; 924 int connect_fd;
925 925
@@ -1046,7 +1046,7 @@ enum MHD_DaemonInfoType
1046 * @param reason error detail, may be NULL 1046 * @param reason error detail, may be NULL
1047 * @ingroup logging 1047 * @ingroup logging
1048 */ 1048 */
1049typedef 1049typedef
1050 void (*MHD_PanicCallback) (void *cls, 1050 void (*MHD_PanicCallback) (void *cls,
1051 const char *file, 1051 const char *file,
1052 unsigned int line, 1052 unsigned int line,
@@ -1076,7 +1076,7 @@ typedef int
1076 * @param cls argument given together with the function 1076 * @param cls argument given together with the function
1077 * pointer when the handler was registered with MHD 1077 * pointer when the handler was registered with MHD
1078 * @param url the requested url 1078 * @param url the requested url
1079 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 1079 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
1080 * #MHD_HTTP_METHOD_PUT, etc.) 1080 * #MHD_HTTP_METHOD_PUT, etc.)
1081 * @param version the HTTP version string (i.e. 1081 * @param version the HTTP version string (i.e.
1082 * #MHD_HTTP_VERSION_1_1) 1082 * #MHD_HTTP_VERSION_1_1)
@@ -1157,12 +1157,9 @@ typedef int
1157 * total number of bytes that has been placed into @a buf should be 1157 * total number of bytes that has been placed into @a buf should be
1158 * returned. 1158 * returned.
1159 * 1159 *
1160 * Note that returning zero will cause libmicrohttpd to try again, 1160 * Note that returning zero will cause libmicrohttpd to try again.
1161 * either "immediately" if in multi-threaded mode (in which case the 1161 * Thus, returning zero should only be used in conjunction
1162 * callback may want to do blocking operations) or in the next round 1162 * with MHD_suspend_connection() to avoid busy waiting.
1163 * if #MHD_run is used. Returning 0 for a daemon that runs in internal
1164 * select mode is an error (since it would result in busy waiting) and
1165 * will cause the program to be aborted (via `abort()`).
1166 * 1163 *
1167 * @param cls extra argument to the callback 1164 * @param cls extra argument to the callback
1168 * @param pos position in the datastream to access; 1165 * @param pos position in the datastream to access;
@@ -1175,7 +1172,7 @@ typedef int
1175 * obtained from the content reader so far. 1172 * obtained from the content reader so far.
1176 * @param buf where to copy the data 1173 * @param buf where to copy the data
1177 * @param max maximum number of bytes to copy to @a buf (size of @a buf) 1174 * @param max maximum number of bytes to copy to @a buf (size of @a buf)
1178 * @return number of bytes written to @a buf; 1175 * @return number of bytes written to @a buf;
1179 * 0 is legal unless we are running in internal select mode (since 1176 * 0 is legal unless we are running in internal select mode (since
1180 * this would cause busy-waiting); 0 in external select mode 1177 * this would cause busy-waiting); 0 in external select mode
1181 * will cause this function to be called again once the external 1178 * will cause this function to be called again once the external
@@ -1183,7 +1180,7 @@ typedef int
1183 * #MHD_CONTENT_READER_END_OF_STREAM (-1) for the regular 1180 * #MHD_CONTENT_READER_END_OF_STREAM (-1) for the regular
1184 * end of transmission (with chunked encoding, MHD will then 1181 * end of transmission (with chunked encoding, MHD will then
1185 * terminate the chunk and send any HTTP footers that might be 1182 * terminate the chunk and send any HTTP footers that might be
1186 * present; without chunked encoding and given an unknown 1183 * present; without chunked encoding and given an unknown
1187 * response size, MHD will simply close the connection; note 1184 * response size, MHD will simply close the connection; note
1188 * that while returning #MHD_CONTENT_READER_END_OF_STREAM is not technically 1185 * that while returning #MHD_CONTENT_READER_END_OF_STREAM is not technically
1189 * legal if a response size was specified, MHD accepts this 1186 * legal if a response size was specified, MHD accepts this
@@ -1214,7 +1211,7 @@ typedef ssize_t
1214 * @param cls closure 1211 * @param cls closure
1215 * @ingroup response 1212 * @ingroup response
1216 */ 1213 */
1217typedef void 1214typedef void
1218 (*MHD_ContentReaderFreeCallback) (void *cls); 1215 (*MHD_ContentReaderFreeCallback) (void *cls);
1219 1216
1220 1217
@@ -1244,8 +1241,8 @@ typedef int
1244 const char *filename, 1241 const char *filename,
1245 const char *content_type, 1242 const char *content_type,
1246 const char *transfer_encoding, 1243 const char *transfer_encoding,
1247 const char *data, 1244 const char *data,
1248 uint64_t off, 1245 uint64_t off,
1249 size_t size); 1246 size_t size);
1250 1247
1251/* **************** Daemon handling functions ***************** */ 1248/* **************** Daemon handling functions ***************** */
@@ -1271,7 +1268,7 @@ struct MHD_Daemon *
1271MHD_start_daemon_va (unsigned int flags, 1268MHD_start_daemon_va (unsigned int flags,
1272 uint16_t port, 1269 uint16_t port,
1273 MHD_AcceptPolicyCallback apc, void *apc_cls, 1270 MHD_AcceptPolicyCallback apc, void *apc_cls,
1274 MHD_AccessHandlerCallback dh, void *dh_cls, 1271 MHD_AccessHandlerCallback dh, void *dh_cls,
1275 va_list ap); 1272 va_list ap);
1276 1273
1277 1274
@@ -1295,7 +1292,7 @@ struct MHD_Daemon *
1295MHD_start_daemon (unsigned int flags, 1292MHD_start_daemon (unsigned int flags,
1296 uint16_t port, 1293 uint16_t port,
1297 MHD_AcceptPolicyCallback apc, void *apc_cls, 1294 MHD_AcceptPolicyCallback apc, void *apc_cls,
1298 MHD_AccessHandlerCallback dh, void *dh_cls, 1295 MHD_AccessHandlerCallback dh, void *dh_cls,
1299 ...); 1296 ...);
1300 1297
1301 1298
@@ -1314,7 +1311,7 @@ MHD_start_daemon (unsigned int flags,
1314 * #MHD_start_daemon, this function will return -1. 1311 * #MHD_start_daemon, this function will return -1.
1315 * 1312 *
1316 * @param daemon daemon to stop accepting new connections for 1313 * @param daemon daemon to stop accepting new connections for
1317 * @return old listen socket on success, -1 if the daemon was 1314 * @return old listen socket on success, -1 if the daemon was
1318 * already not listening anymore 1315 * already not listening anymore
1319 * @ingroup specialized 1316 * @ingroup specialized
1320 */ 1317 */
@@ -1328,7 +1325,7 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon);
1328 * @param daemon daemon to stop 1325 * @param daemon daemon to stop
1329 * @ingroup event 1326 * @ingroup event
1330 */ 1327 */
1331void 1328void
1332MHD_stop_daemon (struct MHD_Daemon *daemon); 1329MHD_stop_daemon (struct MHD_Daemon *daemon);
1333 1330
1334 1331
@@ -1361,8 +1358,8 @@ MHD_stop_daemon (struct MHD_Daemon *daemon);
1361 * set to indicate further details about the error. 1358 * set to indicate further details about the error.
1362 * @ingroup specialized 1359 * @ingroup specialized
1363 */ 1360 */
1364int 1361int
1365MHD_add_connection (struct MHD_Daemon *daemon, 1362MHD_add_connection (struct MHD_Daemon *daemon,
1366 int client_socket, 1363 int client_socket,
1367 const struct sockaddr *addr, 1364 const struct sockaddr *addr,
1368 socklen_t addrlen); 1365 socklen_t addrlen);
@@ -1385,8 +1382,8 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1385int 1382int
1386MHD_get_fdset (struct MHD_Daemon *daemon, 1383MHD_get_fdset (struct MHD_Daemon *daemon,
1387 fd_set *read_fd_set, 1384 fd_set *read_fd_set,
1388 fd_set *write_fd_set, 1385 fd_set *write_fd_set,
1389 fd_set *except_fd_set, 1386 fd_set *except_fd_set,
1390 int *max_fd); 1387 int *max_fd);
1391 1388
1392 1389
@@ -1404,8 +1401,8 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
1404 * necessiate the use of a timeout right now). 1401 * necessiate the use of a timeout right now).
1405 * @ingroup event 1402 * @ingroup event
1406 */ 1403 */
1407int 1404int
1408MHD_get_timeout (struct MHD_Daemon *daemon, 1405MHD_get_timeout (struct MHD_Daemon *daemon,
1409 MHD_UNSIGNED_LONG_LONG *timeout); 1406 MHD_UNSIGNED_LONG_LONG *timeout);
1410 1407
1411 1408
@@ -1428,7 +1425,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
1428 * options for this call. 1425 * options for this call.
1429 * @ingroup event 1426 * @ingroup event
1430 */ 1427 */
1431int 1428int
1432MHD_run (struct MHD_Daemon *daemon); 1429MHD_run (struct MHD_Daemon *daemon);
1433 1430
1434 1431
@@ -1452,7 +1449,7 @@ MHD_run (struct MHD_Daemon *daemon);
1452 * @ingroup event 1449 * @ingroup event
1453 */ 1450 */
1454int 1451int
1455MHD_run_from_select (struct MHD_Daemon *daemon, 1452MHD_run_from_select (struct MHD_Daemon *daemon,
1456 const fd_set *read_fd_set, 1453 const fd_set *read_fd_set,
1457 const fd_set *write_fd_set, 1454 const fd_set *write_fd_set,
1458 const fd_set *except_fd_set); 1455 const fd_set *except_fd_set);
@@ -1486,7 +1483,7 @@ MHD_get_connection_values (struct MHD_Connection *connection,
1486 * them). This maybe required in certain situations (see Mantis 1483 * them). This maybe required in certain situations (see Mantis
1487 * #1399) where (broken) HTTP implementations fail to supply values 1484 * #1399) where (broken) HTTP implementations fail to supply values
1488 * needed by the post processor (or other parts of the application). 1485 * needed by the post processor (or other parts of the application).
1489 * 1486 *
1490 * This function MUST only be called from within the 1487 * This function MUST only be called from within the
1491 * #MHD_AccessHandlerCallback (otherwise, access maybe improperly 1488 * #MHD_AccessHandlerCallback (otherwise, access maybe improperly
1492 * synchronized). Furthermore, the client must guarantee that the key 1489 * synchronized). Furthermore, the client must guarantee that the key
@@ -1507,7 +1504,7 @@ MHD_get_connection_values (struct MHD_Connection *connection,
1507int 1504int
1508MHD_set_connection_value (struct MHD_Connection *connection, 1505MHD_set_connection_value (struct MHD_Connection *connection,
1509 enum MHD_ValueKind kind, 1506 enum MHD_ValueKind kind,
1510 const char *key, 1507 const char *key,
1511 const char *value); 1508 const char *value);
1512 1509
1513 1510
@@ -1527,7 +1524,7 @@ MHD_set_connection_value (struct MHD_Connection *connection,
1527 * @param cls passed to @a cb 1524 * @param cls passed to @a cb
1528 * @ingroup logging 1525 * @ingroup logging
1529 */ 1526 */
1530void 1527void
1531MHD_set_panic_func (MHD_PanicCallback cb, void *cls); 1528MHD_set_panic_func (MHD_PanicCallback cb, void *cls);
1532 1529
1533 1530
@@ -1560,10 +1557,53 @@ MHD_lookup_connection_value (struct MHD_Connection *connection,
1560 */ 1557 */
1561int 1558int
1562MHD_queue_response (struct MHD_Connection *connection, 1559MHD_queue_response (struct MHD_Connection *connection,
1563 unsigned int status_code, 1560 unsigned int status_code,
1564 struct MHD_Response *response); 1561 struct MHD_Response *response);
1565 1562
1566 1563
1564/**
1565 * Suspend handling of network data for a given connection. This can
1566 * be used to dequeue a connection from MHD's event loop (external
1567 * select, internal select or thread pool; not applicable to
1568 * thread-per-connection!) for a while.
1569 *
1570 * If you use this API in conjunction with a internal select or a
1571 * thread pool, you must set the option #MHD_USE_PIPE_FOR_SHUTDOWN to
1572 * ensure that a resumed connection is immediately processed by MHD.
1573 *
1574 * Suspended connections continue to count against the total number of
1575 * connections allowed (per daemon, as well as per IP, if such limits
1576 * are set). Suspended connections will NOT time out; timeouts will
1577 * restart when the connection handling is resumed. While a
1578 * connection is suspended, MHD will not detect disconnects by the
1579 * client.
1580 *
1581 * The only safe time to suspend a connection is from the
1582 * #MHD_AccessHandlerCallback.
1583 *
1584 * Finally, it is an API violation to call #MHD_stop_daemon while
1585 * having suspended connections (this will at least create memory and
1586 * socket leaks or lead to undefined behavior). You must explicitly
1587 * resume all connections before stopping the daemon.
1588 *
1589 * @param connection the connection to suspend
1590 */
1591void
1592MHD_suspend_connection (struct MHD_Connection *connection);
1593
1594
1595/**
1596 * Resume handling of network data for suspended connection. It is
1597 * safe to resume a suspended connection at any time. Calling this
1598 * function on a connection that was not previously suspended will
1599 * result in undefined behavior.
1600 *
1601 * @param connection the connection to resume
1602 */
1603void
1604MHD_resume_connection (struct MHD_Connection *connection);
1605
1606
1567/* **************** Response manipulation functions ***************** */ 1607/* **************** Response manipulation functions ***************** */
1568 1608
1569/** 1609/**
@@ -1615,7 +1655,7 @@ MHD_create_response_from_data (size_t size,
1615 * given for the response. 1655 * given for the response.
1616 * @ingroup response 1656 * @ingroup response
1617 */ 1657 */
1618enum MHD_ResponseMemoryMode 1658enum MHD_ResponseMemoryMode
1619{ 1659{
1620 1660
1621 /** 1661 /**
@@ -1667,7 +1707,7 @@ MHD_create_response_from_buffer (size_t size,
1667 * header information and then be used any number of times. 1707 * header information and then be used any number of times.
1668 * 1708 *
1669 * @param size size of the data portion of the response 1709 * @param size size of the data portion of the response
1670 * @param fd file descriptor referring to a file on disk with the 1710 * @param fd file descriptor referring to a file on disk with the
1671 * data; will be closed when response is destroyed; 1711 * data; will be closed when response is destroyed;
1672 * fd should be in 'blocking' mode 1712 * fd should be in 'blocking' mode
1673 * @return NULL on error (i.e. invalid arguments, out of memory) 1713 * @return NULL on error (i.e. invalid arguments, out of memory)
@@ -1687,7 +1727,7 @@ MHD_create_response_from_fd (size_t size,
1687 * data; will be closed when response is destroyed; 1727 * data; will be closed when response is destroyed;
1688 * fd should be in 'blocking' mode 1728 * fd should be in 'blocking' mode
1689 * @param offset offset to start reading from in the file; 1729 * @param offset offset to start reading from in the file;
1690 * Be careful! `off_t` may have been compiled to be a 1730 * Be careful! `off_t` may have been compiled to be a
1691 * 64-bit variable for MHD, in which case your application 1731 * 64-bit variable for MHD, in which case your application
1692 * also has to be compiled using the same options! Read 1732 * also has to be compiled using the same options! Read
1693 * the MHD manual for more details. 1733 * the MHD manual for more details.
@@ -1705,7 +1745,7 @@ MHD_create_response_from_fd_at_offset (size_t size,
1705 * Bits in an event mask that specifies which actions 1745 * Bits in an event mask that specifies which actions
1706 * MHD should perform and under which conditions it 1746 * MHD should perform and under which conditions it
1707 * should call the 'upgrade' callback again. 1747 * should call the 'upgrade' callback again.
1708 */ 1748 */
1709enum MHD_UpgradeEventMask 1749enum MHD_UpgradeEventMask
1710{ 1750{
1711 1751
@@ -1731,7 +1771,7 @@ enum MHD_UpgradeEventMask
1731 * Do not wait on any socket actions, we're waiting on 1771 * Do not wait on any socket actions, we're waiting on
1732 * an 'external' event. Run the function again once 1772 * an 'external' event. Run the function again once
1733 * the 'select' call returns _without_ this socket even 1773 * the 'select' call returns _without_ this socket even
1734 * being involved in the select sets (useful in 1774 * being involved in the select sets (useful in
1735 * conjunction with the external select loop). 1775 * conjunction with the external select loop).
1736 */ 1776 */
1737 MHD_UPGRADE_EVENT_EXTERNAL = 4, 1777 MHD_UPGRADE_EVENT_EXTERNAL = 4,
@@ -1743,15 +1783,15 @@ enum MHD_UpgradeEventMask
1743 * may ignore if the platform does not support it). Note that 1783 * may ignore if the platform does not support it). Note that
1744 * only returning 'CORK' will *also* cause the socket to be closed! 1784 * only returning 'CORK' will *also* cause the socket to be closed!
1745 */ 1785 */
1746 MHD_UPGRADE_EVENT_CORK = 8 1786 MHD_UPGRADE_EVENT_CORK = 8
1747 1787
1748}; 1788};
1749 1789
1750 1790
1751/** 1791/**
1752 * Function called after a protocol "upgrade" response was sent 1792 * Function called after a protocol "upgrade" response was sent
1753 * successfully and the socket should now be controlled by some 1793 * successfully and the socket should now be controlled by some
1754 * protocol other than HTTP. 1794 * protocol other than HTTP.
1755 * 1795 *
1756 * Any data received on the socket will be made available in 1796 * Any data received on the socket will be made available in
1757 * 'data_in'. The function should update 'data_in_size' to 1797 * 'data_in'. The function should update 'data_in_size' to
@@ -1786,7 +1826,7 @@ enum MHD_UpgradeEventMask
1786 * be also given to the #MHD_RequestCompletedCallback 1826 * be also given to the #MHD_RequestCompletedCallback
1787 * @param data_in_size available data for reading, set to data read 1827 * @param data_in_size available data for reading, set to data read
1788 * @param data_in data read from the socket 1828 * @param data_in data read from the socket
1789 * @param data_out_size available buffer for writing, set to bytes 1829 * @param data_out_size available buffer for writing, set to bytes
1790 * written to 'data_out' 1830 * written to 'data_out'
1791 * @param data_out buffer for sending data via the connection 1831 * @param data_out buffer for sending data via the connection
1792 * @return desired actions for event handling loop 1832 * @return desired actions for event handling loop
@@ -1843,7 +1883,7 @@ MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
1843 * @param response response to destroy 1883 * @param response response to destroy
1844 * @ingroup response 1884 * @ingroup response
1845 */ 1885 */
1846void 1886void
1847MHD_destroy_response (struct MHD_Response *response); 1887MHD_destroy_response (struct MHD_Response *response);
1848 1888
1849 1889
@@ -1874,7 +1914,7 @@ MHD_add_response_header (struct MHD_Response *response,
1874 */ 1914 */
1875int 1915int
1876MHD_add_response_footer (struct MHD_Response *response, 1916MHD_add_response_footer (struct MHD_Response *response,
1877 const char *footer, 1917 const char *footer,
1878 const char *content); 1918 const char *content);
1879 1919
1880 1920
@@ -1889,7 +1929,7 @@ MHD_add_response_footer (struct MHD_Response *response,
1889 */ 1929 */
1890int 1930int
1891MHD_del_response_header (struct MHD_Response *response, 1931MHD_del_response_header (struct MHD_Response *response,
1892 const char *header, 1932 const char *header,
1893 const char *content); 1933 const char *content);
1894 1934
1895 1935
@@ -1982,7 +2022,7 @@ MHD_post_process (struct MHD_PostProcessor *pp,
1982 * value of this function 2022 * value of this function
1983 * @ingroup request 2023 * @ingroup request
1984 */ 2024 */
1985int 2025int
1986MHD_destroy_post_processor (struct MHD_PostProcessor *pp); 2026MHD_destroy_post_processor (struct MHD_PostProcessor *pp);
1987 2027
1988 2028
@@ -2098,7 +2138,7 @@ MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection,
2098 */ 2138 */
2099const union MHD_ConnectionInfo * 2139const union MHD_ConnectionInfo *
2100MHD_get_connection_info (struct MHD_Connection *connection, 2140MHD_get_connection_info (struct MHD_Connection *connection,
2101 enum MHD_ConnectionInfoType info_type, 2141 enum MHD_ConnectionInfoType info_type,
2102 ...); 2142 ...);
2103 2143
2104 2144
@@ -2128,11 +2168,11 @@ enum MHD_CONNECTION_OPTION
2128 * @return #MHD_YES on success, #MHD_NO if setting the option failed 2168 * @return #MHD_YES on success, #MHD_NO if setting the option failed
2129 * @ingroup specialized 2169 * @ingroup specialized
2130 */ 2170 */
2131int 2171int
2132MHD_set_connection_option (struct MHD_Connection *connection, 2172MHD_set_connection_option (struct MHD_Connection *connection,
2133 enum MHD_CONNECTION_OPTION option, 2173 enum MHD_CONNECTION_OPTION option,
2134 ...); 2174 ...);
2135 2175
2136 2176
2137/** 2177/**
2138 * Information about an MHD daemon. 2178 * Information about an MHD daemon.
@@ -2171,7 +2211,7 @@ union MHD_DaemonInfo
2171 */ 2211 */
2172const union MHD_DaemonInfo * 2212const union MHD_DaemonInfo *
2173MHD_get_daemon_info (struct MHD_Daemon *daemon, 2213MHD_get_daemon_info (struct MHD_Daemon *daemon,
2174 enum MHD_DaemonInfoType info_type, 2214 enum MHD_DaemonInfoType info_type,
2175 ...); 2215 ...);
2176 2216
2177 2217
@@ -2181,7 +2221,7 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon,
2181 * @return static version string, e.g. "0.9.9" 2221 * @return static version string, e.g. "0.9.9"
2182 * @ingroup specialized 2222 * @ingroup specialized
2183 */ 2223 */
2184const char* 2224const char*
2185MHD_get_version (void); 2225MHD_get_version (void);
2186 2226
2187 2227
diff --git a/src/microhttpd/EXPORT.sym b/src/microhttpd/EXPORT.sym
index dc32b6d3..402a0ef3 100644
--- a/src/microhttpd/EXPORT.sym
+++ b/src/microhttpd/EXPORT.sym
@@ -35,3 +35,5 @@ MHD_basic_auth_get_username_password
35MHD_queue_basic_auth_fail_response 35MHD_queue_basic_auth_fail_response
36MHD_add_connection 36MHD_add_connection
37MHD_set_connection_option 37MHD_set_connection_option
38MHD_suspend_connection
39MHD_resume_connection
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 6190fc29..63df4b94 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -148,7 +148,7 @@ MHD_get_connection_values (struct MHD_Connection *connection,
148 * them). This maybe required in certain situations (see Mantis 148 * them). This maybe required in certain situations (see Mantis
149 * #1399) where (broken) HTTP implementations fail to supply values 149 * #1399) where (broken) HTTP implementations fail to supply values
150 * needed by the post processor (or other parts of the application). 150 * needed by the post processor (or other parts of the application).
151 * 151 *
152 * This function MUST only be called from within the 152 * This function MUST only be called from within the
153 * #MHD_AccessHandlerCallback (otherwise, access maybe improperly 153 * #MHD_AccessHandlerCallback (otherwise, access maybe improperly
154 * synchronized). Furthermore, the client must guarantee that the key 154 * synchronized). Furthermore, the client must guarantee that the key
@@ -215,12 +215,12 @@ MHD_lookup_connection_value (struct MHD_Connection *connection,
215 if (NULL == connection) 215 if (NULL == connection)
216 return NULL; 216 return NULL;
217 for (pos = connection->headers_received; NULL != pos; pos = pos->next) 217 for (pos = connection->headers_received; NULL != pos; pos = pos->next)
218 if ((0 != (pos->kind & kind)) && 218 if ((0 != (pos->kind & kind)) &&
219 ( (key == pos->header) || 219 ( (key == pos->header) ||
220 ( (NULL != pos->header) && 220 ( (NULL != pos->header) &&
221 (NULL != key) && 221 (NULL != key) &&
222 (0 == strcasecmp (key, pos->header))) )) 222 (0 == strcasecmp (key, pos->header))) ))
223 return pos->value; 223 return pos->value;
224 return NULL; 224 return NULL;
225} 225}
226 226
@@ -265,13 +265,13 @@ MHD_connection_close (struct MHD_Connection *connection,
265 265
266 daemon = connection->daemon; 266 daemon = connection->daemon;
267 if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO)) 267 if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO))
268 SHUTDOWN (connection->socket_fd, 268 SHUTDOWN (connection->socket_fd,
269 (MHD_YES == connection->read_closed) ? SHUT_WR : SHUT_RDWR); 269 (MHD_YES == connection->read_closed) ? SHUT_WR : SHUT_RDWR);
270 connection->state = MHD_CONNECTION_CLOSED; 270 connection->state = MHD_CONNECTION_CLOSED;
271 connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; 271 connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP;
272 if ( (NULL != daemon->notify_completed) && 272 if ( (NULL != daemon->notify_completed) &&
273 (MHD_YES == connection->client_aware) ) 273 (MHD_YES == connection->client_aware) )
274 daemon->notify_completed (daemon->notify_completed_cls, 274 daemon->notify_completed (daemon->notify_completed_cls,
275 connection, 275 connection,
276 &connection->client_context, 276 &connection->client_context,
277 termination_code); 277 termination_code);
@@ -342,25 +342,16 @@ try_ready_normal_body (struct MHD_Connection *connection)
342 (0 == (connection->daemon->options & MHD_USE_SSL)) ) 342 (0 == (connection->daemon->options & MHD_USE_SSL)) )
343 { 343 {
344 /* will use sendfile, no need to bother response crc */ 344 /* will use sendfile, no need to bother response crc */
345 return MHD_YES; 345 return MHD_YES;
346 } 346 }
347#endif 347#endif
348 348
349 ret = response->crc (response->crc_cls, 349 ret = response->crc (response->crc_cls,
350 connection->response_write_position, 350 connection->response_write_position,
351 response->data, 351 response->data,
352 MHD_MIN (response->data_buffer_size, 352 MHD_MIN (response->data_buffer_size,
353 response->total_size - 353 response->total_size -
354 connection->response_write_position)); 354 connection->response_write_position));
355 if ((0 == ret) &&
356 (0 != (connection->daemon->options & MHD_USE_SELECT_INTERNALLY)))
357 mhd_panic (mhd_panic_cls, __FILE__, __LINE__
358#if HAVE_MESSAGES
359 , "API violation"
360#else
361 , NULL
362#endif
363 );
364 if ( (MHD_CONTENT_READER_END_OF_STREAM == ret) || 355 if ( (MHD_CONTENT_READER_END_OF_STREAM == ret) ||
365 (MHD_CONTENT_READER_END_WITH_ERROR == ret) ) 356 (MHD_CONTENT_READER_END_WITH_ERROR == ret) )
366 { 357 {
@@ -368,7 +359,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
368 response->total_size = connection->response_write_position; 359 response->total_size = connection->response_write_position;
369 if (NULL != response->crc) 360 if (NULL != response->crc)
370 pthread_mutex_unlock (&response->mutex); 361 pthread_mutex_unlock (&response->mutex);
371 if (MHD_CONTENT_READER_END_OF_STREAM == ret) 362 if (MHD_CONTENT_READER_END_OF_STREAM == ret)
372 MHD_connection_close (connection, MHD_REQUEST_TERMINATED_COMPLETED_OK); 363 MHD_connection_close (connection, MHD_REQUEST_TERMINATED_COMPLETED_OK);
373 else 364 else
374 CONNECTION_CLOSE_ERROR (connection, 365 CONNECTION_CLOSE_ERROR (connection,
@@ -470,14 +461,14 @@ try_ready_chunked_body (struct MHD_Connection *connection)
470 response->total_size = connection->response_write_position; 461 response->total_size = connection->response_write_position;
471 return MHD_YES; 462 return MHD_YES;
472 } 463 }
473 if (0 == ret) 464 if (0 == ret)
474 { 465 {
475 connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY; 466 connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY;
476 return MHD_NO; 467 return MHD_NO;
477 } 468 }
478 if (ret > 0xFFFFFF) 469 if (ret > 0xFFFFFF)
479 ret = 0xFFFFFF; 470 ret = 0xFFFFFF;
480 snprintf (cbuf, 471 snprintf (cbuf,
481 sizeof (cbuf), 472 sizeof (cbuf),
482 "%X\r\n", (unsigned int) ret); 473 "%X\r\n", (unsigned int) ret);
483 cblen = strlen (cbuf); 474 cblen = strlen (cbuf);
@@ -528,7 +519,7 @@ add_extra_headers (struct MHD_Connection *connection)
528 if the client asked for a close, no need to start chunk'ing */ 519 if the client asked for a close, no need to start chunk'ing */
529 if ((NULL == client_close) && 520 if ((NULL == client_close) &&
530 (NULL != connection->version) && 521 (NULL != connection->version) &&
531 (0 == strcasecmp (connection->version, MHD_HTTP_VERSION_1_1))) 522 (0 == strcasecmp (connection->version, MHD_HTTP_VERSION_1_1)))
532 { 523 {
533 connection->have_chunked_upload = MHD_YES; 524 connection->have_chunked_upload = MHD_YES;
534 have_encoding = MHD_get_response_header (connection->response, 525 have_encoding = MHD_get_response_header (connection->response,
@@ -562,17 +553,17 @@ add_extra_headers (struct MHD_Connection *connection)
562 MHD_HTTP_METHOD_CONNECT)) || 553 MHD_HTTP_METHOD_CONNECT)) ||
563 (0 != connection->response->total_size) ) ) 554 (0 != connection->response->total_size) ) )
564 { 555 {
565 /* 556 /*
566 Here we add a content-length if one is missing; however, 557 Here we add a content-length if one is missing; however,
567 for 'connect' methods, the responses MUST NOT include a 558 for 'connect' methods, the responses MUST NOT include a
568 content-length header *if* the response code is 2xx (in 559 content-length header *if* the response code is 2xx (in
569 which case we expect there to be no body). Still, 560 which case we expect there to be no body). Still,
570 as we don't know the response code here in some cases, we 561 as we don't know the response code here in some cases, we
571 simply only force adding a content-length header if this 562 simply only force adding a content-length header if this
572 is not a 'connect' or if the response is not empty 563 is not a 'connect' or if the response is not empty
573 (which is kind of more sane, because if some crazy 564 (which is kind of more sane, because if some crazy
574 application did return content with a 2xx status code, 565 application did return content with a 2xx status code,
575 then having a content-length might again be a good idea). 566 then having a content-length might again be a good idea).
576 567
577 Note that the change from 'SHOULD NOT' to 'MUST NOT' is 568 Note that the change from 'SHOULD NOT' to 'MUST NOT' is
578 a recent development of the HTTP 1.1 specification. 569 a recent development of the HTTP 1.1 specification.
@@ -616,8 +607,8 @@ get_date_string (char *date)
616 (unsigned int) now.tm_mday, 607 (unsigned int) now.tm_mday,
617 mons[now.tm_mon % 12], 608 mons[now.tm_mon % 12],
618 (unsigned int) (1900 + now.tm_year), 609 (unsigned int) (1900 + now.tm_year),
619 (unsigned int) now.tm_hour, 610 (unsigned int) now.tm_hour,
620 (unsigned int) now.tm_min, 611 (unsigned int) now.tm_min,
621 (unsigned int) now.tm_sec); 612 (unsigned int) now.tm_sec);
622} 613}
623 614
@@ -626,7 +617,7 @@ get_date_string (char *date)
626 * Try growing the read buffer. We initially claim half the 617 * Try growing the read buffer. We initially claim half the
627 * available buffer space for the read buffer (the other half 618 * available buffer space for the read buffer (the other half
628 * being left for management data structures; the write 619 * being left for management data structures; the write
629 * buffer can in the end take virtually everything as the 620 * buffer can in the end take virtually everything as the
630 * read buffer can be reduced to the minimum necessary at that 621 * read buffer can be reduced to the minimum necessary at that
631 * point. 622 * point.
632 * 623 *
@@ -696,18 +687,18 @@ build_header_response (struct MHD_Connection *connection)
696 SPRINTF (code, 687 SPRINTF (code,
697 "%s %u %s\r\n", 688 "%s %u %s\r\n",
698 (0 != (connection->responseCode & MHD_ICY_FLAG)) 689 (0 != (connection->responseCode & MHD_ICY_FLAG))
699 ? "ICY" 690 ? "ICY"
700 : ( (0 == strcasecmp (MHD_HTTP_VERSION_1_0, 691 : ( (0 == strcasecmp (MHD_HTTP_VERSION_1_0,
701 connection->version)) 692 connection->version))
702 ? MHD_HTTP_VERSION_1_0 693 ? MHD_HTTP_VERSION_1_0
703 : MHD_HTTP_VERSION_1_1), 694 : MHD_HTTP_VERSION_1_1),
704 rc, 695 rc,
705 reason_phrase); 696 reason_phrase);
706 off = strlen (code); 697 off = strlen (code);
707 /* estimate size */ 698 /* estimate size */
708 size = off + 2; /* extra \r\n at the end */ 699 size = off + 2; /* extra \r\n at the end */
709 kind = MHD_HEADER_KIND; 700 kind = MHD_HEADER_KIND;
710 if ( (0 == (connection->daemon->options & MHD_SUPPRESS_DATE_NO_CLOCK)) && 701 if ( (0 == (connection->daemon->options & MHD_SUPPRESS_DATE_NO_CLOCK)) &&
711 (NULL == MHD_get_response_header (connection->response, 702 (NULL == MHD_get_response_header (connection->response,
712 MHD_HTTP_HEADER_DATE)) ) 703 MHD_HTTP_HEADER_DATE)) )
713 get_date_string (date); 704 get_date_string (date);
@@ -757,9 +748,9 @@ build_header_response (struct MHD_Connection *connection)
757 } 748 }
758 for (pos = connection->response->first_header; NULL != pos; pos = pos->next) 749 for (pos = connection->response->first_header; NULL != pos; pos = pos->next)
759 if (pos->kind == kind) 750 if (pos->kind == kind)
760 off += SPRINTF (&data[off], 751 off += SPRINTF (&data[off],
761 "%s: %s\r\n", 752 "%s: %s\r\n",
762 pos->header, 753 pos->header,
763 pos->value); 754 pos->value);
764 if (connection->state == MHD_CONNECTION_FOOTERS_RECEIVED) 755 if (connection->state == MHD_CONNECTION_FOOTERS_RECEIVED)
765 { 756 {
@@ -790,7 +781,7 @@ build_header_response (struct MHD_Connection *connection)
790 */ 781 */
791static void 782static void
792transmit_error_response (struct MHD_Connection *connection, 783transmit_error_response (struct MHD_Connection *connection,
793 unsigned int status_code, 784 unsigned int status_code,
794 const char *message) 785 const char *message)
795{ 786{
796 struct MHD_Response *response; 787 struct MHD_Response *response;
@@ -810,7 +801,7 @@ transmit_error_response (struct MHD_Connection *connection,
810#endif 801#endif
811 EXTRA_CHECK (NULL == connection->response); 802 EXTRA_CHECK (NULL == connection->response);
812 response = MHD_create_response_from_buffer (strlen (message), 803 response = MHD_create_response_from_buffer (strlen (message),
813 (void *) message, 804 (void *) message,
814 MHD_RESPMEM_PERSISTENT); 805 MHD_RESPMEM_PERSISTENT);
815 MHD_queue_response (connection, status_code, response); 806 MHD_queue_response (connection, status_code, response);
816 EXTRA_CHECK (NULL != connection->response); 807 EXTRA_CHECK (NULL != connection->response);
@@ -834,7 +825,7 @@ transmit_error_response (struct MHD_Connection *connection,
834 * perform other updates to the connection if needed to prepare for 825 * perform other updates to the connection if needed to prepare for
835 * the next round of the event loop. 826 * the next round of the event loop.
836 * 827 *
837 * @param connection connetion to get poll set for 828 * @param connection connetion to get poll set for
838 */ 829 */
839static void 830static void
840MHD_connection_update_event_loop_info (struct MHD_Connection *connection) 831MHD_connection_update_event_loop_info (struct MHD_Connection *connection)
@@ -847,7 +838,7 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection)
847#endif 838#endif
848 switch (connection->state) 839 switch (connection->state)
849 { 840 {
850#if HTTPS_SUPPORT 841#if HTTPS_SUPPORT
851 case MHD_TLS_CONNECTION_INIT: 842 case MHD_TLS_CONNECTION_INIT:
852 if (0 == gnutls_record_get_direction (connection->tls_session)) 843 if (0 == gnutls_record_get_direction (connection->tls_session))
853 connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; 844 connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
@@ -921,7 +912,7 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection)
921 read buffer if needed, no size-check required */ 912 read buffer if needed, no size-check required */
922 if (MHD_YES == connection->read_closed) 913 if (MHD_YES == connection->read_closed)
923 { 914 {
924 CONNECTION_CLOSE_ERROR (connection, 915 CONNECTION_CLOSE_ERROR (connection,
925 NULL); 916 NULL);
926 continue; 917 continue;
927 } 918 }
@@ -1000,7 +991,7 @@ get_next_header_line (struct MHD_Connection *connection)
1000 { 991 {
1001 /* not found, consider growing... */ 992 /* not found, consider growing... */
1002 if ( (connection->read_buffer_offset == connection->read_buffer_size) && 993 if ( (connection->read_buffer_offset == connection->read_buffer_size) &&
1003 (MHD_NO == 994 (MHD_NO ==
1004 try_grow_read_buffer (connection)) ) 995 try_grow_read_buffer (connection)) )
1005 { 996 {
1006 transmit_error_response (connection, 997 transmit_error_response (connection,
@@ -1008,7 +999,7 @@ get_next_header_line (struct MHD_Connection *connection)
1008 ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE 999 ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE
1009 : MHD_HTTP_REQUEST_URI_TOO_LONG, 1000 : MHD_HTTP_REQUEST_URI_TOO_LONG,
1010 REQUEST_TOO_BIG); 1001 REQUEST_TOO_BIG);
1011 } 1002 }
1012 return NULL; 1003 return NULL;
1013 } 1004 }
1014 /* found, check if we have proper LFCR */ 1005 /* found, check if we have proper LFCR */
@@ -1064,7 +1055,7 @@ connection_add_header (struct MHD_Connection *connection,
1064 */ 1055 */
1065static int 1056static int
1066parse_arguments (enum MHD_ValueKind kind, 1057parse_arguments (enum MHD_ValueKind kind,
1067 struct MHD_Connection *connection, 1058 struct MHD_Connection *connection,
1068 char *args) 1059 char *args)
1069{ 1060{
1070 char *equals; 1061 char *equals;
@@ -1086,7 +1077,7 @@ parse_arguments (enum MHD_ValueKind kind,
1086 return connection_add_header (connection, 1077 return connection_add_header (connection,
1087 args, 1078 args,
1088 NULL, 1079 NULL,
1089 kind); 1080 kind);
1090 } 1081 }
1091 /* got 'foo=bar' */ 1082 /* got 'foo=bar' */
1092 equals[0] = '\0'; 1083 equals[0] = '\0';
@@ -1261,7 +1252,7 @@ parse_initial_message_line (struct MHD_Connection *connection, char *line)
1261 } 1252 }
1262 if (NULL != connection->daemon->uri_log_callback) 1253 if (NULL != connection->daemon->uri_log_callback)
1263 connection->client_context 1254 connection->client_context
1264 = connection->daemon->uri_log_callback (connection->daemon->uri_log_callback_cls, 1255 = connection->daemon->uri_log_callback (connection->daemon->uri_log_callback_cls,
1265 uri, 1256 uri,
1266 connection); 1257 connection);
1267 args = strchr (uri, '?'); 1258 args = strchr (uri, '?');
@@ -1296,7 +1287,7 @@ call_connection_handler (struct MHD_Connection *connection)
1296 size_t processed; 1287 size_t processed;
1297 1288
1298 if (NULL != connection->response) 1289 if (NULL != connection->response)
1299 return; /* already queued a response */ 1290 return; /* already queued a response */
1300 processed = 0; 1291 processed = 0;
1301 connection->client_aware = MHD_YES; 1292 connection->client_aware = MHD_YES;
1302 if (MHD_NO == 1293 if (MHD_NO ==
@@ -1309,7 +1300,7 @@ call_connection_handler (struct MHD_Connection *connection)
1309 &connection->client_context)) 1300 &connection->client_context))
1310 { 1301 {
1311 /* serious internal error, close connection */ 1302 /* serious internal error, close connection */
1312 CONNECTION_CLOSE_ERROR (connection, 1303 CONNECTION_CLOSE_ERROR (connection,
1313 "Internal application error, closing connection.\n"); 1304 "Internal application error, closing connection.\n");
1314 return; 1305 return;
1315 } 1306 }
@@ -1438,7 +1429,7 @@ process_request_body (struct MHD_Connection *connection)
1438 else 1429 else
1439 { 1430 {
1440 /* no chunked encoding, give all to the client */ 1431 /* no chunked encoding, give all to the client */
1441 if ( (0 != connection->remaining_upload_size) && 1432 if ( (0 != connection->remaining_upload_size) &&
1442 (MHD_SIZE_UNKNOWN != connection->remaining_upload_size) && 1433 (MHD_SIZE_UNKNOWN != connection->remaining_upload_size) &&
1443 (connection->remaining_upload_size < available) ) 1434 (connection->remaining_upload_size < available) )
1444 { 1435 {
@@ -1527,7 +1518,7 @@ do_read (struct MHD_Connection *connection)
1527 "Failed to receive data: %s\n", 1518 "Failed to receive data: %s\n",
1528 gnutls_strerror (bytes_read)); 1519 gnutls_strerror (bytes_read));
1529 else 1520 else
1530#endif 1521#endif
1531 MHD_DLOG (connection->daemon, 1522 MHD_DLOG (connection->daemon,
1532 "Failed to receive data: %s\n", STRERROR (errno)); 1523 "Failed to receive data: %s\n", STRERROR (errno));
1533#endif 1524#endif
@@ -1577,7 +1568,7 @@ do_write (struct MHD_Connection *connection)
1577 "Failed to send data: %s\n", 1568 "Failed to send data: %s\n",
1578 gnutls_strerror (ret)); 1569 gnutls_strerror (ret));
1579 else 1570 else
1580#endif 1571#endif
1581 MHD_DLOG (connection->daemon, 1572 MHD_DLOG (connection->daemon,
1582 "Failed to send data: %s\n", STRERROR (errno)); 1573 "Failed to send data: %s\n", STRERROR (errno));
1583#endif 1574#endif
@@ -1613,7 +1604,7 @@ check_write_done (struct MHD_Connection *connection,
1613 connection->write_buffer_append_offset = 0; 1604 connection->write_buffer_append_offset = 0;
1614 connection->write_buffer_send_offset = 0; 1605 connection->write_buffer_send_offset = 0;
1615 connection->state = next_state; 1606 connection->state = next_state;
1616 MHD_pool_reallocate (connection->pool, 1607 MHD_pool_reallocate (connection->pool,
1617 connection->write_buffer, 1608 connection->write_buffer,
1618 connection->write_buffer_size, 0); 1609 connection->write_buffer_size, 0);
1619 connection->write_buffer = NULL; 1610 connection->write_buffer = NULL;
@@ -1641,7 +1632,7 @@ process_header_line (struct MHD_Connection *connection, char *line)
1641 if (NULL == colon) 1632 if (NULL == colon)
1642 { 1633 {
1643 /* error in header line, die hard */ 1634 /* error in header line, die hard */
1644 CONNECTION_CLOSE_ERROR (connection, 1635 CONNECTION_CLOSE_ERROR (connection,
1645 "Received malformed line (no colon), closing connection.\n"); 1636 "Received malformed line (no colon), closing connection.\n");
1646 return MHD_NO; 1637 return MHD_NO;
1647 } 1638 }
@@ -1689,7 +1680,7 @@ process_broken_line (struct MHD_Connection *connection,
1689 /* skip whitespace at start of 2nd line */ 1680 /* skip whitespace at start of 2nd line */
1690 tmp = line; 1681 tmp = line;
1691 while ((tmp[0] == ' ') || (tmp[0] == '\t')) 1682 while ((tmp[0] == ' ') || (tmp[0] == '\t'))
1692 tmp++; 1683 tmp++;
1693 tmp_len = strlen (tmp); 1684 tmp_len = strlen (tmp);
1694 /* FIXME: we might be able to do this better (faster!), as most 1685 /* FIXME: we might be able to do this better (faster!), as most
1695 likely 'last' and 'line' should already be adjacent in 1686 likely 'last' and 'line' should already be adjacent in
@@ -1833,7 +1824,7 @@ update_last_activity (struct MHD_Connection *connection)
1833 /* move connection to head of timeout list (by remove + add operation) */ 1824 /* move connection to head of timeout list (by remove + add operation) */
1834 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1825 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1835 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 1826 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
1836 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1827 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1837 XDLL_remove (daemon->normal_timeout_head, 1828 XDLL_remove (daemon->normal_timeout_head,
1838 daemon->normal_timeout_tail, 1829 daemon->normal_timeout_tail,
1839 connection); 1830 connection);
@@ -1842,13 +1833,13 @@ update_last_activity (struct MHD_Connection *connection)
1842 connection); 1833 connection);
1843 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1834 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1844 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 1835 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
1845 MHD_PANIC ("Failed to release cleanup mutex\n"); 1836 MHD_PANIC ("Failed to release cleanup mutex\n");
1846} 1837}
1847 1838
1848 1839
1849/** 1840/**
1850 * This function handles a particular connection when it has been 1841 * This function handles a particular connection when it has been
1851 * determined that there is data to be read off a socket. 1842 * determined that there is data to be read off a socket.
1852 * 1843 *
1853 * @param connection connection to handle 1844 * @param connection connection to handle
1854 * @return always #MHD_YES (we should continue to process the 1845 * @return always #MHD_YES (we should continue to process the
@@ -1982,10 +1973,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1982 break; 1973 break;
1983 case MHD_CONNECTION_NORMAL_BODY_READY: 1974 case MHD_CONNECTION_NORMAL_BODY_READY:
1984 response = connection->response; 1975 response = connection->response;
1985 if (response->crc != NULL) 1976 if (NULL != response->crc)
1986 pthread_mutex_lock (&response->mutex); 1977 pthread_mutex_lock (&response->mutex);
1987 if (MHD_YES != try_ready_normal_body (connection)) 1978 if (MHD_YES != try_ready_normal_body (connection))
1988 break; 1979 break;
1989 ret = connection->send_cls (connection, 1980 ret = connection->send_cls (connection,
1990 &response->data 1981 &response->data
1991 [connection->response_write_position 1982 [connection->response_write_position
@@ -2001,7 +1992,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
2001 &response->data[connection->response_write_position - 1992 &response->data[connection->response_write_position -
2002 response->data_start]); 1993 response->data_start]);
2003#endif 1994#endif
2004 if (response->crc != NULL) 1995 if (NULL != response->crc)
2005 pthread_mutex_unlock (&response->mutex); 1996 pthread_mutex_unlock (&response->mutex);
2006 if (ret < 0) 1997 if (ret < 0)
2007 { 1998 {
@@ -2078,8 +2069,8 @@ cleanup_connection (struct MHD_Connection *connection)
2078 connection->response = NULL; 2069 connection->response = NULL;
2079 } 2070 }
2080 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2071 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2081 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 2072 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
2082 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 2073 MHD_PANIC ("Failed to acquire cleanup mutex\n");
2083 if (connection->connection_timeout == daemon->connection_timeout) 2074 if (connection->connection_timeout == daemon->connection_timeout)
2084 XDLL_remove (daemon->normal_timeout_head, 2075 XDLL_remove (daemon->normal_timeout_head,
2085 daemon->normal_timeout_tail, 2076 daemon->normal_timeout_tail,
@@ -2095,15 +2086,15 @@ cleanup_connection (struct MHD_Connection *connection)
2095 daemon->cleanup_tail, 2086 daemon->cleanup_tail,
2096 connection); 2087 connection);
2097 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2088 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2098 (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) ) 2089 (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) )
2099 MHD_PANIC ("Failed to release cleanup mutex\n"); 2090 MHD_PANIC ("Failed to release cleanup mutex\n");
2100 connection->in_idle = MHD_NO; 2091 connection->in_idle = MHD_NO;
2101} 2092}
2102 2093
2103 2094
2104/** 2095/**
2105 * This function was created to handle per-connection processing that 2096 * This function was created to handle per-connection processing that
2106 * has to happen even if the socket cannot be read or written to. 2097 * has to happen even if the socket cannot be read or written to.
2107 * 2098 *
2108 * @param connection connection to handle 2099 * @param connection connection to handle
2109 * @return #MHD_YES if we should continue to process the 2100 * @return #MHD_YES if we should continue to process the
@@ -2135,7 +2126,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2135 continue; 2126 continue;
2136 if (MHD_YES == connection->read_closed) 2127 if (MHD_YES == connection->read_closed)
2137 { 2128 {
2138 CONNECTION_CLOSE_ERROR (connection, 2129 CONNECTION_CLOSE_ERROR (connection,
2139 NULL); 2130 NULL);
2140 continue; 2131 continue;
2141 } 2132 }
@@ -2154,7 +2145,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2154 continue; 2145 continue;
2155 if (MHD_YES == connection->read_closed) 2146 if (MHD_YES == connection->read_closed)
2156 { 2147 {
2157 CONNECTION_CLOSE_ERROR (connection, 2148 CONNECTION_CLOSE_ERROR (connection,
2158 NULL); 2149 NULL);
2159 continue; 2150 continue;
2160 } 2151 }
@@ -2182,7 +2173,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2182 continue; 2173 continue;
2183 if (MHD_YES == connection->read_closed) 2174 if (MHD_YES == connection->read_closed)
2184 { 2175 {
2185 CONNECTION_CLOSE_ERROR (connection, 2176 CONNECTION_CLOSE_ERROR (connection,
2186 NULL); 2177 NULL);
2187 continue; 2178 continue;
2188 } 2179 }
@@ -2262,7 +2253,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2262 continue; 2253 continue;
2263 if (MHD_YES == connection->read_closed) 2254 if (MHD_YES == connection->read_closed)
2264 { 2255 {
2265 CONNECTION_CLOSE_ERROR (connection, 2256 CONNECTION_CLOSE_ERROR (connection,
2266 NULL); 2257 NULL);
2267 continue; 2258 continue;
2268 } 2259 }
@@ -2290,7 +2281,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2290 continue; 2281 continue;
2291 if (MHD_YES == connection->read_closed) 2282 if (MHD_YES == connection->read_closed)
2292 { 2283 {
2293 CONNECTION_CLOSE_ERROR (connection, 2284 CONNECTION_CLOSE_ERROR (connection,
2294 NULL); 2285 NULL);
2295 continue; 2286 continue;
2296 } 2287 }
@@ -2314,7 +2305,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2314 if (MHD_NO == build_header_response (connection)) 2305 if (MHD_NO == build_header_response (connection))
2315 { 2306 {
2316 /* oops - close! */ 2307 /* oops - close! */
2317 CONNECTION_CLOSE_ERROR (connection, 2308 CONNECTION_CLOSE_ERROR (connection,
2318 "Closing connection (failed to create response header)\n"); 2309 "Closing connection (failed to create response header)\n");
2319 continue; 2310 continue;
2320 } 2311 }
@@ -2342,11 +2333,11 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2342 /* nothing to do here */ 2333 /* nothing to do here */
2343 break; 2334 break;
2344 case MHD_CONNECTION_NORMAL_BODY_UNREADY: 2335 case MHD_CONNECTION_NORMAL_BODY_UNREADY:
2345 if (connection->response->crc != NULL) 2336 if (NULL != connection->response->crc)
2346 pthread_mutex_lock (&connection->response->mutex); 2337 pthread_mutex_lock (&connection->response->mutex);
2347 if (0 == connection->response->total_size) 2338 if (0 == connection->response->total_size)
2348 { 2339 {
2349 if (connection->response->crc != NULL) 2340 if (NULL != connection->response->crc)
2350 pthread_mutex_unlock (&connection->response->mutex); 2341 pthread_mutex_unlock (&connection->response->mutex);
2351 connection->state = MHD_CONNECTION_BODY_SENT; 2342 connection->state = MHD_CONNECTION_BODY_SENT;
2352 continue; 2343 continue;
@@ -2364,23 +2355,23 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2364 /* nothing to do here */ 2355 /* nothing to do here */
2365 break; 2356 break;
2366 case MHD_CONNECTION_CHUNKED_BODY_UNREADY: 2357 case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
2367 if (connection->response->crc != NULL) 2358 if (NULL != connection->response->crc)
2368 pthread_mutex_lock (&connection->response->mutex); 2359 pthread_mutex_lock (&connection->response->mutex);
2369 if (0 == connection->response->total_size) 2360 if (0 == connection->response->total_size)
2370 { 2361 {
2371 if (connection->response->crc != NULL) 2362 if (NULL != connection->response->crc)
2372 pthread_mutex_unlock (&connection->response->mutex); 2363 pthread_mutex_unlock (&connection->response->mutex);
2373 connection->state = MHD_CONNECTION_BODY_SENT; 2364 connection->state = MHD_CONNECTION_BODY_SENT;
2374 continue; 2365 continue;
2375 } 2366 }
2376 if (MHD_YES == try_ready_chunked_body (connection)) 2367 if (MHD_YES == try_ready_chunked_body (connection))
2377 { 2368 {
2378 if (connection->response->crc != NULL) 2369 if (NULL != connection->response->crc)
2379 pthread_mutex_unlock (&connection->response->mutex); 2370 pthread_mutex_unlock (&connection->response->mutex);
2380 connection->state = MHD_CONNECTION_CHUNKED_BODY_READY; 2371 connection->state = MHD_CONNECTION_CHUNKED_BODY_READY;
2381 continue; 2372 continue;
2382 } 2373 }
2383 if (connection->response->crc != NULL) 2374 if (NULL != connection->response->crc)
2384 pthread_mutex_unlock (&connection->response->mutex); 2375 pthread_mutex_unlock (&connection->response->mutex);
2385 break; 2376 break;
2386 case MHD_CONNECTION_BODY_SENT: 2377 case MHD_CONNECTION_BODY_SENT:
@@ -2404,7 +2395,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2404 } 2395 }
2405#endif 2396#endif
2406 end = 2397 end =
2407 MHD_get_response_header (connection->response, 2398 MHD_get_response_header (connection->response,
2408 MHD_HTTP_HEADER_CONNECTION); 2399 MHD_HTTP_HEADER_CONNECTION);
2409 rend = ( (MHD_YES == connection->read_closed) || 2400 rend = ( (MHD_YES == connection->read_closed) ||
2410 ( (end != NULL) && (0 == strcasecmp (end, "close")) ) ); 2401 ( (end != NULL) && (0 == strcasecmp (end, "close")) ) );
@@ -2414,7 +2405,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2414 daemon->notify_completed (daemon->notify_completed_cls, 2405 daemon->notify_completed (daemon->notify_completed_cls,
2415 connection, 2406 connection,
2416 &connection->client_context, 2407 &connection->client_context,
2417 MHD_REQUEST_TERMINATED_COMPLETED_OK); 2408 MHD_REQUEST_TERMINATED_COMPLETED_OK);
2418 connection->client_aware = MHD_NO; 2409 connection->client_aware = MHD_NO;
2419 end = 2410 end =
2420 MHD_lookup_connection_value (connection, MHD_HEADER_KIND, 2411 MHD_lookup_connection_value (connection, MHD_HEADER_KIND,
@@ -2478,7 +2469,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2478 return MHD_YES; 2469 return MHD_YES;
2479 } 2470 }
2480 MHD_connection_update_event_loop_info (connection); 2471 MHD_connection_update_event_loop_info (connection);
2481#if EPOLL_SUPPORT 2472#if EPOLL_SUPPORT
2482 switch (connection->event_loop_info) 2473 switch (connection->event_loop_info)
2483 { 2474 {
2484 case MHD_EVENT_LOOP_INFO_READ: 2475 case MHD_EVENT_LOOP_INFO_READ:
@@ -2492,7 +2483,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2492 } 2483 }
2493 break; 2484 break;
2494 case MHD_EVENT_LOOP_INFO_WRITE: 2485 case MHD_EVENT_LOOP_INFO_WRITE:
2495 if ( (connection->read_buffer_size > connection->read_buffer_offset) && 2486 if ( (connection->read_buffer_size > connection->read_buffer_offset) &&
2496 (0 != (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) && 2487 (0 != (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) &&
2497 (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) ) 2488 (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) )
2498 { 2489 {
@@ -2517,7 +2508,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2517 { 2508 {
2518 EDLL_insert (daemon->eready_head, 2509 EDLL_insert (daemon->eready_head,
2519 daemon->eready_tail, 2510 daemon->eready_tail,
2520 connection); 2511 connection);
2521 connection->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL; 2512 connection->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
2522 } 2513 }
2523 break; 2514 break;
@@ -2540,13 +2531,13 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2540 * @param connection connection to process 2531 * @param connection connection to process
2541 * @return #MHD_YES if we should continue to process the 2532 * @return #MHD_YES if we should continue to process the
2542 * connection (not dead yet), #MHD_NO if it died 2533 * connection (not dead yet), #MHD_NO if it died
2543 */ 2534 */
2544int 2535int
2545MHD_connection_epoll_update_ (struct MHD_Connection *connection) 2536MHD_connection_epoll_update_ (struct MHD_Connection *connection)
2546{ 2537{
2547 struct MHD_Daemon *daemon = connection->daemon; 2538 struct MHD_Daemon *daemon = connection->daemon;
2548 2539
2549 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && 2540 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
2550 (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) && 2541 (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) &&
2551 ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_WRITE_READY)) || 2542 ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_WRITE_READY)) ||
2552 ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) && 2543 ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) &&
@@ -2558,7 +2549,7 @@ MHD_connection_epoll_update_ (struct MHD_Connection *connection)
2558 struct epoll_event event; 2549 struct epoll_event event;
2559 2550
2560 event.events = EPOLLIN | EPOLLOUT | EPOLLET; 2551 event.events = EPOLLIN | EPOLLOUT | EPOLLET;
2561 event.data.ptr = connection; 2552 event.data.ptr = connection;
2562 if (0 != epoll_ctl (daemon->epoll_fd, 2553 if (0 != epoll_ctl (daemon->epoll_fd,
2563 EPOLL_CTL_ADD, 2554 EPOLL_CTL_ADD,
2564 connection->socket_fd, 2555 connection->socket_fd,
@@ -2566,8 +2557,8 @@ MHD_connection_epoll_update_ (struct MHD_Connection *connection)
2566 { 2557 {
2567#if HAVE_MESSAGES 2558#if HAVE_MESSAGES
2568 if (0 != (daemon->options & MHD_USE_DEBUG)) 2559 if (0 != (daemon->options & MHD_USE_DEBUG))
2569 MHD_DLOG (daemon, 2560 MHD_DLOG (daemon,
2570 "Call to epoll_ctl failed: %s\n", 2561 "Call to epoll_ctl failed: %s\n",
2571 STRERROR (errno)); 2562 STRERROR (errno));
2572#endif 2563#endif
2573 connection->state = MHD_CONNECTION_CLOSED; 2564 connection->state = MHD_CONNECTION_CLOSED;
@@ -2649,7 +2640,7 @@ MHD_get_connection_info (struct MHD_Connection *connection,
2649 * @return #MHD_YES on success, #MHD_NO if setting the option failed 2640 * @return #MHD_YES on success, #MHD_NO if setting the option failed
2650 * @ingroup specialized 2641 * @ingroup specialized
2651 */ 2642 */
2652int 2643int
2653MHD_set_connection_option (struct MHD_Connection *connection, 2644MHD_set_connection_option (struct MHD_Connection *connection,
2654 enum MHD_CONNECTION_OPTION option, 2645 enum MHD_CONNECTION_OPTION option,
2655 ...) 2646 ...)
@@ -2657,13 +2648,13 @@ MHD_set_connection_option (struct MHD_Connection *connection,
2657 va_list ap; 2648 va_list ap;
2658 struct MHD_Daemon *daemon; 2649 struct MHD_Daemon *daemon;
2659 2650
2660 daemon = connection->daemon; 2651 daemon = connection->daemon;
2661 switch (option) 2652 switch (option)
2662 { 2653 {
2663 case MHD_CONNECTION_OPTION_TIMEOUT: 2654 case MHD_CONNECTION_OPTION_TIMEOUT:
2664 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2655 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2665 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 2656 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
2666 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 2657 MHD_PANIC ("Failed to acquire cleanup mutex\n");
2667 if (connection->connection_timeout == daemon->connection_timeout) 2658 if (connection->connection_timeout == daemon->connection_timeout)
2668 XDLL_remove (daemon->normal_timeout_head, 2659 XDLL_remove (daemon->normal_timeout_head,
2669 daemon->normal_timeout_tail, 2660 daemon->normal_timeout_tail,
@@ -2685,7 +2676,7 @@ MHD_set_connection_option (struct MHD_Connection *connection,
2685 connection); 2676 connection);
2686 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2677 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2687 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 2678 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
2688 MHD_PANIC ("Failed to release cleanup mutex\n"); 2679 MHD_PANIC ("Failed to release cleanup mutex\n");
2689 return MHD_YES; 2680 return MHD_YES;
2690 default: 2681 default:
2691 return MHD_NO; 2682 return MHD_NO;
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 70741fba..61416a7b 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -104,7 +104,7 @@
104 * @param line line number with the problem 104 * @param line line number with the problem
105 * @param reason error message with details 105 * @param reason error message with details
106 */ 106 */
107static void 107static void
108mhd_panic_std (void *cls, 108mhd_panic_std (void *cls,
109 const char *file, 109 const char *file,
110 unsigned int line, 110 unsigned int line,
@@ -133,7 +133,7 @@ void *mhd_panic_cls;
133 * Trace up to and return master daemon. If the supplied daemon 133 * Trace up to and return master daemon. If the supplied daemon
134 * is a master, then return the daemon itself. 134 * is a master, then return the daemon itself.
135 * 135 *
136 * @param daemon handle to a daemon 136 * @param daemon handle to a daemon
137 * @return master daemon handle 137 * @return master daemon handle
138 */ 138 */
139static struct MHD_Daemon* 139static struct MHD_Daemon*
@@ -162,12 +162,12 @@ struct MHD_IPCount
162 { 162 {
163 /** 163 /**
164 * IPv4 address. 164 * IPv4 address.
165 */ 165 */
166 struct in_addr ipv4; 166 struct in_addr ipv4;
167#if HAVE_IPV6 167#if HAVE_IPV6
168 /** 168 /**
169 * IPv6 address. 169 * IPv6 address.
170 */ 170 */
171 struct in6_addr ipv6; 171 struct in6_addr ipv6;
172#endif 172#endif
173 } addr; 173 } addr;
@@ -213,7 +213,7 @@ MHD_ip_count_unlock (struct MHD_Daemon *daemon)
213 * Tree comparison function for IP addresses (supplied to tsearch() family). 213 * Tree comparison function for IP addresses (supplied to tsearch() family).
214 * We compare everything in the struct up through the beginning of the 214 * We compare everything in the struct up through the beginning of the
215 * 'count' field. 215 * 'count' field.
216 * 216 *
217 * @param a1 first address to compare 217 * @param a1 first address to compare
218 * @param a2 second address to compare 218 * @param a2 second address to compare
219 * @return -1, 0 or 1 depending on result of compare 219 * @return -1, 0 or 1 depending on result of compare
@@ -234,7 +234,7 @@ MHD_ip_addr_compare (const void *a1, const void *a2)
234 * @return #MHD_YES on success and #MHD_NO otherwise (e.g., invalid address type) 234 * @return #MHD_YES on success and #MHD_NO otherwise (e.g., invalid address type)
235 */ 235 */
236static int 236static int
237MHD_ip_addr_to_key (const struct sockaddr *addr, 237MHD_ip_addr_to_key (const struct sockaddr *addr,
238 socklen_t addrlen, 238 socklen_t addrlen,
239 struct MHD_IPCount *key) 239 struct MHD_IPCount *key)
240{ 240{
@@ -302,14 +302,14 @@ MHD_ip_limit_add (struct MHD_Daemon *daemon,
302 MHD_ip_count_lock (daemon); 302 MHD_ip_count_lock (daemon);
303 303
304 /* Search for the IP address */ 304 /* Search for the IP address */
305 if (NULL == (nodep = TSEARCH (key, 305 if (NULL == (nodep = TSEARCH (key,
306 &daemon->per_ip_connection_count, 306 &daemon->per_ip_connection_count,
307 &MHD_ip_addr_compare))) 307 &MHD_ip_addr_compare)))
308 { 308 {
309#if HAVE_MESSAGES 309#if HAVE_MESSAGES
310 MHD_DLOG (daemon, 310 MHD_DLOG (daemon,
311 "Failed to add IP connection count node\n"); 311 "Failed to add IP connection count node\n");
312#endif 312#endif
313 MHD_ip_count_unlock (daemon); 313 MHD_ip_count_unlock (daemon);
314 free (key); 314 free (key);
315 return MHD_NO; 315 return MHD_NO;
@@ -358,10 +358,10 @@ MHD_ip_limit_del (struct MHD_Daemon *daemon,
358 MHD_ip_count_lock (daemon); 358 MHD_ip_count_lock (daemon);
359 359
360 /* Search for the IP address */ 360 /* Search for the IP address */
361 if (NULL == (nodep = TFIND (&search_key, 361 if (NULL == (nodep = TFIND (&search_key,
362 &daemon->per_ip_connection_count, 362 &daemon->per_ip_connection_count,
363 &MHD_ip_addr_compare))) 363 &MHD_ip_addr_compare)))
364 { 364 {
365 /* Something's wrong if we couldn't find an IP address 365 /* Something's wrong if we couldn't find an IP address
366 * that was previously added */ 366 * that was previously added */
367 MHD_PANIC ("Failed to find previously-added IP address\n"); 367 MHD_PANIC ("Failed to find previously-added IP address\n");
@@ -375,8 +375,8 @@ MHD_ip_limit_del (struct MHD_Daemon *daemon,
375 /* Remove the node entirely if count reduces to 0 */ 375 /* Remove the node entirely if count reduces to 0 */
376 if (0 == --found_key->count) 376 if (0 == --found_key->count)
377 { 377 {
378 TDELETE (found_key, 378 TDELETE (found_key,
379 &daemon->per_ip_connection_count, 379 &daemon->per_ip_connection_count,
380 &MHD_ip_addr_compare); 380 &MHD_ip_addr_compare);
381 free (found_key); 381 free (found_key);
382 } 382 }
@@ -409,7 +409,7 @@ recv_tls_adapter (struct MHD_Connection *connection, void *other, size_t i)
409 (GNUTLS_E_INTERRUPTED == res) ) 409 (GNUTLS_E_INTERRUPTED == res) )
410 { 410 {
411 errno = EINTR; 411 errno = EINTR;
412#if EPOLL_SUPPORT 412#if EPOLL_SUPPORT
413 connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY; 413 connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
414#endif 414#endif
415 return -1; 415 return -1;
@@ -451,7 +451,7 @@ send_tls_adapter (struct MHD_Connection *connection,
451 { 451 {
452 fprintf (stderr, "WAGAIN!\n"); 452 fprintf (stderr, "WAGAIN!\n");
453 errno = EINTR; 453 errno = EINTR;
454#if EPOLL_SUPPORT 454#if EPOLL_SUPPORT
455 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; 455 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
456#endif 456#endif
457 return -1; 457 return -1;
@@ -472,12 +472,12 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon)
472 gnutls_datum_t key; 472 gnutls_datum_t key;
473 gnutls_datum_t cert; 473 gnutls_datum_t cert;
474 474
475 if (NULL != daemon->https_mem_trust) 475 if (NULL != daemon->https_mem_trust)
476 { 476 {
477 cert.data = (unsigned char *) daemon->https_mem_trust; 477 cert.data = (unsigned char *) daemon->https_mem_trust;
478 cert.size = strlen (daemon->https_mem_trust); 478 cert.size = strlen (daemon->https_mem_trust);
479 if (gnutls_certificate_set_x509_trust_mem (daemon->x509_cred, &cert, 479 if (gnutls_certificate_set_x509_trust_mem (daemon->x509_cred, &cert,
480 GNUTLS_X509_FMT_PEM) < 0) 480 GNUTLS_X509_FMT_PEM) < 0)
481 { 481 {
482#if HAVE_MESSAGES 482#if HAVE_MESSAGES
483 MHD_DLOG(daemon, 483 MHD_DLOG(daemon,
@@ -486,9 +486,9 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon)
486 return -1; 486 return -1;
487 } 487 }
488 } 488 }
489 489
490 /* certificate & key loaded from memory */ 490 /* certificate & key loaded from memory */
491 if ( (NULL != daemon->https_mem_cert) && 491 if ( (NULL != daemon->https_mem_cert) &&
492 (NULL != daemon->https_mem_key) ) 492 (NULL != daemon->https_mem_key) )
493 { 493 {
494 key.data = (unsigned char *) daemon->https_mem_key; 494 key.data = (unsigned char *) daemon->https_mem_key;
@@ -544,8 +544,8 @@ MHD_TLS_init (struct MHD_Daemon *daemon)
544 * @param max_fd maximum value to potentially update 544 * @param max_fd maximum value to potentially update
545 */ 545 */
546static void 546static void
547add_to_fd_set (int fd, 547add_to_fd_set (int fd,
548 fd_set *set, 548 fd_set *set,
549 int *max_fd) 549 int *max_fd)
550{ 550{
551 FD_SET (fd, set); 551 FD_SET (fd, set);
@@ -572,17 +572,17 @@ add_to_fd_set (int fd,
572int 572int
573MHD_get_fdset (struct MHD_Daemon *daemon, 573MHD_get_fdset (struct MHD_Daemon *daemon,
574 fd_set *read_fd_set, 574 fd_set *read_fd_set,
575 fd_set *write_fd_set, 575 fd_set *write_fd_set,
576 fd_set *except_fd_set, 576 fd_set *except_fd_set,
577 int *max_fd) 577 int *max_fd)
578{ 578{
579 struct MHD_Connection *pos; 579 struct MHD_Connection *pos;
580 int fd; 580 int fd;
581 581
582 if ( (NULL == daemon) 582 if ( (NULL == daemon)
583 || (NULL == read_fd_set) 583 || (NULL == read_fd_set)
584 || (NULL == write_fd_set) 584 || (NULL == write_fd_set)
585 || (NULL == except_fd_set) 585 || (NULL == except_fd_set)
586 || (NULL == max_fd) 586 || (NULL == max_fd)
587 || (MHD_YES == daemon->shutdown) 587 || (MHD_YES == daemon->shutdown)
588 || (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 588 || (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
@@ -597,7 +597,7 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
597 if (daemon->epoll_fd >= FD_SETSIZE) 597 if (daemon->epoll_fd >= FD_SETSIZE)
598 return MHD_NO; /* poll fd too big, fail hard */ 598 return MHD_NO; /* poll fd too big, fail hard */
599 FD_SET (daemon->epoll_fd, read_fd_set); 599 FD_SET (daemon->epoll_fd, read_fd_set);
600 if ((*max_fd) < daemon->epoll_fd) 600 if ((*max_fd) < daemon->epoll_fd)
601 *max_fd = daemon->epoll_fd; 601 *max_fd = daemon->epoll_fd;
602 return MHD_YES; 602 return MHD_YES;
603 } 603 }
@@ -607,7 +607,7 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
607 { 607 {
608 FD_SET (fd, read_fd_set); 608 FD_SET (fd, read_fd_set);
609 /* update max file descriptor */ 609 /* update max file descriptor */
610 if ((*max_fd) < fd) 610 if ((*max_fd) < fd)
611 *max_fd = fd; 611 *max_fd = fd;
612 } 612 }
613 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) 613 for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
@@ -643,7 +643,7 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
643/** 643/**
644 * Main function of the thread that handles an individual 644 * Main function of the thread that handles an individual
645 * connection when #MHD_USE_THREAD_PER_CONNECTION is set. 645 * connection when #MHD_USE_THREAD_PER_CONNECTION is set.
646 * 646 *
647 * @param data the 'struct MHD_Connection' this thread will handle 647 * @param data the 'struct MHD_Connection' this thread will handle
648 * @return always NULL 648 * @return always NULL
649 */ 649 */
@@ -664,8 +664,8 @@ MHD_handle_connection (void *data)
664#endif 664#endif
665 665
666 timeout = con->daemon->connection_timeout; 666 timeout = con->daemon->connection_timeout;
667 while ( (MHD_YES != con->daemon->shutdown) && 667 while ( (MHD_YES != con->daemon->shutdown) &&
668 (MHD_CONNECTION_CLOSED != con->state) ) 668 (MHD_CONNECTION_CLOSED != con->state) )
669 { 669 {
670 tvp = NULL; 670 tvp = NULL;
671 if (timeout > 0) 671 if (timeout > 0)
@@ -715,13 +715,13 @@ MHD_handle_connection (void *data)
715 goto exit; 715 goto exit;
716 } 716 }
717 num_ready = SELECT (max + 1, &rs, &ws, NULL, tvp); 717 num_ready = SELECT (max + 1, &rs, &ws, NULL, tvp);
718 if (num_ready < 0) 718 if (num_ready < 0)
719 { 719 {
720 if (EINTR == errno) 720 if (EINTR == errno)
721 continue; 721 continue;
722#if HAVE_MESSAGES 722#if HAVE_MESSAGES
723 MHD_DLOG (con->daemon, 723 MHD_DLOG (con->daemon,
724 "Error during select (%d): `%s'\n", 724 "Error during select (%d): `%s'\n",
725 max, 725 max,
726 STRERROR (errno)); 726 STRERROR (errno));
727#endif 727#endif
@@ -730,7 +730,7 @@ MHD_handle_connection (void *data)
730 /* call appropriate connection handler if necessary */ 730 /* call appropriate connection handler if necessary */
731 if ( (FD_ISSET (con->socket_fd, &rs)) 731 if ( (FD_ISSET (con->socket_fd, &rs))
732#if HTTPS_SUPPORT 732#if HTTPS_SUPPORT
733 || (MHD_YES == con->tls_read_ready) 733 || (MHD_YES == con->tls_read_ready)
734#endif 734#endif
735 ) 735 )
736 con->read_handler (con); 736 con->read_handler (con);
@@ -748,16 +748,16 @@ MHD_handle_connection (void *data)
748 switch (con->event_loop_info) 748 switch (con->event_loop_info)
749 { 749 {
750 case MHD_EVENT_LOOP_INFO_READ: 750 case MHD_EVENT_LOOP_INFO_READ:
751 p[0].events |= POLLIN; 751 p[0].events |= POLLIN;
752 break; 752 break;
753 case MHD_EVENT_LOOP_INFO_WRITE: 753 case MHD_EVENT_LOOP_INFO_WRITE:
754 p[0].events |= POLLOUT; 754 p[0].events |= POLLOUT;
755 if (con->read_buffer_size > con->read_buffer_offset) 755 if (con->read_buffer_size > con->read_buffer_offset)
756 p[0].events |= POLLIN; 756 p[0].events |= POLLIN;
757 break; 757 break;
758 case MHD_EVENT_LOOP_INFO_BLOCK: 758 case MHD_EVENT_LOOP_INFO_BLOCK:
759 if (con->read_buffer_size > con->read_buffer_offset) 759 if (con->read_buffer_size > con->read_buffer_offset)
760 p[0].events |= POLLIN; 760 p[0].events |= POLLIN;
761 tv.tv_sec = 0; 761 tv.tv_sec = 0;
762 tv.tv_usec = 0; 762 tv.tv_usec = 0;
763 tvp = &tv; 763 tvp = &tv;
@@ -766,27 +766,27 @@ MHD_handle_connection (void *data)
766 /* how did we get here!? */ 766 /* how did we get here!? */
767 goto exit; 767 goto exit;
768 } 768 }
769 if (poll (p, 1, 769 if (poll (p, 1,
770 (NULL == tvp) ? -1 : tv.tv_sec * 1000) < 0) 770 (NULL == tvp) ? -1 : tv.tv_sec * 1000) < 0)
771 { 771 {
772 if (EINTR == errno) 772 if (EINTR == errno)
773 continue; 773 continue;
774#if HAVE_MESSAGES 774#if HAVE_MESSAGES
775 MHD_DLOG (con->daemon, "Error during poll: `%s'\n", 775 MHD_DLOG (con->daemon, "Error during poll: `%s'\n",
776 STRERROR (errno)); 776 STRERROR (errno));
777#endif 777#endif
778 break; 778 break;
779 } 779 }
780 if ( (0 != (p[0].revents & POLLIN)) 780 if ( (0 != (p[0].revents & POLLIN))
781#if HTTPS_SUPPORT 781#if HTTPS_SUPPORT
782 || (MHD_YES == con->tls_read_ready) 782 || (MHD_YES == con->tls_read_ready)
783#endif 783#endif
784 ) 784 )
785 con->read_handler (con); 785 con->read_handler (con);
786 if (0 != (p[0].revents & POLLOUT)) 786 if (0 != (p[0].revents & POLLOUT))
787 con->write_handler (con); 787 con->write_handler (con);
788 if (0 != (p[0].revents & (POLLERR | POLLHUP))) 788 if (0 != (p[0].revents & (POLLERR | POLLHUP)))
789 MHD_connection_close (con, MHD_REQUEST_TERMINATED_WITH_ERROR); 789 MHD_connection_close (con, MHD_REQUEST_TERMINATED_WITH_ERROR);
790 if (MHD_NO == con->idle_handler (con)) 790 if (MHD_NO == con->idle_handler (con))
791 goto exit; 791 goto exit;
792 } 792 }
@@ -801,7 +801,7 @@ MHD_handle_connection (void *data)
801#endif 801#endif
802#endif 802#endif
803 if (MHD_CONNECTION_CLOSED != con->state) 803 if (MHD_CONNECTION_CLOSED != con->state)
804 MHD_connection_close (con, 804 MHD_connection_close (con,
805 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN); 805 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN);
806 con->idle_handler (con); 806 con->idle_handler (con);
807 } 807 }
@@ -825,7 +825,7 @@ exit:
825 */ 825 */
826static ssize_t 826static ssize_t
827recv_param_adapter (struct MHD_Connection *connection, 827recv_param_adapter (struct MHD_Connection *connection,
828 void *other, 828 void *other,
829 size_t i) 829 size_t i)
830{ 830{
831 ssize_t ret; 831 ssize_t ret;
@@ -887,7 +887,7 @@ send_param_adapter (struct MHD_Connection *connection,
887 left = connection->response->total_size - connection->response_write_position; 887 left = connection->response->total_size - connection->response_write_position;
888 if (left > SSIZE_MAX) 888 if (left > SSIZE_MAX)
889 left = SSIZE_MAX; /* cap at return value limit */ 889 left = SSIZE_MAX; /* cap at return value limit */
890 if (-1 != (ret = sendfile (connection->socket_fd, 890 if (-1 != (ret = sendfile (connection->socket_fd,
891 fd, 891 fd,
892 &offset, 892 &offset,
893 (size_t) left))) 893 (size_t) left)))
@@ -904,7 +904,7 @@ send_param_adapter (struct MHD_Connection *connection,
904 if ( (EINTR == errno) || (EAGAIN == errno) ) 904 if ( (EINTR == errno) || (EAGAIN == errno) )
905 return 0; 905 return 0;
906 if ( (EINVAL == errno) || (EBADF == errno) ) 906 if ( (EINVAL == errno) || (EBADF == errno) )
907 return -1; 907 return -1;
908 /* None of the 'usual' sendfile errors occurred, so we should try 908 /* None of the 'usual' sendfile errors occurred, so we should try
909 to fall back to 'SEND'; see also this thread for info on 909 to fall back to 'SEND'; see also this thread for info on
910 odd libc/Linux behavior with sendfile: 910 odd libc/Linux behavior with sendfile:
@@ -934,7 +934,7 @@ typedef void *(*ThreadStartRoutine)(void *cls);
934 934
935/** 935/**
936 * Create a thread and set the attributes according to our options. 936 * Create a thread and set the attributes according to our options.
937 * 937 *
938 * @param thread handle to initialize 938 * @param thread handle to initialize
939 * @param daemon daemon with options 939 * @param daemon daemon with options
940 * @param start_routine main function of thread 940 * @param start_routine main function of thread
@@ -950,10 +950,10 @@ create_thread (pthread_t *thread,
950 pthread_attr_t attr; 950 pthread_attr_t attr;
951 pthread_attr_t *pattr; 951 pthread_attr_t *pattr;
952 int ret; 952 int ret;
953 953
954 if (0 != daemon->thread_stack_size) 954 if (0 != daemon->thread_stack_size)
955 { 955 {
956 if (0 != (ret = pthread_attr_init (&attr))) 956 if (0 != (ret = pthread_attr_init (&attr)))
957 goto ERR; 957 goto ERR;
958 if (0 != (ret = pthread_attr_setstacksize (&attr, daemon->thread_stack_size))) 958 if (0 != (ret = pthread_attr_setstacksize (&attr, daemon->thread_stack_size)))
959 { 959 {
@@ -973,7 +973,7 @@ create_thread (pthread_t *thread,
973 (void) pthread_setname_np (*thread, "libmicrohttpd"); 973 (void) pthread_setname_np (*thread, "libmicrohttpd");
974#endif 974#endif
975#endif 975#endif
976 if (0 != daemon->thread_stack_size) 976 if (0 != daemon->thread_stack_size)
977 pthread_attr_destroy (&attr); 977 pthread_attr_destroy (&attr);
978 return ret; 978 return ret;
979 ERR: 979 ERR:
@@ -987,11 +987,11 @@ create_thread (pthread_t *thread,
987 987
988 988
989/** 989/**
990 * Add another client connection to the set of connections 990 * Add another client connection to the set of connections
991 * managed by MHD. This API is usually not needed (since 991 * managed by MHD. This API is usually not needed (since
992 * MHD will accept inbound connections on the server socket). 992 * MHD will accept inbound connections on the server socket).
993 * Use this API in special cases, for example if your HTTP 993 * Use this API in special cases, for example if your HTTP
994 * server is behind NAT and needs to connect out to the 994 * server is behind NAT and needs to connect out to the
995 * HTTP client. 995 * HTTP client.
996 * 996 *
997 * The given client socket will be managed (and closed!) by MHD after 997 * The given client socket will be managed (and closed!) by MHD after
@@ -1012,8 +1012,8 @@ create_thread (pthread_t *thread,
1012 * The socket will be closed in any case; 'errno' is 1012 * The socket will be closed in any case; 'errno' is
1013 * set to indicate further details about the error. 1013 * set to indicate further details about the error.
1014 */ 1014 */
1015static int 1015static int
1016internal_add_connection (struct MHD_Daemon *daemon, 1016internal_add_connection (struct MHD_Daemon *daemon,
1017 int client_socket, 1017 int client_socket,
1018 const struct sockaddr *addr, 1018 const struct sockaddr *addr,
1019 socklen_t addrlen, 1019 socklen_t addrlen,
@@ -1025,7 +1025,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1025 int eno; 1025 int eno;
1026#if OSX 1026#if OSX
1027 static int on = 1; 1027 static int on = 1;
1028#endif 1028#endif
1029 1029
1030 if (NULL != daemon->worker_pool) 1030 if (NULL != daemon->worker_pool)
1031 { 1031 {
@@ -1044,7 +1044,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1044#if ENFILE 1044#if ENFILE
1045 errno = ENFILE; 1045 errno = ENFILE;
1046#endif 1046#endif
1047 return MHD_NO; 1047 return MHD_NO;
1048 } 1048 }
1049 1049
1050#ifndef WINDOWS 1050#ifndef WINDOWS
@@ -1089,8 +1089,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
1089 } 1089 }
1090 1090
1091 /* apply connection acceptance policy if present */ 1091 /* apply connection acceptance policy if present */
1092 if ( (NULL != daemon->apc) && 1092 if ( (NULL != daemon->apc) &&
1093 (MHD_NO == daemon->apc (daemon->apc_cls, 1093 (MHD_NO == daemon->apc (daemon->apc_cls,
1094 addr, addrlen)) ) 1094 addr, addrlen)) )
1095 { 1095 {
1096#if DEBUG_CLOSE 1096#if DEBUG_CLOSE
@@ -1110,8 +1110,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
1110#if OSX 1110#if OSX
1111#ifdef SOL_SOCKET 1111#ifdef SOL_SOCKET
1112#ifdef SO_NOSIGPIPE 1112#ifdef SO_NOSIGPIPE
1113 setsockopt (client_socket, 1113 setsockopt (client_socket,
1114 SOL_SOCKET, SO_NOSIGPIPE, 1114 SOL_SOCKET, SO_NOSIGPIPE,
1115 &on, sizeof (on)); 1115 &on, sizeof (on));
1116#endif 1116#endif
1117#endif 1117#endif
@@ -1121,8 +1121,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
1121 { 1121 {
1122 eno = errno; 1122 eno = errno;
1123#if HAVE_MESSAGES 1123#if HAVE_MESSAGES
1124 MHD_DLOG (daemon, 1124 MHD_DLOG (daemon,
1125 "Error allocating memory: %s\n", 1125 "Error allocating memory: %s\n",
1126 STRERROR (errno)); 1126 STRERROR (errno));
1127#endif 1127#endif
1128 if (0 != CLOSE (client_socket)) 1128 if (0 != CLOSE (client_socket))
@@ -1136,14 +1136,14 @@ internal_add_connection (struct MHD_Daemon *daemon,
1136 if (NULL == connection->pool) 1136 if (NULL == connection->pool)
1137 { 1137 {
1138#if HAVE_MESSAGES 1138#if HAVE_MESSAGES
1139 MHD_DLOG (daemon, 1139 MHD_DLOG (daemon,
1140 "Error allocating memory: %s\n", 1140 "Error allocating memory: %s\n",
1141 STRERROR (errno)); 1141 STRERROR (errno));
1142#endif 1142#endif
1143 if (0 != CLOSE (client_socket)) 1143 if (0 != CLOSE (client_socket))
1144 MHD_PANIC ("close failed\n"); 1144 MHD_PANIC ("close failed\n");
1145 MHD_ip_limit_del (daemon, addr, addrlen); 1145 MHD_ip_limit_del (daemon, addr, addrlen);
1146 free (connection); 1146 free (connection);
1147#if ENOMEM 1147#if ENOMEM
1148 errno = ENOMEM; 1148 errno = ENOMEM;
1149#endif 1149#endif
@@ -1155,8 +1155,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
1155 { 1155 {
1156 eno = errno; 1156 eno = errno;
1157#if HAVE_MESSAGES 1157#if HAVE_MESSAGES
1158 MHD_DLOG (daemon, 1158 MHD_DLOG (daemon,
1159 "Error allocating memory: %s\n", 1159 "Error allocating memory: %s\n",
1160 STRERROR (errno)); 1160 STRERROR (errno));
1161#endif 1161#endif
1162 if (0 != CLOSE (client_socket)) 1162 if (0 != CLOSE (client_socket))
@@ -1172,7 +1172,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1172 connection->socket_fd = client_socket; 1172 connection->socket_fd = client_socket;
1173 connection->daemon = daemon; 1173 connection->daemon = daemon;
1174 connection->last_activity = MHD_monotonic_time(); 1174 connection->last_activity = MHD_monotonic_time();
1175 1175
1176 /* set default connection handlers */ 1176 /* set default connection handlers */
1177 MHD_set_http_callbacks_ (connection); 1177 MHD_set_http_callbacks_ (connection);
1178 connection->recv_cls = &recv_param_adapter; 1178 connection->recv_cls = &recv_param_adapter;
@@ -1196,7 +1196,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1196 { 1196 {
1197#if HAVE_MESSAGES 1197#if HAVE_MESSAGES
1198 MHD_DLOG (daemon, 1198 MHD_DLOG (daemon,
1199 "Failed to make socket %d non-blocking: %s\n", 1199 "Failed to make socket %d non-blocking: %s\n",
1200 connection->socket_fd, 1200 connection->socket_fd,
1201 STRERROR (errno)); 1201 STRERROR (errno));
1202#endif 1202#endif
@@ -1206,8 +1206,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
1206 if (0 != ioctlsocket (connection->socket_fd, FIONBIO, &flags)) 1206 if (0 != ioctlsocket (connection->socket_fd, FIONBIO, &flags))
1207 { 1207 {
1208#if HAVE_MESSAGES 1208#if HAVE_MESSAGES
1209 MHD_DLOG (daemon, 1209 MHD_DLOG (daemon,
1210 "Failed to make socket non-blocking: %s\n", 1210 "Failed to make socket non-blocking: %s\n",
1211 STRERROR (errno)); 1211 STRERROR (errno));
1212#endif 1212#endif
1213 } 1213 }
@@ -1258,14 +1258,14 @@ internal_add_connection (struct MHD_Daemon *daemon,
1258 (gnutls_push_func) &send_param_adapter); 1258 (gnutls_push_func) &send_param_adapter);
1259 1259
1260 if (daemon->https_mem_trust) 1260 if (daemon->https_mem_trust)
1261 gnutls_certificate_server_set_request (connection->tls_session, 1261 gnutls_certificate_server_set_request (connection->tls_session,
1262 GNUTLS_CERT_REQUEST); 1262 GNUTLS_CERT_REQUEST);
1263 } 1263 }
1264#endif 1264#endif
1265 1265
1266 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1266 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1267 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 1267 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
1268 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1268 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1269 XDLL_insert (daemon->normal_timeout_head, 1269 XDLL_insert (daemon->normal_timeout_head,
1270 daemon->normal_timeout_tail, 1270 daemon->normal_timeout_tail,
1271 connection); 1271 connection);
@@ -1274,7 +1274,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1274 connection); 1274 connection);
1275 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1275 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1276 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 1276 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
1277 MHD_PANIC ("Failed to release cleanup mutex\n"); 1277 MHD_PANIC ("Failed to release cleanup mutex\n");
1278 1278
1279 /* attempt to create handler thread */ 1279 /* attempt to create handler thread */
1280 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 1280 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
@@ -1307,9 +1307,9 @@ internal_add_connection (struct MHD_Daemon *daemon,
1307 if (0 == (daemon->options & MHD_USE_EPOLL_TURBO)) 1307 if (0 == (daemon->options & MHD_USE_EPOLL_TURBO))
1308 { 1308 {
1309 struct epoll_event event; 1309 struct epoll_event event;
1310 1310
1311 event.events = EPOLLIN | EPOLLOUT | EPOLLET; 1311 event.events = EPOLLIN | EPOLLOUT | EPOLLET;
1312 event.data.ptr = connection; 1312 event.data.ptr = connection;
1313 if (0 != epoll_ctl (daemon->epoll_fd, 1313 if (0 != epoll_ctl (daemon->epoll_fd,
1314 EPOLL_CTL_ADD, 1314 EPOLL_CTL_ADD,
1315 client_socket, 1315 client_socket,
@@ -1317,10 +1317,9 @@ internal_add_connection (struct MHD_Daemon *daemon,
1317 { 1317 {
1318 eno = errno; 1318 eno = errno;
1319#if HAVE_MESSAGES 1319#if HAVE_MESSAGES
1320 if (0 != (daemon->options & MHD_USE_DEBUG)) 1320 MHD_DLOG (daemon,
1321 MHD_DLOG (daemon, 1321 "Call to epoll_ctl failed: %s\n",
1322 "Call to epoll_ctl failed: %s\n", 1322 STRERROR (errno));
1323 STRERROR (errno));
1324#endif 1323#endif
1325 goto cleanup; 1324 goto cleanup;
1326 } 1325 }
@@ -1336,15 +1335,15 @@ internal_add_connection (struct MHD_Daemon *daemon,
1336 } 1335 }
1337 } 1336 }
1338#endif 1337#endif
1339 daemon->max_connections--; 1338 daemon->max_connections--;
1340 return MHD_YES; 1339 return MHD_YES;
1341 cleanup: 1340 cleanup:
1342 if (0 != CLOSE (client_socket)) 1341 if (0 != CLOSE (client_socket))
1343 MHD_PANIC ("close failed\n"); 1342 MHD_PANIC ("close failed\n");
1344 MHD_ip_limit_del (daemon, addr, addrlen); 1343 MHD_ip_limit_del (daemon, addr, addrlen);
1345 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1344 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1346 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 1345 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
1347 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1346 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1348 DLL_remove (daemon->connections_head, 1347 DLL_remove (daemon->connections_head,
1349 daemon->connections_tail, 1348 daemon->connections_tail,
1350 connection); 1349 connection);
@@ -1354,7 +1353,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1354 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1353 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1355 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 1354 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
1356 MHD_PANIC ("Failed to release cleanup mutex\n"); 1355 MHD_PANIC ("Failed to release cleanup mutex\n");
1357 MHD_pool_destroy (connection->pool); 1356 MHD_pool_destroy (connection->pool);
1358 free (connection->addr); 1357 free (connection->addr);
1359 free (connection); 1358 free (connection);
1360#if EINVAL 1359#if EINVAL
@@ -1365,11 +1364,150 @@ internal_add_connection (struct MHD_Daemon *daemon,
1365 1364
1366 1365
1367/** 1366/**
1367 * Suspend handling of network data for a given connection. This can
1368 * be used to dequeue a connection from MHD's event loop (external
1369 * select, internal select or thread pool; not applicable to
1370 * thread-per-connection!) for a while.
1371 *
1372 * If you use this API in conjunction with a internal select or a
1373 * thread pool, you must set the option #MHD_USE_PIPE_FOR_SHUTDOWN to
1374 * ensure that a resumed connection is immediately processed by MHD.
1375 *
1376 * Suspended connections continue to count against the total number of
1377 * connections allowed (per daemon, as well as per IP, if such limits
1378 * are set). Suspended connections will NOT time out; timeouts will
1379 * restart when the connection handling is resumed. While a
1380 * connection is suspended, MHD will not detect disconnects by the
1381 * client.
1382 *
1383 * The only safe time to suspend a connection is from the
1384 * #MHD_AccessHandlerCallback.
1385 *
1386 * Finally, it is an API violation to call #MHD_stop_daemon while
1387 * having suspended connections (this will at least create memory and
1388 * socket leaks or lead to undefined behavior). You must explicitly
1389 * resume all connections before stopping the daemon.
1390 *
1391 * @param connection the connection to suspend
1392 */
1393void
1394MHD_suspend_connection (struct MHD_Connection *connection)
1395{
1396 struct MHD_Daemon *daemon;
1397
1398 daemon = connection->daemon;
1399 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
1400 MHD_PANIC ("Cannot suspend connections in THREAD_PER_CONNECTION mode!\n");
1401 DLL_remove (daemon->connections_head,
1402 daemon->connections_tail,
1403 connection);
1404 if (connection->connection_timeout == daemon->connection_timeout)
1405 XDLL_remove (daemon->normal_timeout_head,
1406 daemon->normal_timeout_tail,
1407 connection);
1408 else
1409 XDLL_remove (daemon->manual_timeout_head,
1410 daemon->manual_timeout_tail,
1411 connection);
1412#if EPOLL_SUPPORT
1413 if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
1414 {
1415 EDLL_remove (daemon->eready_head,
1416 daemon->eready_tail,
1417 connection);
1418 }
1419 if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET))
1420 {
1421 if (0 != epoll_ctl (daemon->epoll_fd,
1422 EPOLL_CTL_DEL,
1423 connection->socket_fd,
1424 NULL))
1425 MHD_PANIC ("Failed to remove FD from epoll set\n");
1426 connection->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET;
1427 }
1428#endif
1429}
1430
1431
1432/**
1433 * Resume handling of network data for suspended connection. It is
1434 * safe to resume a suspended connection at any time. Calling this function
1435 * on a connection that was not previously suspended will result
1436 * in undefined behavior.
1437 *
1438 * @param connection the connection to resume
1439 */
1440void
1441MHD_resume_connection (struct MHD_Connection *connection)
1442{
1443 struct MHD_Daemon *daemon;
1444
1445 daemon = connection->daemon;
1446 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
1447 MHD_PANIC ("Cannot resume connections in THREAD_PER_CONNECTION mode!\n");
1448 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1449 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
1450 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1451 DLL_insert (daemon->connections_head,
1452 daemon->connections_tail,
1453 connection);
1454 if (connection->connection_timeout == daemon->connection_timeout)
1455 XDLL_insert (daemon->normal_timeout_head,
1456 daemon->normal_timeout_tail,
1457 connection);
1458 else
1459 XDLL_insert (daemon->manual_timeout_head,
1460 daemon->manual_timeout_tail,
1461 connection);
1462#if EPOLL_SUPPORT
1463 if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
1464 {
1465 EDLL_insert (daemon->eready_head,
1466 daemon->eready_tail,
1467 connection);
1468 }
1469 else
1470 {
1471 struct epoll_event event;
1472
1473 event.events = EPOLLIN | EPOLLOUT | EPOLLET;
1474 event.data.ptr = connection;
1475 if (0 != epoll_ctl (daemon->epoll_fd,
1476 EPOLL_CTL_ADD,
1477 connection->socket_fd,
1478 &event))
1479 {
1480#if HAVE_MESSAGES
1481 MHD_DLOG (daemon,
1482 "Call to epoll_ctl failed: %s\n",
1483 STRERROR (errno));
1484#endif
1485 /* and now, good luck with this... */
1486 }
1487 else
1488 connection->epoll_state |= MHD_EPOLL_STATE_IN_EPOLL_SET;
1489 }
1490#endif
1491 if ( (-1 != daemon->wpipe[1]) &&
1492 (1 != WRITE (daemon->wpipe[1], "n", 1)) )
1493 {
1494#if HAVE_MESSAGES
1495 MHD_DLOG (daemon,
1496 "failed to signal resume via pipe");
1497#endif
1498 }
1499 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1500 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
1501 MHD_PANIC ("Failed to release cleanup mutex\n");
1502}
1503
1504
1505/**
1368 * Change socket options to be non-blocking, non-inheritable. 1506 * Change socket options to be non-blocking, non-inheritable.
1369 * 1507 *
1370 * @param daemon daemon context 1508 * @param daemon daemon context
1371 * @param sock socket to manipulate 1509 * @param sock socket to manipulate
1372 */ 1510 */
1373static void 1511static void
1374make_nonblocking_noninheritable (struct MHD_Daemon *daemon, 1512make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
1375 int sock) 1513 int sock)
@@ -1389,12 +1527,12 @@ make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
1389#ifdef WINDOWS 1527#ifdef WINDOWS
1390 DWORD dwFlags; 1528 DWORD dwFlags;
1391 unsigned long flags = 1; 1529 unsigned long flags = 1;
1392 1530
1393 if (0 != ioctlsocket (sock, FIONBIO, &flags)) 1531 if (0 != ioctlsocket (sock, FIONBIO, &flags))
1394 { 1532 {
1395#if HAVE_MESSAGES 1533#if HAVE_MESSAGES
1396 MHD_DLOG (daemon, 1534 MHD_DLOG (daemon,
1397 "Failed to make socket non-blocking: %s\n", 1535 "Failed to make socket non-blocking: %s\n",
1398 STRERROR (errno)); 1536 STRERROR (errno));
1399#endif 1537#endif
1400 } 1538 }
@@ -1405,13 +1543,13 @@ make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
1405#if HAVE_MESSAGES 1543#if HAVE_MESSAGES
1406 SetErrnoFromWinError (GetLastError ()); 1544 SetErrnoFromWinError (GetLastError ());
1407 MHD_DLOG (daemon, 1545 MHD_DLOG (daemon,
1408 "Failed to make socket non-inheritable: %s\n", 1546 "Failed to make socket non-inheritable: %s\n",
1409 STRERROR (errno)); 1547 STRERROR (errno));
1410#endif 1548#endif
1411 } 1549 }
1412#else 1550#else
1413 int flags; 1551 int flags;
1414 1552
1415 nonblock = O_NONBLOCK; 1553 nonblock = O_NONBLOCK;
1416#ifdef CYGWIN 1554#ifdef CYGWIN
1417 if (0 == (daemon->options & MHD_USE_SSL)) 1555 if (0 == (daemon->options & MHD_USE_SSL))
@@ -1424,7 +1562,7 @@ make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
1424 { 1562 {
1425#if HAVE_MESSAGES 1563#if HAVE_MESSAGES
1426 MHD_DLOG (daemon, 1564 MHD_DLOG (daemon,
1427 "Failed to make socket non-inheritable: %s\n", 1565 "Failed to make socket non-inheritable: %s\n",
1428 STRERROR (errno)); 1566 STRERROR (errno));
1429#endif 1567#endif
1430 } 1568 }
@@ -1461,13 +1599,13 @@ make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
1461 * set to indicate further details about the error. 1599 * set to indicate further details about the error.
1462 * @ingroup specialized 1600 * @ingroup specialized
1463 */ 1601 */
1464int 1602int
1465MHD_add_connection (struct MHD_Daemon *daemon, 1603MHD_add_connection (struct MHD_Daemon *daemon,
1466 int client_socket, 1604 int client_socket,
1467 const struct sockaddr *addr, 1605 const struct sockaddr *addr,
1468 socklen_t addrlen) 1606 socklen_t addrlen)
1469{ 1607{
1470 make_nonblocking_noninheritable (daemon, 1608 make_nonblocking_noninheritable (daemon,
1471 client_socket); 1609 client_socket);
1472 return internal_add_connection (daemon, 1610 return internal_add_connection (daemon,
1473 client_socket, 1611 client_socket,
@@ -1480,7 +1618,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1480 * Accept an incoming connection and create the MHD_Connection object for 1618 * Accept an incoming connection and create the MHD_Connection object for
1481 * it. This function also enforces policy by way of checking with the 1619 * it. This function also enforces policy by way of checking with the
1482 * accept policy callback. 1620 * accept policy callback.
1483 * 1621 *
1484 * @param daemon handle with the listen socket 1622 * @param daemon handle with the listen socket
1485 * @return MHD_YES on success (connections denied by policy or due 1623 * @return MHD_YES on success (connections denied by policy or due
1486 * to 'out of memory' and similar errors) are still considered 1624 * to 'out of memory' and similar errors) are still considered
@@ -1525,8 +1663,8 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1525#if HAVE_MESSAGES 1663#if HAVE_MESSAGES
1526 /* This could be a common occurance with multiple worker threads */ 1664 /* This could be a common occurance with multiple worker threads */
1527 if ((EAGAIN != errno) && (EWOULDBLOCK != errno)) 1665 if ((EAGAIN != errno) && (EWOULDBLOCK != errno))
1528 MHD_DLOG (daemon, 1666 MHD_DLOG (daemon,
1529 "Error accepting connection: %s\n", 1667 "Error accepting connection: %s\n",
1530 STRERROR (errno)); 1668 STRERROR (errno));
1531#endif 1669#endif
1532 if (-1 != s) 1670 if (-1 != s)
@@ -1567,7 +1705,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
1567 1705
1568 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1706 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1569 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 1707 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
1570 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1708 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1571 while (NULL != (pos = daemon->cleanup_head)) 1709 while (NULL != (pos = daemon->cleanup_head))
1572 { 1710 {
1573 DLL_remove (daemon->cleanup_head, 1711 DLL_remove (daemon->cleanup_head,
@@ -1575,7 +1713,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
1575 pos); 1713 pos);
1576 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1714 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1577 (MHD_NO == pos->thread_joined) ) 1715 (MHD_NO == pos->thread_joined) )
1578 { 1716 {
1579 if (0 != (rc = pthread_join (pos->pid, &unused))) 1717 if (0 != (rc = pthread_join (pos->pid, &unused)))
1580 { 1718 {
1581 MHD_PANIC ("Failed to join a thread\n"); 1719 MHD_PANIC ("Failed to join a thread\n");
@@ -1586,8 +1724,8 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
1586 if (pos->tls_session != NULL) 1724 if (pos->tls_session != NULL)
1587 gnutls_deinit (pos->tls_session); 1725 gnutls_deinit (pos->tls_session);
1588#endif 1726#endif
1589 MHD_ip_limit_del (daemon, 1727 MHD_ip_limit_del (daemon,
1590 (struct sockaddr *) pos->addr, 1728 (struct sockaddr *) pos->addr,
1591 pos->addr_len); 1729 pos->addr_len);
1592#if EPOLL_SUPPORT 1730#if EPOLL_SUPPORT
1593 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) 1731 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
@@ -1633,9 +1771,9 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
1633 free (pos); 1771 free (pos);
1634 daemon->max_connections++; 1772 daemon->max_connections++;
1635 } 1773 }
1636 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1774 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1637 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 1775 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
1638 MHD_PANIC ("Failed to release cleanup mutex\n"); 1776 MHD_PANIC ("Failed to release cleanup mutex\n");
1639} 1777}
1640 1778
1641 1779
@@ -1666,7 +1804,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
1666 { 1804 {
1667#if HAVE_MESSAGES 1805#if HAVE_MESSAGES
1668 MHD_DLOG (daemon, "Illegal call to MHD_get_timeout\n"); 1806 MHD_DLOG (daemon, "Illegal call to MHD_get_timeout\n");
1669#endif 1807#endif
1670 return MHD_NO; 1808 return MHD_NO;
1671 } 1809 }
1672 1810
@@ -1683,7 +1821,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
1683 have_timeout = MHD_NO; 1821 have_timeout = MHD_NO;
1684 for (pos = daemon->manual_timeout_head; NULL != pos; pos = pos->nextX) 1822 for (pos = daemon->manual_timeout_head; NULL != pos; pos = pos->nextX)
1685 { 1823 {
1686 if (0 != pos->connection_timeout) 1824 if (0 != pos->connection_timeout)
1687 { 1825 {
1688 if ( (! have_timeout) || 1826 if ( (! have_timeout) ||
1689 (earliest_deadline > pos->last_activity + pos->connection_timeout) ) 1827 (earliest_deadline > pos->last_activity + pos->connection_timeout) )
@@ -1743,7 +1881,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
1743 * @ingroup event 1881 * @ingroup event
1744 */ 1882 */
1745int 1883int
1746MHD_run_from_select (struct MHD_Daemon *daemon, 1884MHD_run_from_select (struct MHD_Daemon *daemon,
1747 const fd_set *read_fd_set, 1885 const fd_set *read_fd_set,
1748 const fd_set *write_fd_set, 1886 const fd_set *write_fd_set,
1749 const fd_set *except_fd_set) 1887 const fd_set *except_fd_set)
@@ -1790,7 +1928,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
1790 case MHD_EVENT_LOOP_INFO_READ: 1928 case MHD_EVENT_LOOP_INFO_READ:
1791 if ( (FD_ISSET (ds, read_fd_set)) 1929 if ( (FD_ISSET (ds, read_fd_set))
1792#if HTTPS_SUPPORT 1930#if HTTPS_SUPPORT
1793 || (MHD_YES == pos->tls_read_ready) 1931 || (MHD_YES == pos->tls_read_ready)
1794#endif 1932#endif
1795 ) 1933 )
1796 pos->read_handler (pos); 1934 pos->read_handler (pos);
@@ -1811,7 +1949,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
1811 /* should never happen */ 1949 /* should never happen */
1812 break; 1950 break;
1813 } 1951 }
1814 pos->idle_handler (pos); 1952 pos->idle_handler (pos);
1815 } 1953 }
1816 } 1954 }
1817 MHD_cleanup_connections (daemon); 1955 MHD_cleanup_connections (daemon);
@@ -1828,7 +1966,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
1828 * @return #MHD_NO on serious errors, #MHD_YES on success 1966 * @return #MHD_NO on serious errors, #MHD_YES on success
1829 */ 1967 */
1830static int 1968static int
1831MHD_select (struct MHD_Daemon *daemon, 1969MHD_select (struct MHD_Daemon *daemon,
1832 int may_block) 1970 int may_block)
1833{ 1971{
1834 int num_ready; 1972 int num_ready;
@@ -1856,14 +1994,14 @@ MHD_select (struct MHD_Daemon *daemon,
1856 1994
1857 /* If we're at the connection limit, no need to 1995 /* If we're at the connection limit, no need to
1858 accept new connections. */ 1996 accept new connections. */
1859 if ( (0 == daemon->max_connections) && 1997 if ( (0 == daemon->max_connections) &&
1860 (-1 != daemon->socket_fd) ) 1998 (-1 != daemon->socket_fd) )
1861 FD_CLR (daemon->socket_fd, &rs); 1999 FD_CLR (daemon->socket_fd, &rs);
1862 } 2000 }
1863 else 2001 else
1864 { 2002 {
1865 /* accept only, have one thread per connection */ 2003 /* accept only, have one thread per connection */
1866 if (-1 != daemon->socket_fd) 2004 if (-1 != daemon->socket_fd)
1867 { 2005 {
1868 max = daemon->socket_fd; 2006 max = daemon->socket_fd;
1869 FD_SET (daemon->socket_fd, &rs); 2007 FD_SET (daemon->socket_fd, &rs);
@@ -1938,7 +2076,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
1938 int timeout; 2076 int timeout;
1939 unsigned int poll_server; 2077 unsigned int poll_server;
1940 int poll_listen; 2078 int poll_listen;
1941 2079
1942 memset (p, 0, sizeof (p)); 2080 memset (p, 0, sizeof (p));
1943 poll_server = 0; 2081 poll_server = 0;
1944 poll_listen = -1; 2082 poll_listen = -1;
@@ -1952,7 +2090,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
1952 poll_listen = (int) poll_server; 2090 poll_listen = (int) poll_server;
1953 poll_server++; 2091 poll_server++;
1954 } 2092 }
1955 if (-1 != daemon->wpipe[0]) 2093 if (-1 != daemon->wpipe[0])
1956 { 2094 {
1957 p[poll_server].fd = daemon->wpipe[0]; 2095 p[poll_server].fd = daemon->wpipe[0];
1958 p[poll_server].events = POLLIN; 2096 p[poll_server].events = POLLIN;
@@ -1966,7 +2104,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
1966 timeout = -1; 2104 timeout = -1;
1967 else 2105 else
1968 timeout = (ltimeout > INT_MAX) ? INT_MAX : (int) ltimeout; 2106 timeout = (ltimeout > INT_MAX) ? INT_MAX : (int) ltimeout;
1969 2107
1970 i = 0; 2108 i = 0;
1971 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) 2109 for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
1972 { 2110 {
@@ -1974,16 +2112,16 @@ MHD_poll_all (struct MHD_Daemon *daemon,
1974 switch (pos->event_loop_info) 2112 switch (pos->event_loop_info)
1975 { 2113 {
1976 case MHD_EVENT_LOOP_INFO_READ: 2114 case MHD_EVENT_LOOP_INFO_READ:
1977 p[poll_server+i].events |= POLLIN; 2115 p[poll_server+i].events |= POLLIN;
1978 break; 2116 break;
1979 case MHD_EVENT_LOOP_INFO_WRITE: 2117 case MHD_EVENT_LOOP_INFO_WRITE:
1980 p[poll_server+i].events |= POLLOUT; 2118 p[poll_server+i].events |= POLLOUT;
1981 if (pos->read_buffer_size > pos->read_buffer_offset) 2119 if (pos->read_buffer_size > pos->read_buffer_offset)
1982 p[poll_server+i].events |= POLLIN; 2120 p[poll_server+i].events |= POLLIN;
1983 break; 2121 break;
1984 case MHD_EVENT_LOOP_INFO_BLOCK: 2122 case MHD_EVENT_LOOP_INFO_BLOCK:
1985 if (pos->read_buffer_size > pos->read_buffer_offset) 2123 if (pos->read_buffer_size > pos->read_buffer_offset)
1986 p[poll_server+i].events |= POLLIN; 2124 p[poll_server+i].events |= POLLIN;
1987 break; 2125 break;
1988 case MHD_EVENT_LOOP_INFO_CLEANUP: 2126 case MHD_EVENT_LOOP_INFO_CLEANUP:
1989 /* should never happen */ 2127 /* should never happen */
@@ -1993,20 +2131,20 @@ MHD_poll_all (struct MHD_Daemon *daemon,
1993 } 2131 }
1994 if (0 == poll_server + num_connections) 2132 if (0 == poll_server + num_connections)
1995 return MHD_YES; 2133 return MHD_YES;
1996 if (poll (p, poll_server + num_connections, timeout) < 0) 2134 if (poll (p, poll_server + num_connections, timeout) < 0)
1997 { 2135 {
1998 if (EINTR == errno) 2136 if (EINTR == errno)
1999 return MHD_YES; 2137 return MHD_YES;
2000#if HAVE_MESSAGES 2138#if HAVE_MESSAGES
2001 MHD_DLOG (daemon, 2139 MHD_DLOG (daemon,
2002 "poll failed: %s\n", 2140 "poll failed: %s\n",
2003 STRERROR (errno)); 2141 STRERROR (errno));
2004#endif 2142#endif
2005 return MHD_NO; 2143 return MHD_NO;
2006 } 2144 }
2007 /* handle shutdown */ 2145 /* handle shutdown */
2008 if (MHD_YES == daemon->shutdown) 2146 if (MHD_YES == daemon->shutdown)
2009 return MHD_NO; 2147 return MHD_NO;
2010 i = 0; 2148 i = 0;
2011 next = daemon->connections_head; 2149 next = daemon->connections_head;
2012 while (NULL != (pos = next)) 2150 while (NULL != (pos = next))
@@ -2017,11 +2155,11 @@ MHD_poll_all (struct MHD_Daemon *daemon,
2017 case MHD_EVENT_LOOP_INFO_READ: 2155 case MHD_EVENT_LOOP_INFO_READ:
2018 /* first, sanity checks */ 2156 /* first, sanity checks */
2019 if (i >= num_connections) 2157 if (i >= num_connections)
2020 break; /* connection list changed somehow, retry later ... */ 2158 break; /* connection list changed somehow, retry later ... */
2021 if (p[poll_server+i].fd != pos->socket_fd) 2159 if (p[poll_server+i].fd != pos->socket_fd)
2022 break; /* fd mismatch, something else happened, retry later ... */ 2160 break; /* fd mismatch, something else happened, retry later ... */
2023 /* normal handling */ 2161 /* normal handling */
2024 if (0 != (p[poll_server+i].revents & POLLIN)) 2162 if (0 != (p[poll_server+i].revents & POLLIN))
2025 pos->read_handler (pos); 2163 pos->read_handler (pos);
2026 pos->idle_handler (pos); 2164 pos->idle_handler (pos);
2027 i++; 2165 i++;
@@ -2029,19 +2167,19 @@ MHD_poll_all (struct MHD_Daemon *daemon,
2029 case MHD_EVENT_LOOP_INFO_WRITE: 2167 case MHD_EVENT_LOOP_INFO_WRITE:
2030 /* first, sanity checks */ 2168 /* first, sanity checks */
2031 if (i >= num_connections) 2169 if (i >= num_connections)
2032 break; /* connection list changed somehow, retry later ... */ 2170 break; /* connection list changed somehow, retry later ... */
2033 if (p[poll_server+i].fd != pos->socket_fd) 2171 if (p[poll_server+i].fd != pos->socket_fd)
2034 break; /* fd mismatch, something else happened, retry later ... */ 2172 break; /* fd mismatch, something else happened, retry later ... */
2035 /* normal handling */ 2173 /* normal handling */
2036 if (0 != (p[poll_server+i].revents & POLLIN)) 2174 if (0 != (p[poll_server+i].revents & POLLIN))
2037 pos->read_handler (pos); 2175 pos->read_handler (pos);
2038 if (0 != (p[poll_server+i].revents & POLLOUT)) 2176 if (0 != (p[poll_server+i].revents & POLLOUT))
2039 pos->write_handler (pos); 2177 pos->write_handler (pos);
2040 pos->idle_handler (pos); 2178 pos->idle_handler (pos);
2041 i++; 2179 i++;
2042 break; 2180 break;
2043 case MHD_EVENT_LOOP_INFO_BLOCK: 2181 case MHD_EVENT_LOOP_INFO_BLOCK:
2044 if (0 != (p[poll_server+i].revents & POLLIN)) 2182 if (0 != (p[poll_server+i].revents & POLLIN))
2045 pos->read_handler (pos); 2183 pos->read_handler (pos);
2046 pos->idle_handler (pos); 2184 pos->idle_handler (pos);
2047 break; 2185 break;
@@ -2074,7 +2212,7 @@ MHD_poll_listen_socket (struct MHD_Daemon *daemon,
2074 int timeout; 2212 int timeout;
2075 unsigned int poll_count; 2213 unsigned int poll_count;
2076 int poll_listen; 2214 int poll_listen;
2077 2215
2078 memset (&p, 0, sizeof (p)); 2216 memset (&p, 0, sizeof (p));
2079 poll_count = 0; 2217 poll_count = 0;
2080 poll_listen = -1; 2218 poll_listen = -1;
@@ -2110,10 +2248,10 @@ MHD_poll_listen_socket (struct MHD_Daemon *daemon,
2110 } 2248 }
2111 /* handle shutdown */ 2249 /* handle shutdown */
2112 if (MHD_YES == daemon->shutdown) 2250 if (MHD_YES == daemon->shutdown)
2113 return MHD_NO; 2251 return MHD_NO;
2114 if ( (-1 != poll_listen) && 2252 if ( (-1 != poll_listen) &&
2115 (0 != (p[poll_listen].revents & POLLIN)) ) 2253 (0 != (p[poll_listen].revents & POLLIN)) )
2116 (void) MHD_accept_connection (daemon); 2254 (void) MHD_accept_connection (daemon);
2117 return MHD_YES; 2255 return MHD_YES;
2118} 2256}
2119#endif 2257#endif
@@ -2175,7 +2313,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
2175 int timeout_ms; 2313 int timeout_ms;
2176 MHD_UNSIGNED_LONG_LONG timeout_ll; 2314 MHD_UNSIGNED_LONG_LONG timeout_ll;
2177 int num_events; 2315 int num_events;
2178 unsigned int i; 2316 unsigned int i;
2179 unsigned int series_length; 2317 unsigned int series_length;
2180 2318
2181 if (-1 == daemon->epoll_fd) 2319 if (-1 == daemon->epoll_fd)
@@ -2187,7 +2325,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
2187 (MHD_NO == daemon->listen_socket_in_epoll) ) 2325 (MHD_NO == daemon->listen_socket_in_epoll) )
2188 { 2326 {
2189 event.events = EPOLLIN; 2327 event.events = EPOLLIN;
2190 event.data.ptr = daemon; 2328 event.data.ptr = daemon;
2191 if (0 != epoll_ctl (daemon->epoll_fd, 2329 if (0 != epoll_ctl (daemon->epoll_fd,
2192 EPOLL_CTL_ADD, 2330 EPOLL_CTL_ADD,
2193 daemon->socket_fd, 2331 daemon->socket_fd,
@@ -2195,8 +2333,8 @@ MHD_epoll (struct MHD_Daemon *daemon,
2195 { 2333 {
2196#if HAVE_MESSAGES 2334#if HAVE_MESSAGES
2197 if (0 != (daemon->options & MHD_USE_DEBUG)) 2335 if (0 != (daemon->options & MHD_USE_DEBUG))
2198 MHD_DLOG (daemon, 2336 MHD_DLOG (daemon,
2199 "Call to epoll_ctl failed: %s\n", 2337 "Call to epoll_ctl failed: %s\n",
2200 STRERROR (errno)); 2338 STRERROR (errno));
2201#endif 2339#endif
2202 return MHD_NO; 2340 return MHD_NO;
@@ -2247,8 +2385,8 @@ MHD_epoll (struct MHD_Daemon *daemon,
2247 return MHD_YES; 2385 return MHD_YES;
2248#if HAVE_MESSAGES 2386#if HAVE_MESSAGES
2249 if (0 != (daemon->options & MHD_USE_DEBUG)) 2387 if (0 != (daemon->options & MHD_USE_DEBUG))
2250 MHD_DLOG (daemon, 2388 MHD_DLOG (daemon,
2251 "Call to epoll_wait failed: %s\n", 2389 "Call to epoll_wait failed: %s\n",
2252 STRERROR (errno)); 2390 STRERROR (errno));
2253#endif 2391#endif
2254 return MHD_NO; 2392 return MHD_NO;
@@ -2270,7 +2408,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
2270 (pos->read_buffer_size > pos->read_buffer_offset) ) && 2408 (pos->read_buffer_size > pos->read_buffer_offset) ) &&
2271 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) ) 2409 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
2272 { 2410 {
2273 EDLL_insert (daemon->eready_head, 2411 EDLL_insert (daemon->eready_head,
2274 daemon->eready_tail, 2412 daemon->eready_tail,
2275 pos); 2413 pos);
2276 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL; 2414 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
@@ -2282,7 +2420,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
2282 if ( (MHD_EVENT_LOOP_INFO_WRITE == pos->event_loop_info) && 2420 if ( (MHD_EVENT_LOOP_INFO_WRITE == pos->event_loop_info) &&
2283 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) ) 2421 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
2284 { 2422 {
2285 EDLL_insert (daemon->eready_head, 2423 EDLL_insert (daemon->eready_head,
2286 daemon->eready_tail, 2424 daemon->eready_tail,
2287 pos); 2425 pos);
2288 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL; 2426 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
@@ -2368,25 +2506,25 @@ MHD_epoll (struct MHD_Daemon *daemon,
2368int 2506int
2369MHD_run (struct MHD_Daemon *daemon) 2507MHD_run (struct MHD_Daemon *daemon)
2370{ 2508{
2371 if ( (MHD_YES == daemon->shutdown) || 2509 if ( (MHD_YES == daemon->shutdown) ||
2372 (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || 2510 (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ||
2373 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) 2511 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) )
2374 return MHD_NO; 2512 return MHD_NO;
2375 if (0 != (daemon->options & MHD_USE_POLL)) 2513 if (0 != (daemon->options & MHD_USE_POLL))
2376 { 2514 {
2377 MHD_poll (daemon, MHD_NO); 2515 MHD_poll (daemon, MHD_NO);
2378 MHD_cleanup_connections (daemon); 2516 MHD_cleanup_connections (daemon);
2379 } 2517 }
2380#if EPOLL_SUPPORT 2518#if EPOLL_SUPPORT
2381 else if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) 2519 else if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY))
2382 { 2520 {
2383 MHD_epoll (daemon, MHD_NO); 2521 MHD_epoll (daemon, MHD_NO);
2384 MHD_cleanup_connections (daemon); 2522 MHD_cleanup_connections (daemon);
2385 } 2523 }
2386#endif 2524#endif
2387 else 2525 else
2388 { 2526 {
2389 MHD_select (daemon, MHD_NO); 2527 MHD_select (daemon, MHD_NO);
2390 /* MHD_select does MHD_cleanup_connections already */ 2528 /* MHD_select does MHD_cleanup_connections already */
2391 } 2529 }
2392 return MHD_YES; 2530 return MHD_YES;
@@ -2407,13 +2545,13 @@ MHD_select_thread (void *cls)
2407 2545
2408 while (MHD_YES != daemon->shutdown) 2546 while (MHD_YES != daemon->shutdown)
2409 { 2547 {
2410 if (0 != (daemon->options & MHD_USE_POLL)) 2548 if (0 != (daemon->options & MHD_USE_POLL))
2411 MHD_poll (daemon, MHD_YES); 2549 MHD_poll (daemon, MHD_YES);
2412#if EPOLL_SUPPORT 2550#if EPOLL_SUPPORT
2413 else if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) 2551 else if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY))
2414 MHD_epoll (daemon, MHD_YES); 2552 MHD_epoll (daemon, MHD_YES);
2415#endif 2553#endif
2416 else 2554 else
2417 MHD_select (daemon, MHD_YES); 2555 MHD_select (daemon, MHD_YES);
2418 MHD_cleanup_connections (daemon); 2556 MHD_cleanup_connections (daemon);
2419 } 2557 }
@@ -2469,7 +2607,7 @@ MHD_start_daemon (unsigned int flags,
2469 * #MHD_start_daemon, this function will return -1. 2607 * #MHD_start_daemon, this function will return -1.
2470 * 2608 *
2471 * @param daemon daemon to stop accepting new connections for 2609 * @param daemon daemon to stop accepting new connections for
2472 * @return old listen socket on success, -1 if the daemon was 2610 * @return old listen socket on success, -1 if the daemon was
2473 * already not listening anymore 2611 * already not listening anymore
2474 * @ingroup specialized 2612 * @ingroup specialized
2475 */ 2613 */
@@ -2486,7 +2624,7 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon)
2486 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) 2624 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) )
2487 { 2625 {
2488#if HAVE_MESSAGES 2626#if HAVE_MESSAGES
2489 MHD_DLOG (daemon, 2627 MHD_DLOG (daemon,
2490 "Using MHD_quiesce_daemon in this mode requires MHD_USE_PIPE_FOR_SHUTDOWN\n"); 2628 "Using MHD_quiesce_daemon in this mode requires MHD_USE_PIPE_FOR_SHUTDOWN\n");
2491#endif 2629#endif
2492 return -1; 2630 return -1;
@@ -2536,13 +2674,13 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon)
2536 * @param va arguments to the format string (fprintf-style) 2674 * @param va arguments to the format string (fprintf-style)
2537 */ 2675 */
2538typedef void (*VfprintfFunctionPointerType)(void *cls, 2676typedef void (*VfprintfFunctionPointerType)(void *cls,
2539 const char *format, 2677 const char *format,
2540 va_list va); 2678 va_list va);
2541 2679
2542 2680
2543/** 2681/**
2544 * Parse a list of options given as varargs. 2682 * Parse a list of options given as varargs.
2545 * 2683 *
2546 * @param daemon the daemon to initialize 2684 * @param daemon the daemon to initialize
2547 * @param servaddr where to store the server's listen address 2685 * @param servaddr where to store the server's listen address
2548 * @param ap the options 2686 * @param ap the options
@@ -2556,7 +2694,7 @@ parse_options_va (struct MHD_Daemon *daemon,
2556 2694
2557/** 2695/**
2558 * Parse a list of options given as varargs. 2696 * Parse a list of options given as varargs.
2559 * 2697 *
2560 * @param daemon the daemon to initialize 2698 * @param daemon the daemon to initialize
2561 * @param servaddr where to store the server's listen address 2699 * @param servaddr where to store the server's listen address
2562 * @param ... the options 2700 * @param ... the options
@@ -2579,7 +2717,7 @@ parse_options (struct MHD_Daemon *daemon,
2579 2717
2580/** 2718/**
2581 * Parse a list of options given as varargs. 2719 * Parse a list of options given as varargs.
2582 * 2720 *
2583 * @param daemon the daemon to initialize 2721 * @param daemon the daemon to initialize
2584 * @param servaddr where to store the server's listen address 2722 * @param servaddr where to store the server's listen address
2585 * @param ap the options 2723 * @param ap the options
@@ -2597,7 +2735,7 @@ parse_options_va (struct MHD_Daemon *daemon,
2597 int ret; 2735 int ret;
2598 const char *pstr; 2736 const char *pstr;
2599#endif 2737#endif
2600 2738
2601 while (MHD_OPTION_END != (opt = (enum MHD_OPTION) va_arg (ap, int))) 2739 while (MHD_OPTION_END != (opt = (enum MHD_OPTION) va_arg (ap, int)))
2602 { 2740 {
2603 switch (opt) 2741 switch (opt)
@@ -2650,7 +2788,7 @@ parse_options_va (struct MHD_Daemon *daemon,
2650 else 2788 else
2651 MHD_DLOG (daemon, 2789 MHD_DLOG (daemon,
2652 "MHD HTTPS option %d passed to MHD but MHD_USE_SSL not set\n", 2790 "MHD HTTPS option %d passed to MHD but MHD_USE_SSL not set\n",
2653 opt); 2791 opt);
2654#endif 2792#endif
2655 break; 2793 break;
2656 case MHD_OPTION_HTTPS_MEM_CERT: 2794 case MHD_OPTION_HTTPS_MEM_CERT:
@@ -2660,7 +2798,7 @@ parse_options_va (struct MHD_Daemon *daemon,
2660 else 2798 else
2661 MHD_DLOG (daemon, 2799 MHD_DLOG (daemon,
2662 "MHD HTTPS option %d passed to MHD but MHD_USE_SSL not set\n", 2800 "MHD HTTPS option %d passed to MHD but MHD_USE_SSL not set\n",
2663 opt); 2801 opt);
2664#endif 2802#endif
2665 break; 2803 break;
2666 case MHD_OPTION_HTTPS_MEM_TRUST: 2804 case MHD_OPTION_HTTPS_MEM_TRUST:
@@ -2690,7 +2828,7 @@ parse_options_va (struct MHD_Daemon *daemon,
2690 "Setting priorities to `%s' failed: %s\n", 2828 "Setting priorities to `%s' failed: %s\n",
2691 pstr, 2829 pstr,
2692 gnutls_strerror (ret)); 2830 gnutls_strerror (ret));
2693#endif 2831#endif
2694 daemon->priority_cache = NULL; 2832 daemon->priority_cache = NULL;
2695 return MHD_NO; 2833 return MHD_NO;
2696 } 2834 }
@@ -2707,7 +2845,7 @@ parse_options_va (struct MHD_Daemon *daemon,
2707 break; 2845 break;
2708#endif 2846#endif
2709 case MHD_OPTION_LISTEN_SOCKET: 2847 case MHD_OPTION_LISTEN_SOCKET:
2710 daemon->socket_fd = va_arg (ap, int); 2848 daemon->socket_fd = va_arg (ap, int);
2711 break; 2849 break;
2712 case MHD_OPTION_EXTERNAL_LOGGER: 2850 case MHD_OPTION_EXTERNAL_LOGGER:
2713#if HAVE_MESSAGES 2851#if HAVE_MESSAGES
@@ -2829,7 +2967,7 @@ parse_options_va (struct MHD_Daemon *daemon,
2829#endif 2967#endif
2830 return MHD_NO; 2968 return MHD_NO;
2831 } 2969 }
2832 } 2970 }
2833 return MHD_YES; 2971 return MHD_YES;
2834} 2972}
2835 2973
@@ -2848,7 +2986,7 @@ create_socket (struct MHD_Daemon *daemon,
2848{ 2986{
2849 int ctype = type | SOCK_CLOEXEC; 2987 int ctype = type | SOCK_CLOEXEC;
2850 int fd; 2988 int fd;
2851 2989
2852 /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo 2990 /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo
2853 * implementations do not set ai_socktype, e.g. RHL6.2. */ 2991 * implementations do not set ai_socktype, e.g. RHL6.2. */
2854 fd = SOCKET (domain, ctype, protocol); 2992 fd = SOCKET (domain, ctype, protocol);
@@ -2883,19 +3021,19 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
2883 { 3021 {
2884#if HAVE_MESSAGES 3022#if HAVE_MESSAGES
2885 if (0 != (daemon->options & MHD_USE_DEBUG)) 3023 if (0 != (daemon->options & MHD_USE_DEBUG))
2886 MHD_DLOG (daemon, 3024 MHD_DLOG (daemon,
2887 "Call to epoll_create1 failed: %s\n", 3025 "Call to epoll_create1 failed: %s\n",
2888 STRERROR (errno)); 3026 STRERROR (errno));
2889#endif 3027#endif
2890 return MHD_NO; 3028 return MHD_NO;
2891 } 3029 }
2892 if (0 == EPOLL_CLOEXEC) 3030 if (0 == EPOLL_CLOEXEC)
2893 make_nonblocking_noninheritable (daemon, 3031 make_nonblocking_noninheritable (daemon,
2894 daemon->epoll_fd); 3032 daemon->epoll_fd);
2895 if (-1 == daemon->socket_fd) 3033 if (-1 == daemon->socket_fd)
2896 return MHD_YES; /* non-listening daemon */ 3034 return MHD_YES; /* non-listening daemon */
2897 event.events = EPOLLIN; 3035 event.events = EPOLLIN;
2898 event.data.ptr = daemon; 3036 event.data.ptr = daemon;
2899 if (0 != epoll_ctl (daemon->epoll_fd, 3037 if (0 != epoll_ctl (daemon->epoll_fd,
2900 EPOLL_CTL_ADD, 3038 EPOLL_CTL_ADD,
2901 daemon->socket_fd, 3039 daemon->socket_fd,
@@ -2903,8 +3041,8 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
2903 { 3041 {
2904#if HAVE_MESSAGES 3042#if HAVE_MESSAGES
2905 if (0 != (daemon->options & MHD_USE_DEBUG)) 3043 if (0 != (daemon->options & MHD_USE_DEBUG))
2906 MHD_DLOG (daemon, 3044 MHD_DLOG (daemon,
2907 "Call to epoll_ctl failed: %s\n", 3045 "Call to epoll_ctl failed: %s\n",
2908 STRERROR (errno)); 3046 STRERROR (errno));
2909#endif 3047#endif
2910 return MHD_NO; 3048 return MHD_NO;
@@ -2955,15 +3093,15 @@ MHD_start_daemon_va (unsigned int flags,
2955 3093
2956#ifndef HAVE_INET6 3094#ifndef HAVE_INET6
2957 if (0 != (flags & MHD_USE_IPv6)) 3095 if (0 != (flags & MHD_USE_IPv6))
2958 return NULL; 3096 return NULL;
2959#endif 3097#endif
2960#ifndef HAVE_POLL_H 3098#ifndef HAVE_POLL_H
2961 if (0 != (flags & MHD_USE_POLL)) 3099 if (0 != (flags & MHD_USE_POLL))
2962 return NULL; 3100 return NULL;
2963#endif 3101#endif
2964#if ! HTTPS_SUPPORT 3102#if ! HTTPS_SUPPORT
2965 if (0 != (flags & MHD_USE_SSL)) 3103 if (0 != (flags & MHD_USE_SSL))
2966 return NULL; 3104 return NULL;
2967#endif 3105#endif
2968 if (NULL == dh) 3106 if (NULL == dh)
2969 return NULL; 3107 return NULL;
@@ -3021,7 +3159,7 @@ MHD_start_daemon_va (unsigned int flags,
3021 ) 3159 )
3022 { 3160 {
3023#if HAVE_MESSAGES 3161#if HAVE_MESSAGES
3024 MHD_DLOG (daemon, 3162 MHD_DLOG (daemon,
3025 "Failed to create control pipe: %s\n", 3163 "Failed to create control pipe: %s\n",
3026 STRERROR (errno)); 3164 STRERROR (errno));
3027#endif 3165#endif
@@ -3034,7 +3172,7 @@ MHD_start_daemon_va (unsigned int flags,
3034 (daemon->wpipe[0] >= FD_SETSIZE) ) 3172 (daemon->wpipe[0] >= FD_SETSIZE) )
3035 { 3173 {
3036#if HAVE_MESSAGES 3174#if HAVE_MESSAGES
3037 MHD_DLOG (daemon, 3175 MHD_DLOG (daemon,
3038 "file descriptor for control pipe exceeds maximum value\n"); 3176 "file descriptor for control pipe exceeds maximum value\n");
3039#endif 3177#endif
3040 if (0 != CLOSE (daemon->wpipe[0])) 3178 if (0 != CLOSE (daemon->wpipe[0]))
@@ -3069,9 +3207,9 @@ MHD_start_daemon_va (unsigned int flags,
3069 return NULL; 3207 return NULL;
3070 } 3208 }
3071#ifdef DAUTH_SUPPORT 3209#ifdef DAUTH_SUPPORT
3072 if (daemon->nonce_nc_size > 0) 3210 if (daemon->nonce_nc_size > 0)
3073 { 3211 {
3074 if ( ( (size_t) (daemon->nonce_nc_size * sizeof (struct MHD_NonceNc))) / 3212 if ( ( (size_t) (daemon->nonce_nc_size * sizeof (struct MHD_NonceNc))) /
3075 sizeof(struct MHD_NonceNc) != daemon->nonce_nc_size) 3213 sizeof(struct MHD_NonceNc) != daemon->nonce_nc_size)
3076 { 3214 {
3077#if HAVE_MESSAGES 3215#if HAVE_MESSAGES
@@ -3083,7 +3221,7 @@ MHD_start_daemon_va (unsigned int flags,
3083 gnutls_priority_deinit (daemon->priority_cache); 3221 gnutls_priority_deinit (daemon->priority_cache);
3084#endif 3222#endif
3085 free (daemon); 3223 free (daemon);
3086 return NULL; 3224 return NULL;
3087 } 3225 }
3088 daemon->nnc = malloc (daemon->nonce_nc_size * sizeof (struct MHD_NonceNc)); 3226 daemon->nnc = malloc (daemon->nonce_nc_size * sizeof (struct MHD_NonceNc));
3089 if (NULL == daemon->nnc) 3227 if (NULL == daemon->nnc)
@@ -3101,7 +3239,7 @@ MHD_start_daemon_va (unsigned int flags,
3101 return NULL; 3239 return NULL;
3102 } 3240 }
3103 } 3241 }
3104 3242
3105 if (0 != pthread_mutex_init (&daemon->nnc_lock, NULL)) 3243 if (0 != pthread_mutex_init (&daemon->nnc_lock, NULL))
3106 { 3244 {
3107#if HAVE_MESSAGES 3245#if HAVE_MESSAGES
@@ -3119,7 +3257,7 @@ MHD_start_daemon_va (unsigned int flags,
3119#endif 3257#endif
3120 3258
3121 /* Thread pooling currently works only with internal select thread model */ 3259 /* Thread pooling currently works only with internal select thread model */
3122 if ( (0 == (flags & MHD_USE_SELECT_INTERNALLY)) && 3260 if ( (0 == (flags & MHD_USE_SELECT_INTERNALLY)) &&
3123 (daemon->worker_pool_size > 0) ) 3261 (daemon->worker_pool_size > 0) )
3124 { 3262 {
3125#if HAVE_MESSAGES 3263#if HAVE_MESSAGES
@@ -3179,8 +3317,8 @@ MHD_start_daemon_va (unsigned int flags,
3179 { 3317 {
3180#if HAVE_MESSAGES 3318#if HAVE_MESSAGES
3181 if (0 != (flags & MHD_USE_DEBUG)) 3319 if (0 != (flags & MHD_USE_DEBUG))
3182 MHD_DLOG (daemon, 3320 MHD_DLOG (daemon,
3183 "Call to socket failed: %s\n", 3321 "Call to socket failed: %s\n",
3184 STRERROR (errno)); 3322 STRERROR (errno));
3185#endif 3323#endif
3186 goto free_and_fail; 3324 goto free_and_fail;
@@ -3188,16 +3326,16 @@ MHD_start_daemon_va (unsigned int flags,
3188 if ( (0 > SETSOCKOPT (socket_fd, 3326 if ( (0 > SETSOCKOPT (socket_fd,
3189 SOL_SOCKET, 3327 SOL_SOCKET,
3190 SO_REUSEADDR, 3328 SO_REUSEADDR,
3191 &on, sizeof (on))) && 3329 &on, sizeof (on))) &&
3192 (0 != (flags & MHD_USE_DEBUG)) ) 3330 (0 != (flags & MHD_USE_DEBUG)) )
3193 { 3331 {
3194#if HAVE_MESSAGES 3332#if HAVE_MESSAGES
3195 MHD_DLOG (daemon, 3333 MHD_DLOG (daemon,
3196 "setsockopt failed: %s\n", 3334 "setsockopt failed: %s\n",
3197 STRERROR (errno)); 3335 STRERROR (errno));
3198#endif 3336#endif
3199 } 3337 }
3200 3338
3201 /* check for user supplied sockaddr */ 3339 /* check for user supplied sockaddr */
3202#if HAVE_INET6 3340#if HAVE_INET6
3203 if (0 != (flags & MHD_USE_IPv6)) 3341 if (0 != (flags & MHD_USE_IPv6))
@@ -3237,8 +3375,8 @@ MHD_start_daemon_va (unsigned int flags,
3237 { 3375 {
3238#ifdef IPPROTO_IPV6 3376#ifdef IPPROTO_IPV6
3239#ifdef IPV6_V6ONLY 3377#ifdef IPV6_V6ONLY
3240 /* Note: "IPV6_V6ONLY" is declared by Windows Vista ff., see "IPPROTO_IPV6 Socket Options" 3378 /* Note: "IPV6_V6ONLY" is declared by Windows Vista ff., see "IPPROTO_IPV6 Socket Options"
3241 (http://msdn.microsoft.com/en-us/library/ms738574%28v=VS.85%29.aspx); 3379 (http://msdn.microsoft.com/en-us/library/ms738574%28v=VS.85%29.aspx);
3242 and may also be missing on older POSIX systems; good luck if you have any of those, 3380 and may also be missing on older POSIX systems; good luck if you have any of those,
3243 your IPv6 socket may then also bind against IPv4 anyway... */ 3381 your IPv6 socket may then also bind against IPv4 anyway... */
3244#ifndef WINDOWS 3382#ifndef WINDOWS
@@ -3246,14 +3384,14 @@ MHD_start_daemon_va (unsigned int flags,
3246#else 3384#else
3247 const char on = 1; 3385 const char on = 1;
3248#endif 3386#endif
3249 if ( (0 > SETSOCKOPT (socket_fd, 3387 if ( (0 > SETSOCKOPT (socket_fd,
3250 IPPROTO_IPV6, IPV6_V6ONLY, 3388 IPPROTO_IPV6, IPV6_V6ONLY,
3251 &on, sizeof (on))) && 3389 &on, sizeof (on))) &&
3252 (0 != (flags & MHD_USE_DEBUG)) ) 3390 (0 != (flags & MHD_USE_DEBUG)) )
3253 { 3391 {
3254#if HAVE_MESSAGES 3392#if HAVE_MESSAGES
3255 MHD_DLOG (daemon, 3393 MHD_DLOG (daemon,
3256 "setsockopt failed: %s\n", 3394 "setsockopt failed: %s\n",
3257 STRERROR (errno)); 3395 STRERROR (errno));
3258#endif 3396#endif
3259 } 3397 }
@@ -3265,8 +3403,8 @@ MHD_start_daemon_va (unsigned int flags,
3265#if HAVE_MESSAGES 3403#if HAVE_MESSAGES
3266 if (0 != (flags & MHD_USE_DEBUG)) 3404 if (0 != (flags & MHD_USE_DEBUG))
3267 MHD_DLOG (daemon, 3405 MHD_DLOG (daemon,
3268 "Failed to bind to port %u: %s\n", 3406 "Failed to bind to port %u: %s\n",
3269 (unsigned int) port, 3407 (unsigned int) port,
3270 STRERROR (errno)); 3408 STRERROR (errno));
3271#endif 3409#endif
3272 if (0 != CLOSE (socket_fd)) 3410 if (0 != CLOSE (socket_fd))
@@ -3281,12 +3419,12 @@ MHD_start_daemon_va (unsigned int flags,
3281 { 3419 {
3282#if HAVE_MESSAGES 3420#if HAVE_MESSAGES
3283 MHD_DLOG (daemon, 3421 MHD_DLOG (daemon,
3284 "Failed to make listen socket non-blocking: %s\n", 3422 "Failed to make listen socket non-blocking: %s\n",
3285 STRERROR (errno)); 3423 STRERROR (errno));
3286#endif 3424#endif
3287 if (0 != CLOSE (socket_fd)) 3425 if (0 != CLOSE (socket_fd))
3288 MHD_PANIC ("close failed\n"); 3426 MHD_PANIC ("close failed\n");
3289 goto free_and_fail; 3427 goto free_and_fail;
3290 } 3428 }
3291 } 3429 }
3292#endif 3430#endif
@@ -3295,13 +3433,13 @@ MHD_start_daemon_va (unsigned int flags,
3295#if HAVE_MESSAGES 3433#if HAVE_MESSAGES
3296 if (0 != (flags & MHD_USE_DEBUG)) 3434 if (0 != (flags & MHD_USE_DEBUG))
3297 MHD_DLOG (daemon, 3435 MHD_DLOG (daemon,
3298 "Failed to listen for connections: %s\n", 3436 "Failed to listen for connections: %s\n",
3299 STRERROR (errno)); 3437 STRERROR (errno));
3300#endif 3438#endif
3301 if (0 != CLOSE (socket_fd)) 3439 if (0 != CLOSE (socket_fd))
3302 MHD_PANIC ("close failed\n"); 3440 MHD_PANIC ("close failed\n");
3303 goto free_and_fail; 3441 goto free_and_fail;
3304 } 3442 }
3305 } 3443 }
3306 else 3444 else
3307 { 3445 {
@@ -3353,7 +3491,7 @@ MHD_start_daemon_va (unsigned int flags,
3353 if ((0 != (flags & MHD_USE_SSL)) && (0 != MHD_TLS_init (daemon))) 3491 if ((0 != (flags & MHD_USE_SSL)) && (0 != MHD_TLS_init (daemon)))
3354 { 3492 {
3355#if HAVE_MESSAGES 3493#if HAVE_MESSAGES
3356 MHD_DLOG (daemon, 3494 MHD_DLOG (daemon,
3357 "Failed to initialize TLS support\n"); 3495 "Failed to initialize TLS support\n");
3358#endif 3496#endif
3359 if ( (-1 != socket_fd) && 3497 if ( (-1 != socket_fd) &&
@@ -3366,14 +3504,14 @@ MHD_start_daemon_va (unsigned int flags,
3366#endif 3504#endif
3367 if ( ( (0 != (flags & MHD_USE_THREAD_PER_CONNECTION)) || 3505 if ( ( (0 != (flags & MHD_USE_THREAD_PER_CONNECTION)) ||
3368 ( (0 != (flags & MHD_USE_SELECT_INTERNALLY)) && 3506 ( (0 != (flags & MHD_USE_SELECT_INTERNALLY)) &&
3369 (0 == daemon->worker_pool_size)) ) && 3507 (0 == daemon->worker_pool_size)) ) &&
3370 (0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) && 3508 (0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) &&
3371 (0 != (res_thread_create = 3509 (0 != (res_thread_create =
3372 create_thread (&daemon->pid, daemon, &MHD_select_thread, daemon)))) 3510 create_thread (&daemon->pid, daemon, &MHD_select_thread, daemon))))
3373 { 3511 {
3374#if HAVE_MESSAGES 3512#if HAVE_MESSAGES
3375 MHD_DLOG (daemon, 3513 MHD_DLOG (daemon,
3376 "Failed to create listen thread: %s\n", 3514 "Failed to create listen thread: %s\n",
3377 STRERROR (res_thread_create)); 3515 STRERROR (res_thread_create));
3378#endif 3516#endif
3379 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3517 pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
@@ -3465,12 +3603,12 @@ MHD_start_daemon_va (unsigned int flags,
3465 } 3603 }
3466 3604
3467 /* Spawn the worker thread */ 3605 /* Spawn the worker thread */
3468 if (0 != (res_thread_create = 3606 if (0 != (res_thread_create =
3469 create_thread (&d->pid, daemon, &MHD_select_thread, d))) 3607 create_thread (&d->pid, daemon, &MHD_select_thread, d)))
3470 { 3608 {
3471#if HAVE_MESSAGES 3609#if HAVE_MESSAGES
3472 MHD_DLOG (daemon, 3610 MHD_DLOG (daemon,
3473 "Failed to create pool thread: %s\n", 3611 "Failed to create pool thread: %s\n",
3474 STRERROR (res_thread_create)); 3612 STRERROR (res_thread_create));
3475#endif 3613#endif
3476 /* Free memory for this worker; cleanup below handles 3614 /* Free memory for this worker; cleanup below handles
@@ -3508,9 +3646,9 @@ thread_failed:
3508 return NULL; 3646 return NULL;
3509 3647
3510 free_and_fail: 3648 free_and_fail:
3511 /* clean up basic memory state in 'daemon' and return NULL to 3649 /* clean up basic memory state in 'daemon' and return NULL to
3512 indicate failure */ 3650 indicate failure */
3513#if EPOLL_SUPPORT 3651#if EPOLL_SUPPORT
3514 if (-1 != daemon->epoll_fd) 3652 if (-1 != daemon->epoll_fd)
3515 close (daemon->epoll_fd); 3653 close (daemon->epoll_fd);
3516#endif 3654#endif
@@ -3571,26 +3709,26 @@ close_all_connections (struct MHD_Daemon *daemon)
3571 struct MHD_Connection *pos; 3709 struct MHD_Connection *pos;
3572 void *unused; 3710 void *unused;
3573 int rc; 3711 int rc;
3574 3712
3575 /* first, make sure all threads are aware of shutdown; need to 3713 /* first, make sure all threads are aware of shutdown; need to
3576 traverse DLLs in peace... */ 3714 traverse DLLs in peace... */
3577 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 3715 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
3578 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 3716 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
3579 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 3717 MHD_PANIC ("Failed to acquire cleanup mutex\n");
3580 for (pos = daemon->connections_head; NULL != pos; pos = pos->nextX) 3718 for (pos = daemon->connections_head; NULL != pos; pos = pos->nextX)
3581 SHUTDOWN (pos->socket_fd, 3719 SHUTDOWN (pos->socket_fd,
3582 (pos->read_closed == MHD_YES) ? SHUT_WR : SHUT_RDWR); 3720 (pos->read_closed == MHD_YES) ? SHUT_WR : SHUT_RDWR);
3583 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 3721 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
3584 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 3722 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
3585 MHD_PANIC ("Failed to release cleanup mutex\n"); 3723 MHD_PANIC ("Failed to release cleanup mutex\n");
3586 3724
3587 /* now, collect threads from thread pool */ 3725 /* now, collect threads from thread pool */
3588 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 3726 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
3589 { 3727 {
3590 while (NULL != (pos = daemon->connections_head)) 3728 while (NULL != (pos = daemon->connections_head))
3591 { 3729 {
3592 if (0 != (rc = pthread_join (pos->pid, &unused))) 3730 if (0 != (rc = pthread_join (pos->pid, &unused)))
3593 MHD_PANIC ("Failed to join a thread\n"); 3731 MHD_PANIC ("Failed to join a thread\n");
3594 pos->thread_joined = MHD_YES; 3732 pos->thread_joined = MHD_YES;
3595 } 3733 }
3596 } 3734 }
@@ -3612,19 +3750,19 @@ static void
3612epoll_shutdown (struct MHD_Daemon *daemon) 3750epoll_shutdown (struct MHD_Daemon *daemon)
3613{ 3751{
3614 struct epoll_event event; 3752 struct epoll_event event;
3615 3753
3616 if (-1 == daemon->wpipe[1]) 3754 if (-1 == daemon->wpipe[1])
3617 { 3755 {
3618 /* wpipe was required in this mode, how could this happen? */ 3756 /* wpipe was required in this mode, how could this happen? */
3619 MHD_PANIC ("Internal error\n"); 3757 MHD_PANIC ("Internal error\n");
3620 } 3758 }
3621 event.events = EPOLLOUT; 3759 event.events = EPOLLOUT;
3622 event.data.ptr = NULL; 3760 event.data.ptr = NULL;
3623 if (0 != epoll_ctl (daemon->epoll_fd, 3761 if (0 != epoll_ctl (daemon->epoll_fd,
3624 EPOLL_CTL_ADD, 3762 EPOLL_CTL_ADD,
3625 daemon->wpipe[1], 3763 daemon->wpipe[1],
3626 &event)) 3764 &event))
3627 MHD_PANIC ("Failed to add wpipe to epoll set to signal termination\n"); 3765 MHD_PANIC ("Failed to add wpipe to epoll set to signal termination\n");
3628} 3766}
3629#endif 3767#endif
3630 3768
@@ -3681,7 +3819,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3681 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && 3819 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
3682 (-1 != daemon->epoll_fd) && 3820 (-1 != daemon->epoll_fd) &&
3683 (-1 == fd) ) 3821 (-1 == fd) )
3684 epoll_shutdown (daemon); 3822 epoll_shutdown (daemon);
3685#endif 3823#endif
3686 3824
3687#if DEBUG_CLOSE 3825#if DEBUG_CLOSE
@@ -3697,11 +3835,11 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3697 /* MHD_USE_NO_LISTEN_SOCKET disables thread pools, hence we need to check */ 3835 /* MHD_USE_NO_LISTEN_SOCKET disables thread pools, hence we need to check */
3698 for (i = 0; i < daemon->worker_pool_size; ++i) 3836 for (i = 0; i < daemon->worker_pool_size; ++i)
3699 { 3837 {
3700 if (0 != (rc = pthread_join (daemon->worker_pool[i].pid, &unused))) 3838 if (0 != (rc = pthread_join (daemon->worker_pool[i].pid, &unused)))
3701 MHD_PANIC ("Failed to join a thread\n"); 3839 MHD_PANIC ("Failed to join a thread\n");
3702 close_all_connections (&daemon->worker_pool[i]); 3840 close_all_connections (&daemon->worker_pool[i]);
3703 pthread_mutex_destroy (&daemon->worker_pool[i].cleanup_connection_mutex); 3841 pthread_mutex_destroy (&daemon->worker_pool[i].cleanup_connection_mutex);
3704#if EPOLL_SUPPORT 3842#if EPOLL_SUPPORT
3705 if ( (-1 != daemon->worker_pool[i].epoll_fd) && 3843 if ( (-1 != daemon->worker_pool[i].epoll_fd) &&
3706 (0 != CLOSE (daemon->worker_pool[i].epoll_fd)) ) 3844 (0 != CLOSE (daemon->worker_pool[i].epoll_fd)) )
3707 MHD_PANIC ("close failed\n"); 3845 MHD_PANIC ("close failed\n");
@@ -3739,7 +3877,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3739#if EPOLL_SUPPORT 3877#if EPOLL_SUPPORT
3740 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && 3878 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
3741 (-1 != daemon->epoll_fd) && 3879 (-1 != daemon->epoll_fd) &&
3742 (0 != CLOSE (daemon->epoll_fd)) ) 3880 (0 != CLOSE (daemon->epoll_fd)) )
3743 MHD_PANIC ("close failed\n"); 3881 MHD_PANIC ("close failed\n");
3744#endif 3882#endif
3745 3883
@@ -3774,7 +3912,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3774 */ 3912 */
3775const union MHD_DaemonInfo * 3913const union MHD_DaemonInfo *
3776MHD_get_daemon_info (struct MHD_Daemon *daemon, 3914MHD_get_daemon_info (struct MHD_Daemon *daemon,
3777 enum MHD_DaemonInfoType info_type, 3915 enum MHD_DaemonInfoType info_type,
3778 ...) 3916 ...)
3779{ 3917{
3780 switch (info_type) 3918 switch (info_type)
@@ -3811,7 +3949,7 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon,
3811 * @param cls passed to @a cb 3949 * @param cls passed to @a cb
3812 * @ingroup logging 3950 * @ingroup logging
3813 */ 3951 */
3814void 3952void
3815MHD_set_panic_func (MHD_PanicCallback cb, void *cls) 3953MHD_set_panic_func (MHD_PanicCallback cb, void *cls)
3816{ 3954{
3817 mhd_panic = cb; 3955 mhd_panic = cb;
@@ -3850,7 +3988,7 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL;
3850/** 3988/**
3851 * Initialize do setup work. 3989 * Initialize do setup work.
3852 */ 3990 */
3853void ATTRIBUTE_CONSTRUCTOR 3991void ATTRIBUTE_CONSTRUCTOR
3854MHD_init () 3992MHD_init ()
3855{ 3993{
3856 mhd_panic = &mhd_panic_std; 3994 mhd_panic = &mhd_panic_std;
@@ -3869,7 +4007,7 @@ MHD_init ()
3869} 4007}
3870 4008
3871 4009
3872void ATTRIBUTE_DESTRUCTOR 4010void ATTRIBUTE_DESTRUCTOR
3873MHD_fini () 4011MHD_fini ()
3874{ 4012{
3875#if HTTPS_SUPPORT 4013#if HTTPS_SUPPORT