gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r30402 - in libmicrohttpd: . doc src/include src/microhttpd


From: gnunet
Subject: [GNUnet-SVN] r30402 - in libmicrohttpd: . doc src/include src/microhttpd
Date: Thu, 24 Oct 2013 10:41:04 +0200

Author: grothoff
Date: 2013-10-24 10:41:04 +0200 (Thu, 24 Oct 2013)
New Revision: 30402

Modified:
   libmicrohttpd/ChangeLog
   libmicrohttpd/doc/libmicrohttpd.texi
   libmicrohttpd/src/include/microhttpd.h
   libmicrohttpd/src/microhttpd/EXPORT.sym
   libmicrohttpd/src/microhttpd/connection.c
   libmicrohttpd/src/microhttpd/daemon.c
Log:
experimental code to support flow control for connections via 
MHD_suspend_connection and MHD_resume_connection

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2013-10-24 08:39:55 UTC (rev 30401)
+++ libmicrohttpd/ChangeLog     2013-10-24 08:41:04 UTC (rev 30402)
@@ -1,3 +1,7 @@
+Thu Oct 24 10:40:03 CEST 2013
+       Adding support for connection flow control via
+       MHD_suspend_connection and MHD_resume_connection. -CG
+
 Sat Oct 19 16:40:32 CEST 2013
        Releasing libmicrohttpd 0.9.31. -CG
 

Modified: libmicrohttpd/doc/libmicrohttpd.texi
===================================================================
--- libmicrohttpd/doc/libmicrohttpd.texi        2013-10-24 08:39:55 UTC (rev 
30401)
+++ libmicrohttpd/doc/libmicrohttpd.texi        2013-10-24 08:41:04 UTC (rev 
30402)
@@ -63,6 +63,7 @@
 * microhttpd-inspect::          Implementing external @code{select}.
 * microhttpd-requests::         Handling requests.
 * microhttpd-responses::        Building responses to requests.
+* microhttpd-flow::             Flow control.
 * microhttpd-dauth::            Utilizing Authentication.
 * microhttpd-post::             Adding a @code{POST} processor.
 * microhttpd-info::             Obtaining and modifying status information.
@@ -132,7 +133,7 @@
 
 @section Scope
 
-MHD is currently used in a wide range of implementations. 
+MHD is currently used in a wide range of implementations.
 Examples based on reports we've received from developers include:
 @itemize
 @item Embedded HTTP server on a cortex M3 (128 KB code space)
@@ -148,7 +149,7 @@
 @cindex select
 
 MHD supports four basic thread modes and up to three event loop
-styes.  
+styes.
 
 The four basic thread modes are external (MHD creates no threads,
 event loop is fully managed by the application), internal (MHD creates
@@ -203,7 +204,7 @@
 @item @b{external}              @tab  yes       @tab no       @tab yes
 @item @b{internal}              @tab  yes       @tab yes      @tab yes
 @item @b{thread pool}           @tab  yes       @tab yes      @tab yes
address@hidden @b{thread-per-connection} @tab  yes       @tab yes      @tab no 
address@hidden @b{thread-per-connection} @tab  yes       @tab yes      @tab no
 @end multitable
 @caption{Supported combinations of event styles and thread modes.}
 @end float
@@ -239,7 +240,7 @@
 @item ``--disable-curl''
 disable running testcases using libcurl
 
address@hidden ``--disable-largefile'' 
address@hidden ``--disable-largefile''
 disable support for 64-bit files
 
 @item ``--disable-messages''
@@ -285,7 +286,7 @@
 Once you have ensured that you manually (!) included the right headers
 for your platform before "microhttpd.h", you should also add a line
 with @code{#define MHD_PLATFORM_H} which will prevent the
-"microhttpd.h" header from trying (and, depending on your platform, 
+"microhttpd.h" header from trying (and, depending on your platform,
 failing) to include the right headers.
 
 If you do not define MHD_PLATFORM_H, the "microhttpd.h" header will
@@ -297,12 +298,12 @@
 MHD does not install a signal handler for SIGPIPE.  On platforms
 where this is possible (such as GNU/Linux), it disables SIGPIPE for
 its I/O operations (by passing MSG_NOSIGNAL).  On other platforms,
-SIGPIPE signals may be generated from network operations by 
+SIGPIPE signals may be generated from network operations by
 MHD and will cause the process to die unless the developer
 explicitly installs a signal handler for SIGPIPE.
 
 Hence portable code using MHD must install a SIGPIPE handler or
-explicitly block the SIGPIPE signal.  MHD does not do so in order 
+explicitly block the SIGPIPE signal.  MHD does not do so in order
 to avoid messing with other parts of the application that may
 need to handle SIGPIPE in a particular way.  You can make your application 
handle SIGPIPE by calling the following function in @code{main}:
 
@@ -422,8 +423,8 @@
 Run in debug mode.  If this flag is used, the library should print error
 messages and warnings to stderr.  Note that for this
 run-time option to have any effect, MHD needs to be
-compiled with messages enabled. This is done by default except you ran 
-configure with the @code{--disable-messages} flag set. 
+compiled with messages enabled. This is done by default except you ran
+configure with the @code{--disable-messages} flag set.
 
 @item MHD_USE_SSL
 @cindex TLS
@@ -519,7 +520,7 @@
 @code{MHD_quiesce_daemon} will fail if this option was not set.  Also,
 use of this option is automatic (as in, you do not even have to
 specify it), if @code{MHD_USE_NO_LISTEN_SOCKET} is specified.  In
-"external" select mode, this option is always simply ignored.  
+"external" select mode, this option is always simply ignored.
 
 @end table
 @end deftp
@@ -533,7 +534,7 @@
 @item MHD_OPTION_END
 No more options / last option.  This is used to terminate the VARARGs
 list.
-  
+
 @item MHD_OPTION_CONNECTION_MEMORY_LIMIT
 @cindex memory, limiting memory utilization
 Maximum memory size per connection (followed by a @code{size_t}).  The
@@ -558,19 +559,19 @@
 @code{unsigned int}).  The default is @code{FD_SETSIZE - 4} (the
 maximum number of file descriptors supported by @code{select} minus
 four for @code{stdin}, @code{stdout}, @code{stderr} and the server
-socket).  In other words, the default is as large as possible.  
+socket).  In other words, the default is as large as possible.
 
 Note that if you set a low connection limit, you can easily get into
 trouble with browsers doing request pipelining.  For example, if your
 connection limit is ``1'', a browser may open a first connection to
-access your ``index.html'' file, keep it open but use a second 
+access your ``index.html'' file, keep it open but use a second
 connection to retrieve CSS files, images and the like.  In fact, modern
 browsers are typically by default configured for up to 15 parallel
 connections to a single server.  If this happens, MHD will refuse to
 even accept the second connection until the first connection is
 closed --- which does not happen until timeout.  As a result, the
 browser will fail to render the page and seem to hang.  If you expect
-your server to operate close to the connection limit, you should 
+your server to operate close to the connection limit, you should
 first consider using a lower timeout value and also possibly add
 a ``Connection: close'' header to your response to ensure that
 request pipelining is not used and connections are closed immediately
@@ -613,8 +614,8 @@
 @item MHD_OPTION_SOCK_ADDR
 @cindex bind, restricting bind
 Bind daemon to the supplied socket address. This option should be followed by a
address@hidden sockaddr *}.  If @code{MHD_USE_IPv6} is specified, 
-the @code{struct sockaddr*} should point to a @code{struct sockaddr_in6}, 
address@hidden sockaddr *}.  If @code{MHD_USE_IPv6} is specified,
+the @code{struct sockaddr*} should point to a @code{struct sockaddr_in6},
 otherwise to a @code{struct sockaddr_in}.  If this option is not specified,
 the daemon will listen to incoming connections from anywhere.  If you use this
 option, the 'port' argument from @code{MHD_start_daemon} is ignored and the 
port
@@ -655,7 +656,7 @@
 HTTPS daemon.  This option should be followed by an
 "const char*" argument.
 This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_CERT'.
-   
+
 @item MHD_OPTION_HTTPS_MEM_CERT
 @cindex SSL
 @cindex TLS
@@ -663,7 +664,7 @@
 HTTPS daemon.  This option should be followed by an
 "const char*" argument.
 This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_KEY'.
-   
+
 @item MHD_OPTION_HTTPS_MEM_TRUST
 @cindex SSL
 @cindex TLS
@@ -677,14 +678,14 @@
 Note that most browsers will only present a client certificate
 only if they have one matching the specified CA, not sending
 any certificate otherwise.
-   
+
 @item MHD_OPTION_HTTPS_CRED_TYPE
 @cindex SSL
 @cindex TLS
 Daemon credentials type.  Either certificate or anonymous,
 this option should be followed by one of the values listed in
 "enum gnutls_credentials_type_t".
-   
+
 @item MHD_OPTION_HTTPS_PRIORITIES
 @cindex SSL
 @cindex TLS
@@ -706,7 +707,7 @@
 second argument in bytes.  Note that the application must ensure that
 the buffer of the second argument remains allocated and unmodified
 while the daemon is running.  For security, you SHOULD provide a fresh
-random nonce when using MHD with Digest Authentication.  
+random nonce when using MHD with Digest Authentication.
 
 @item MHD_OPTION_NONCE_NC_SIZE
 @cindex digest auth
@@ -737,7 +738,7 @@
 (systemd-style).  If this option is used, MHD will not open its own
 listen socket(s). The argument passed must be of type "int" and refer
 to an existing socket that has been bound to a port and is listening.
-  
+
 @item MHD_OPTION_EXTERNAL_LOGGER
 @cindex logging
 Use the given function for logging error messages.
@@ -746,11 +747,11 @@
 of type 'void fun(void * arg, const char * fmt, va_list ap)'
 and the second a pointer of type 'void*' which will
 be passed as the "arg" argument to "fun".
- 
-Note that MHD will not generate any log messages without  
-the MHD_USE_DEBUG flag set and if MHD was compiled 
-with the "--disable-messages" flag. 
 
+Note that MHD will not generate any log messages without
+the MHD_USE_DEBUG flag set and if MHD was compiled
+with the "--disable-messages" flag.
+
 @item MHD_OPTION_THREAD_POOL_SIZE
 @cindex performance
 Number (unsigned int) of threads in thread pool. Enable
@@ -806,7 +807,7 @@
 @code{cls} will be set to the second argument following
 MHD_OPTION_UNESCAPE_CALLBACK.
 
-  
+
 @item MHD_OPTION_THREAD_STACK_SIZE
 @cindex stack
 @cindex thread
@@ -814,7 +815,7 @@
 @cindex embedded systems
 Maximum stack size for threads created by MHD.  This option must be
 followed by a @code{size_t}).  Not specifying this option or using
-a value of zero means using the system default (which is likely to 
+a value of zero means using the system default (which is likely to
 differ based on your platform).
 
 @end table
@@ -823,7 +824,7 @@
 
 @deftp {C Struct} MHD_OptionItem
 Entry in an MHD_OPTION_ARRAY.  See the @code{MHD_OPTION_ARRAY} option
-argument for its use. 
+argument for its use.
 
 The @code{option} member is used to specify which option is specified
 in the array.  The other members specify the respective argument.
@@ -895,7 +896,7 @@
 
 @deftp {Enumeration} MHD_ResponseMemoryMode
 The @code{MHD_ResponeMemoryMode} specifies how MHD should treat
-the memory buffer given for the response in 
+the memory buffer given for the response in
 @code{MHD_create_response_from_buffer}.
 
 @table @code
@@ -903,12 +904,12 @@
 Buffer is a persistent (static/global) buffer that won't change
 for at least the lifetime of the response, MHD should just use
 it, not free it, not copy it, just keep an alias to it.
- 
+
 @item MHD_RESPMEM_MUST_FREE
 Buffer is heap-allocated with @code{malloc} (or equivalent) and
 should be freed by MHD after processing the response has
 concluded (response reference counter reaches zero).
-  
+
 @item MHD_RESPMEM_MUST_COPY
 Buffer is in transient memory, but not on the heap (for example,
 on the stack or non-malloc allocated) and only valid during the
@@ -1094,13 +1095,9 @@
 copy at most @var{max} bytes of content into @var{buf}.  The total
 number of bytes that has been placed into @var{buf} should be returned.
 
-Note that returning zero will cause MHD to try again, either
-``immediately'' if in multi-threaded mode (in which case the callback
-may want to do blocking operations to avoid busy waiting) or in the
-next round if @code{MHD_run} is used.  Returning zero for a daemon
-that runs in internal @code{select}-mode is an error (since it
-would result in busy waiting) and cause the program to be aborted
-(@code{abort()}).
+Note that returning zero will cause MHD to try again.
+Thus, returning zero should only be used in conjunction
+with @code{MHD_suspend_connection()} to avoid busy waiting.
 
 While usually the callback simply returns the number of bytes written
 into @var{buf}, there are two special return value:
@@ -1108,7 +1105,7 @@
 @code{MHD_CONTENT_READER_END_OF_STREAM} (-1) should be returned
 for the regular end of transmission (with chunked encoding, MHD will then
 terminate the chunk and send any HTTP footers that might be
-present; without chunked encoding and given an unknown 
+present; without chunked encoding and given an unknown
 response size, MHD will simply close the connection; note
 that while returning @code{MHD_CONTENT_READER_END_OF_STREAM} is not technically
 legal if a response size was specified, MHD accepts this
@@ -1121,7 +1118,7 @@
 an error to the client.  Note, however, that if the client
 does not know a response size and chunked encoding is not in
 use, then clients will not be able to tell the difference between
address@hidden and 
address@hidden and
 @code{MHD_CONTENT_READER_END_OF_STREAM}.
 This is not a limitation of MHD but rather of the HTTP protocol.
 
@@ -1198,7 +1195,7 @@
 Set a handler for fatal errors.
 
 @table @var
address@hidden cb 
address@hidden cb
 function to call if MHD encounters a fatal internal error.  If no handler was 
set explicitly, MHD will call @code{abort}.
 
 @item cls
@@ -1252,7 +1249,7 @@
 
 This function is useful in the special case that a listen socket
 is to be migrated to another process (i.e. a newer version of the
-HTTP server) while existing connections should continue to be 
+HTTP server) while existing connections should continue to be
 processed until they are finished.
 
 Return @code{-1} on error (daemon not listening), the handle to the
@@ -1278,7 +1275,7 @@
 instead use @code{MHD_run_from_select}, as it is more efficient.
 
 @table @var
address@hidden daemon 
address@hidden daemon
 daemon to process connections of
 @end table
 
@@ -1291,7 +1288,7 @@
 Run webserver operations given sets of ready socket handles.
 @cindex select
 
-This method should be called by clients in combination with 
+This method should be called by clients in combination with
 @code{MHD_get_fdset} if the client-controlled (external)
 select method is used.
 
@@ -1303,7 +1300,7 @@
 ready.
 
 @table @var
address@hidden daemon 
address@hidden daemon
 daemon to process connections of
 @item read_fd_set
 set of descriptors that must be ready for reading without blocking
@@ -1321,11 +1318,11 @@
 
 
 @deftypefun void MHD_add_connection (struct MHD_Daemon *daemon, int 
client_socket, const struct sockaddr *addr, socklen_t addrlen)
-Add another client connection to the set of connections 
+Add another client connection to the set of connections
 managed by MHD.  This API is usually not needed (since
 MHD will accept inbound connections on the server socket).
 Use this API in special cases, for example if your HTTP
-server is behind NAT and needs to connect out to the 
+server is behind NAT and needs to connect out to the
 HTTP client, or if you are building a proxy.
 
 If you use this API in conjunction with a internal select or a thread
@@ -1338,17 +1335,17 @@
 afterwards.
 
 @table @var
address@hidden daemon 
address@hidden daemon
 daemon that manages the connection
address@hidden client_socket 
address@hidden client_socket
 socket to manage (MHD will expect to receive an HTTP request from this socket 
next).
address@hidden addr 
address@hidden addr
 IP address of the client
address@hidden addrlen 
address@hidden addrlen
 number of bytes in addr
 @end table
 
-This function will return @code{MHD_YES} on success, 
+This function will return @code{MHD_YES} on success,
 @code{MHD_NO} if this daemon could
 not handle the connection (i.e. malloc failed, etc).
 The socket will be closed in any case; 'errno' is set
@@ -1387,7 +1384,7 @@
 @code{select} should at most block, not the timeout value set for
 connections.  This function must not be called if the
 @code{MHD_USE_THREAD_PER_CONNECTION} mode is in use (since then it
-is not meaningful to ask for a timeout, after all, there is 
+is not meaningful to ask for a timeout, after all, there is
 concurrenct activity).  The function must also not be called by
 user-code if @code{MHD_USE_INTERNAL_SELECT} is in use.  In the latter
 case, the behavior is undefined.
@@ -1411,7 +1408,7 @@
 
 
 @deftypefun int MHD_get_connection_values (struct MHD_Connection *connection, 
enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls)
-Get all the headers matching @var{kind} from the request.  
+Get all the headers matching @var{kind} from the request.
 
 The @var{iterator} callback is invoked once for each header, with
 @var{iterator_cls} as first argument.  After version 0.9.19, the
@@ -1439,9 +1436,9 @@
 
 @deftypefun int MHD_set_connection_value (struct MHD_Connection *connection, 
enum MHD_ValueKind kind, const char * key, const char * value)
 This function can be used to append an entry to
-the list of HTTP headers of a connection (so that the 
+the list of HTTP headers of a connection (so that the
 @code{MHD_get_connection_values function} will return
-them -- and the MHD PostProcessor will also 
+them -- and the MHD PostProcessor will also
 see them).  This maybe required in certain
 situations (see Mantis #1399) where (broken)
 HTTP implementations fail to supply values needed
@@ -1457,11 +1454,11 @@
 (The easiest way to do this is by passing only
 arguments to permanently allocated strings.).
 
address@hidden is the connection for which 
address@hidden is the connection for which
 the entry for @var{key} of the given @var{kind}
 should be set to the given @var{value}.
 
-The function returns @code{MHD_NO} if the operation 
+The function returns @code{MHD_NO} if the operation
 could not be performed due to insufficient memory
 and @code{MHD_YES} on success.
 @end deftypefun
@@ -1636,8 +1633,8 @@
 
 @item fd
 file descriptor referring to a file on disk with the data; will be
-closed when response is destroyed; note that 'fd' must be an actual 
-file descriptor (not a pipe or socket) since MHD might use 'sendfile' 
+closed when response is destroyed; note that 'fd' must be an actual
+file descriptor (not a pipe or socket) since MHD might use 'sendfile'
 or 'seek' on it.  The descriptor should be in blocking-IO mode.
 @end table
 
@@ -1678,8 +1675,8 @@
 
 @item fd
 file descriptor referring to a file on disk with the data; will be
-closed when response is destroyed; note that 'fd' must be an actual 
-file descriptor (not a pipe or socket) since MHD might use 'sendfile' 
+closed when response is destroyed; note that 'fd' must be an actual
+file descriptor (not a pipe or socket) since MHD might use 'sendfile'
 or 'seek' on it.    The descriptor should be in blocking-IO mode.
 
 @item offset
@@ -1701,8 +1698,8 @@
 @item buffer
 the data itself;
 
address@hidden mode 
-memory management options for buffer; use 
address@hidden mode
+memory management options for buffer; use
 MHD_RESPMEM_PERSISTENT if the buffer is static/global memory,
 use MHD_RESPMEM_MUST_FREE if the buffer is heap-allocated and
 should be freed by MHD and MHD_RESPMEM_MUST_COPY if the
@@ -1779,7 +1776,7 @@
 @deftypefun int MHD_add_response_footer (struct MHD_Response *response, const 
char *footer, const char *content)
 Add a footer line to the response. The strings referenced by
 @var{footer} and @var{content} must be zero-terminated and they are
-duplicated into memory blocks embedded in @var{response}.  
+duplicated into memory blocks embedded in @var{response}.
 
 Notice that the strings must not hold newlines, carriage returns or tab
 chars.  You can add response footers at any time before signalling the
@@ -1833,6 +1830,72 @@
 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 @c ------------------------------------------------------------
address@hidden microhttpd-flow
address@hidden Flow control.
+
address@hidden
+Sometimes it may be possible that clients upload data faster
+than an application can process it, or that an application
+needs an extended period of time to generate a response.
+If @code{MHD_USE_THREAD_PER_CONNECTION} is used, applications
+can simply deal with this by performing their logic within the
+thread and thus effectively blocking connection processing
+by MHD.  In all other modes, blocking logic must not be
+placed within the callbacks invoked by MHD as this would also
+block processing of other requests, as a single thread may be
+responsible for tens of thousands of connections.
+
+Instead, applications using thread modes other than
address@hidden should use the
+following functions to perform flow control.
+
address@hidden int MHD_suspend_connection (struct MHD_Connection *connection)
+Suspend handling of network data for a given connection.  This can
+be used to dequeue a connection from MHD's event loop (external
+select, internal select or thread pool; not applicable to
+thread-per-connection!) for a while.
+
+If you use this API in conjunction with a internal select or a
+thread pool, you must set the option @code{MHD_USE_PIPE_FOR_SHUTDOWN} to
+ensure that a resumed connection is immediately processed by MHD.
+
+Suspended connections continue to count against the total number of
+connections allowed (per daemon, as well as per IP, if such limits
+are set).  Suspended connections will NOT time out; timeouts will
+restart when the connection handling is resumed.  While a
+connection is suspended, MHD will not detect disconnects by the
+client.
+
+The only safe time to suspend a connection is from the
address@hidden
+
+Finally, it is an API violation to call @code{MHD_stop_daemon} while
+having suspended connections (this will at least create memory and
+socket leaks or lead to undefined behavior).  You must explicitly
+resume all connections before stopping the daemon.
+
address@hidden @var
address@hidden connection
+the connection to suspend
address@hidden table
address@hidden deftypefun
+
address@hidden int MHD_resume_connection (struct MHD_Connection *connection)
+Resume handling of network data for suspended connection.  It is safe
+to resume a suspended connection at any time.  Calling this function
+on a connection that was not previously suspended will result in
+undefined behavior.
+
address@hidden @var
address@hidden connection
+the connection to resume
address@hidden table
address@hidden deftypefun
+
+
address@hidden ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
address@hidden ------------------------------------------------------------
 @node microhttpd-dauth
 @chapter Utilizing Authentication
 
@@ -1960,41 +2023,41 @@
   int ret;
 
   username = MHD_digest_auth_get_username(connection);
-  if (username == NULL) 
+  if (username == NULL)
     @{
-      response = MHD_create_response_from_buffer(strlen (DENIED), 
+      response = MHD_create_response_from_buffer(strlen (DENIED),
                                                 DENIED,
-                                                MHD_RESPMEM_PERSISTENT);  
+                                                MHD_RESPMEM_PERSISTENT);
       ret = MHD_queue_auth_fail_response(connection, realm,
                                         OPAQUE,
                                         response,
-                                        MHD_NO);    
-      MHD_destroy_response(response);  
+                                        MHD_NO);
+      MHD_destroy_response(response);
       return ret;
     @}
   ret = MHD_digest_auth_check(connection, realm,
-                             username, 
-                             password, 
+                             username,
+                             password,
                              300);
   free(username);
   if ( (ret == MHD_INVALID_NONCE) ||
        (ret == MHD_NO) )
     @{
-      response = MHD_create_response_from_buffer(strlen (DENIED), 
+      response = MHD_create_response_from_buffer(strlen (DENIED),
                                                 DENIED,
-                                                MHD_RESPMEM_PERSISTENT);  
-      if (NULL == response) 
+                                                MHD_RESPMEM_PERSISTENT);
+      if (NULL == response)
        return MHD_NO;
       ret = MHD_queue_auth_fail_response(connection, realm,
                                         OPAQUE,
                                         response,
-                                        (ret == MHD_INVALID_NONCE) ? MHD_YES : 
MHD_NO);  
-      MHD_destroy_response(response);  
+                                        (ret == MHD_INVALID_NONCE) ? MHD_YES : 
MHD_NO);
+      MHD_destroy_response(response);
       return ret;
     @}
   response = MHD_create_response_from_buffer (strlen(PAGE), PAGE,
                                              MHD_RESPMEM_PERSISTENT);
-  ret = MHD_queue_response(connection, MHD_HTTP_OK, response);  
+  ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
   MHD_destroy_response(response);
   return ret;
 @}
@@ -2026,7 +2089,7 @@
 data comes in the upload buffer it is @strong{mandatory} to use the
 @var{con_cls} to store a reference to per-connection data.  The fact
 that the pointer was initially @code{NULL} can be used to detect that
-this is a new request.  
+this is a new request.
 
 One method to detect that a new connection was established is
 to set @code{*con_cls} to an unused integer:
@@ -2043,7 +2106,7 @@
   static int old_connection_marker;
   int new_connection = (NULL == *con_cls);
 
-  if (new_connection) 
+  if (new_connection)
     @{
       /* new connection with POST */
       *con_cls = &old_connection_marker;
@@ -2070,13 +2133,13 @@
 @{
   struct MHD_PostProcessor * pp = *con_cls;
 
-  if (pp == NULL) 
+  if (pp == NULL)
     @{
       pp = MHD_create_post_processor(connection, ...);
       *con_cls = pp;
       return MHD_YES;
     @}
-  if (*upload_data_size) 
+  if (*upload_data_size)
     @{
       MHD_post_process(pp, upload_data, *upload_data_size);
       *upload_data_size = 0;
@@ -2161,7 +2224,7 @@
 stream.  After destroying the PostProcessor, the programmer should
 perform any necessary work to complete the processing of the iterator.
 
-Return @code{MHD_YES} if processing completed nicely, @code{MHD_NO} 
+Return @code{MHD_YES} if processing completed nicely, @code{MHD_NO}
 if there were spurious characters or formatting problems with
 the post request.  It is common to ignore the return value
 of this function.
@@ -2285,7 +2348,7 @@
 @table @code
 
 @item MHD_CONNECTION_INFO_CIPHER_ALGO
-What cipher algorithm is being used (HTTPS connections only).  
+What cipher algorithm is being used (HTTPS connections only).
 Takes no extra arguments.
 @code{NULL} is returned for non-HTTPS connections.
 
@@ -2295,7 +2358,7 @@
 @code{NULL} is returned for non-HTTPS connections.
 
 @item MHD_CONNECTION_INFO_CLIENT_ADDRESS
-Returns information about the address of the client.  Returns 
+Returns information about the address of the client.  Returns
 essentially a @code{struct sockaddr **} (since the API returns
 a @code{union MHD_ConnectionInfo *} and that union contains
 a @code{struct sockaddr *}).
@@ -2303,7 +2366,7 @@
 @item MHD_CONNECTION_INFO_GNUTLS_SESSION,
 Takes no extra arguments.  Allows access to the underlying GNUtls session,
 including access to the underlying GNUtls client certificate
-(HTTPS connections only).  Takes no extra arguments.  
+(HTTPS connections only).  Takes no extra arguments.
 @code{NULL} is returned for non-HTTPS connections.
 
 @item MHD_CONNECTION_INFO_GNUTLS_CLIENT_CERT,
@@ -2367,7 +2430,7 @@
 @item MHD_CONNECTION_OPTION_TIMEOUT
 Set a custom timeout for the given connection.   Specified
 as the number of seconds, given as an @code{unsigned int}.  Use
-zero for no timeout. 
+zero for no timeout.
 
 @end table
 @end deftp

Modified: libmicrohttpd/src/include/microhttpd.h
===================================================================
--- libmicrohttpd/src/include/microhttpd.h      2013-10-24 08:39:55 UTC (rev 
30401)
+++ libmicrohttpd/src/include/microhttpd.h      2013-10-24 08:41:04 UTC (rev 
30402)
@@ -42,7 +42,7 @@
  *
  * MHD understands POST data and is able to decode certain formats
  * (at the moment only "application/x-www-form-urlencoded" and
- * "mulitpart/formdata"). Unsupported encodings and large POST 
+ * "mulitpart/formdata"). Unsupported encodings and large POST
  * submissions may require the application to manually process
  * the stream, which is provided to the main application (and thus can be
  * processed, just not conveniently by MHD).
@@ -99,7 +99,7 @@
    hence works on any platform, we use "standard" includes here
    to build out-of-the-box for beginning users on common systems.
 
-   Once you have a proper build system and go for more exotic 
+   Once you have a proper build system and go for more exotic
    platforms, you should define MHD_PLATFORM_H in some header that
    you always include *before* "microhttpd.h".  Then the following
    "standard" includes won't be used (which might be a good
@@ -121,7 +121,7 @@
  * Current version of the library.
  * 0x01093001 = 1.9.30-1.
  */
-#define MHD_VERSION 0x00093100
+#define MHD_VERSION 0x00093101
 
 /**
  * MHD-internal return code for "YES".
@@ -254,7 +254,7 @@
  * SHOUTcast.  This will cause the response to begin
  * with the SHOUTcast "ICY" line instad of "HTTP".
  * @ingroup specialized
- */ 
+ */
 #define MHD_ICY_FLAG ((uint32_t)(1 << 31))
 
 /**
@@ -319,7 +319,7 @@
 /** @} */ /* end of group headers */
 
 /**
- * @defgroup versions HTTP versions 
+ * @defgroup versions HTTP versions
  * These strings should be used to match against the first line of the
  * HTTP header.
  * @{
@@ -367,7 +367,7 @@
  *
  * With HTTP/1.1, multiple requests can be run over the same
  * connection.  However, MHD will only show one request per TCP
- * connection to the client at any given time.  
+ * connection to the client at any given time.
  * @ingroup request
  */
 struct MHD_Connection;
@@ -386,7 +386,7 @@
 
 
 /**
- * @brief Flags for the `struct MHD_Daemon`. 
+ * @brief Flags for the `struct MHD_Daemon`.
  *
  * Note that if neither #MHD_USE_THREAD_PER_CONNECTION nor
  * #MHD_USE_SELECT_INTERNALLY is used, the client wants control over
@@ -476,7 +476,7 @@
   MHD_USE_NO_LISTEN_SOCKET = 256,
 
   /**
-   * Use `epoll()` instead of `select()` or `poll()` for the event loop. 
+   * Use `epoll()` instead of `select()` or `poll()` for the event loop.
    * This option is only available on Linux; using the option on
    * non-Linux systems will cause #MHD_start_daemon to fail.
    */
@@ -611,9 +611,9 @@
    * parsing will no longer contain the options, which maybe inconvenient for
    * logging.  This option should be followed by two arguments, the first
    * one must be of the form
-   * 
+   *
    *     void * my_logger(void *cls, const char *uri, struct MHD_Connection 
*con)
-   * 
+   *
    * where the return value will be passed as
    * (`* con_cls`) in calls to the #MHD_AccessHandlerCallback
    * when this request is processed later; returning a
@@ -675,7 +675,7 @@
    * a function of type #MHD_LogCallback and the second a pointer
    * `void *` which will be passed as the first argument to the log
    * callback.
-   * 
+   *
    * Note that MHD will not generate any log messages
    * if it was compiled without the "--enable-messages"
    * flag being set.
@@ -696,7 +696,7 @@
    * Additional options given in an array of `struct MHD_OptionItem`.
    * The array must be terminated with an entry `{MHD_OPTION_END, 0, NULL}`.
    * An example for code using #MHD_OPTION_ARRAY is:
-   * 
+   *
    *     struct MHD_OptionItem ops[] = {
    *       { MHD_OPTION_CONNECTION_LIMIT, 100, NULL },
    *       { MHD_OPTION_CONNECTION_TIMEOUT, 10, NULL },
@@ -705,7 +705,7 @@
    *     d = MHD_start_daemon (0, 8080, NULL, NULL, dh, NULL,
    *                           MHD_OPTION_ARRAY, ops,
    *                           MHD_OPTION_END);
-   * 
+   *
    * For options that expect a single pointer argument, the
    * second member of the `struct MHD_OptionItem` is ignored.
    * For options that expect two pointer arguments, the first
@@ -721,7 +721,7 @@
    * decodes escape sequences of the form "%HH".  This option should
    * be followed by two arguments, the first one must be of the form
    *
-   *     size_t my_unescaper(void *cls, 
+   *     size_t my_unescaper(void *cls,
    *                         struct MHD_Connection *c,
    *                         char *s)
    *
@@ -737,7 +737,7 @@
    * Memory pointer for the random values to be used by the Digest
    * Auth module. This option should be followed by two arguments.
    * First an integer of type  `size_t` which specifies the size
-   * of the buffer pointed to by the second argument in bytes.  
+   * of the buffer pointed to by the second argument in bytes.
    * Note that the application must ensure that the buffer of the
    * second argument remains allocated and unmodified while the
    * deamon is running.
@@ -919,7 +919,7 @@
   int /* enum gnutls_protocol */ protocol;
 
   /**
-   * Connect socket 
+   * Connect socket
    */
   int connect_fd;
 
@@ -1046,7 +1046,7 @@
  * @param reason error detail, may be NULL
  * @ingroup logging
  */
-typedef 
+typedef
   void (*MHD_PanicCallback) (void *cls,
                             const char *file,
                             unsigned int line,
@@ -1076,7 +1076,7 @@
  * @param cls argument given together with the function
  *        pointer when the handler was registered with MHD
  * @param url the requested url
- * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 
+ * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
  *        #MHD_HTTP_METHOD_PUT, etc.)
  * @param version the HTTP version string (i.e.
  *        #MHD_HTTP_VERSION_1_1)
@@ -1157,12 +1157,9 @@
  * total number of bytes that has been placed into @a buf should be
  * returned.
  *
- * Note that returning zero will cause libmicrohttpd to try again,
- * either "immediately" if in multi-threaded mode (in which case the
- * callback may want to do blocking operations) or in the next round
- * if #MHD_run is used.  Returning 0 for a daemon that runs in internal
- * select mode is an error (since it would result in busy waiting) and
- * will cause the program to be aborted (via `abort()`).
+ * Note that returning zero will cause libmicrohttpd to try again.
+ * Thus, returning zero should only be used in conjunction
+ * with MHD_suspend_connection() to avoid busy waiting.
  *
  * @param cls extra argument to the callback
  * @param pos position in the datastream to access;
@@ -1175,7 +1172,7 @@
  *        obtained from the content reader so far.
  * @param buf where to copy the data
  * @param max maximum number of bytes to copy to @a buf (size of @a buf)
- * @return number of bytes written to @a buf; 
+ * @return number of bytes written to @a buf;
  *  0 is legal unless we are running in internal select mode (since
  *    this would cause busy-waiting); 0 in external select mode
  *    will cause this function to be called again once the external
@@ -1183,7 +1180,7 @@
  *  #MHD_CONTENT_READER_END_OF_STREAM (-1) for the regular
  *    end of transmission (with chunked encoding, MHD will then
  *    terminate the chunk and send any HTTP footers that might be
- *    present; without chunked encoding and given an unknown 
+ *    present; without chunked encoding and given an unknown
  *    response size, MHD will simply close the connection; note
  *    that while returning #MHD_CONTENT_READER_END_OF_STREAM is not technically
  *    legal if a response size was specified, MHD accepts this
@@ -1214,7 +1211,7 @@
  * @param cls closure
  * @ingroup response
  */
-typedef void 
+typedef void
   (*MHD_ContentReaderFreeCallback) (void *cls);
 
 
@@ -1244,8 +1241,8 @@
                            const char *filename,
                            const char *content_type,
                            const char *transfer_encoding,
-                           const char *data, 
-                          uint64_t off, 
+                           const char *data,
+                          uint64_t off,
                           size_t size);
 
 /* **************** Daemon handling functions ***************** */
@@ -1271,7 +1268,7 @@
 MHD_start_daemon_va (unsigned int flags,
                     uint16_t port,
                     MHD_AcceptPolicyCallback apc, void *apc_cls,
-                    MHD_AccessHandlerCallback dh, void *dh_cls, 
+                    MHD_AccessHandlerCallback dh, void *dh_cls,
                     va_list ap);
 
 
@@ -1295,7 +1292,7 @@
 MHD_start_daemon (unsigned int flags,
                  uint16_t port,
                  MHD_AcceptPolicyCallback apc, void *apc_cls,
-                 MHD_AccessHandlerCallback dh, void *dh_cls, 
+                 MHD_AccessHandlerCallback dh, void *dh_cls,
                  ...);
 
 
@@ -1314,7 +1311,7 @@
  * #MHD_start_daemon, this function will return -1.
  *
  * @param daemon daemon to stop accepting new connections for
- * @return old listen socket on success, -1 if the daemon was 
+ * @return old listen socket on success, -1 if the daemon was
  *         already not listening anymore
  * @ingroup specialized
  */
@@ -1328,7 +1325,7 @@
  * @param daemon daemon to stop
  * @ingroup event
  */
-void 
+void
 MHD_stop_daemon (struct MHD_Daemon *daemon);
 
 
@@ -1361,8 +1358,8 @@
  *        set to indicate further details about the error.
  * @ingroup specialized
  */
-int 
-MHD_add_connection (struct MHD_Daemon *daemon, 
+int
+MHD_add_connection (struct MHD_Daemon *daemon,
                    int client_socket,
                    const struct sockaddr *addr,
                    socklen_t addrlen);
@@ -1385,8 +1382,8 @@
 int
 MHD_get_fdset (struct MHD_Daemon *daemon,
                fd_set *read_fd_set,
-               fd_set *write_fd_set, 
-              fd_set *except_fd_set, 
+               fd_set *write_fd_set,
+              fd_set *except_fd_set,
               int *max_fd);
 
 
@@ -1404,8 +1401,8 @@
  *        necessiate the use of a timeout right now).
  * @ingroup event
  */
-int 
-MHD_get_timeout (struct MHD_Daemon *daemon, 
+int
+MHD_get_timeout (struct MHD_Daemon *daemon,
                 MHD_UNSIGNED_LONG_LONG *timeout);
 
 
@@ -1428,7 +1425,7 @@
  *         options for this call.
  * @ingroup event
  */
-int 
+int
 MHD_run (struct MHD_Daemon *daemon);
 
 
@@ -1452,7 +1449,7 @@
  * @ingroup event
  */
 int
-MHD_run_from_select (struct MHD_Daemon *daemon, 
+MHD_run_from_select (struct MHD_Daemon *daemon,
                     const fd_set *read_fd_set,
                     const fd_set *write_fd_set,
                     const fd_set *except_fd_set);
@@ -1486,7 +1483,7 @@
  * them).  This maybe required in certain situations (see Mantis
  * #1399) where (broken) HTTP implementations fail to supply values
  * needed by the post processor (or other parts of the application).
- * 
+ *
  * This function MUST only be called from within the
  * #MHD_AccessHandlerCallback (otherwise, access maybe improperly
  * synchronized).  Furthermore, the client must guarantee that the key
@@ -1507,7 +1504,7 @@
 int
 MHD_set_connection_value (struct MHD_Connection *connection,
                           enum MHD_ValueKind kind,
-                          const char *key, 
+                          const char *key,
                          const char *value);
 
 
@@ -1527,7 +1524,7 @@
  * @param cls passed to @a cb
  * @ingroup logging
  */
-void 
+void
 MHD_set_panic_func (MHD_PanicCallback cb, void *cls);
 
 
@@ -1560,10 +1557,53 @@
  */
 int
 MHD_queue_response (struct MHD_Connection *connection,
-                    unsigned int status_code, 
+                    unsigned int status_code,
                    struct MHD_Response *response);
 
 
+/**
+ * Suspend handling of network data for a given connection.  This can
+ * be used to dequeue a connection from MHD's event loop (external
+ * select, internal select or thread pool; not applicable to
+ * thread-per-connection!) for a while.
+ *
+ * If you use this API in conjunction with a internal select or a
+ * thread pool, you must set the option #MHD_USE_PIPE_FOR_SHUTDOWN to
+ * ensure that a resumed connection is immediately processed by MHD.
+ *
+ * Suspended connections continue to count against the total number of
+ * connections allowed (per daemon, as well as per IP, if such limits
+ * are set).  Suspended connections will NOT time out; timeouts will
+ * restart when the connection handling is resumed.  While a
+ * connection is suspended, MHD will not detect disconnects by the
+ * client.
+ *
+ * The only safe time to suspend a connection is from the
+ * #MHD_AccessHandlerCallback.
+ *
+ * Finally, it is an API violation to call #MHD_stop_daemon while
+ * having suspended connections (this will at least create memory and
+ * socket leaks or lead to undefined behavior).  You must explicitly
+ * resume all connections before stopping the daemon.
+ *
+ * @param connection the connection to suspend
+ */
+void
+MHD_suspend_connection (struct MHD_Connection *connection);
+
+
+/**
+ * Resume handling of network data for suspended connection.  It is
+ * safe to resume a suspended connection at any time.  Calling this
+ * function on a connection that was not previously suspended will
+ * result in undefined behavior.
+ *
+ * @param connection the connection to resume
+ */
+void
+MHD_resume_connection (struct MHD_Connection *connection);
+
+
 /* **************** Response manipulation functions ***************** */
 
 /**
@@ -1615,7 +1655,7 @@
  * given for the response.
  * @ingroup response
  */
-enum MHD_ResponseMemoryMode 
+enum MHD_ResponseMemoryMode
 {
 
   /**
@@ -1667,7 +1707,7 @@
  * header information and then be used any number of times.
  *
  * @param size size of the data portion of the response
- * @param fd file descriptor referring to a file on disk with the 
+ * @param fd file descriptor referring to a file on disk with the
  *        data; will be closed when response is destroyed;
  *        fd should be in 'blocking' mode
  * @return NULL on error (i.e. invalid arguments, out of memory)
@@ -1687,7 +1727,7 @@
  *        data; will be closed when response is destroyed;
  *        fd should be in 'blocking' mode
  * @param offset offset to start reading from in the file;
- *        Be careful! `off_t` may have been compiled to be a 
+ *        Be careful! `off_t` may have been compiled to be a
  *        64-bit variable for MHD, in which case your application
  *        also has to be compiled using the same options! Read
  *        the MHD manual for more details.
@@ -1705,7 +1745,7 @@
  * Bits in an event mask that specifies which actions
  * MHD should perform and under which conditions it
  * should call the 'upgrade' callback again.
- */ 
+ */
 enum MHD_UpgradeEventMask
 {
 
@@ -1731,7 +1771,7 @@
    * Do not wait on any socket actions, we're waiting on
    * an 'external' event.  Run the function again once
    * the 'select' call returns _without_ this socket even
-   * being involved in the select sets (useful in 
+   * being involved in the select sets (useful in
    * conjunction with the external select loop).
    */
   MHD_UPGRADE_EVENT_EXTERNAL = 4,
@@ -1743,15 +1783,15 @@
    * may ignore if the platform does not support it).  Note that
    * only returning 'CORK' will *also* cause the socket to be closed!
    */
-  MHD_UPGRADE_EVENT_CORK = 8  
-    
+  MHD_UPGRADE_EVENT_CORK = 8
+
 };
 
 
 /**
  * Function called after a protocol "upgrade" response was sent
  * successfully and the socket should now be controlled by some
- * protocol other than HTTP. 
+ * protocol other than HTTP.
  *
  * Any data received on the socket will be made available in
  * 'data_in'.  The function should update 'data_in_size' to
@@ -1786,7 +1826,7 @@
  *                be also given to the #MHD_RequestCompletedCallback
  * @param data_in_size available data for reading, set to data read
  * @param data_in data read from the socket
- * @param data_out_size available buffer for writing, set to bytes 
+ * @param data_out_size available buffer for writing, set to bytes
  *                written to 'data_out'
  * @param data_out buffer for sending data via the connection
  * @return desired actions for event handling loop
@@ -1843,7 +1883,7 @@
  * @param response response to destroy
  * @ingroup response
  */
-void 
+void
 MHD_destroy_response (struct MHD_Response *response);
 
 
@@ -1874,7 +1914,7 @@
  */
 int
 MHD_add_response_footer (struct MHD_Response *response,
-                         const char *footer, 
+                         const char *footer,
                         const char *content);
 
 
@@ -1889,7 +1929,7 @@
  */
 int
 MHD_del_response_header (struct MHD_Response *response,
-                         const char *header, 
+                         const char *header,
                         const char *content);
 
 
@@ -1982,7 +2022,7 @@
  *                value of this function
  * @ingroup request
  */
-int 
+int
 MHD_destroy_post_processor (struct MHD_PostProcessor *pp);
 
 
@@ -2098,7 +2138,7 @@
  */
 const union MHD_ConnectionInfo *
 MHD_get_connection_info (struct MHD_Connection *connection,
-                        enum MHD_ConnectionInfoType info_type, 
+                        enum MHD_ConnectionInfoType info_type,
                         ...);
 
 
@@ -2128,12 +2168,12 @@
  * @return #MHD_YES on success, #MHD_NO if setting the option failed
  * @ingroup specialized
  */
-int 
+int
 MHD_set_connection_option (struct MHD_Connection *connection,
                           enum MHD_CONNECTION_OPTION option,
                           ...);
-                          
 
+
 /**
  * Information about an MHD daemon.
  */
@@ -2171,7 +2211,7 @@
  */
 const union MHD_DaemonInfo *
 MHD_get_daemon_info (struct MHD_Daemon *daemon,
-                    enum MHD_DaemonInfoType info_type, 
+                    enum MHD_DaemonInfoType info_type,
                     ...);
 
 
@@ -2181,7 +2221,7 @@
  * @return static version string, e.g. "0.9.9"
  * @ingroup specialized
  */
-const char* 
+const char*
 MHD_get_version (void);
 
 

Modified: libmicrohttpd/src/microhttpd/EXPORT.sym
===================================================================
--- libmicrohttpd/src/microhttpd/EXPORT.sym     2013-10-24 08:39:55 UTC (rev 
30401)
+++ libmicrohttpd/src/microhttpd/EXPORT.sym     2013-10-24 08:41:04 UTC (rev 
30402)
@@ -35,3 +35,5 @@
 MHD_queue_basic_auth_fail_response
 MHD_add_connection
 MHD_set_connection_option
+MHD_suspend_connection
+MHD_resume_connection

Modified: libmicrohttpd/src/microhttpd/connection.c
===================================================================
--- libmicrohttpd/src/microhttpd/connection.c   2013-10-24 08:39:55 UTC (rev 
30401)
+++ libmicrohttpd/src/microhttpd/connection.c   2013-10-24 08:41:04 UTC (rev 
30402)
@@ -148,7 +148,7 @@
  * them).  This maybe required in certain situations (see Mantis
  * #1399) where (broken) HTTP implementations fail to supply values
  * needed by the post processor (or other parts of the application).
- * 
+ *
  * This function MUST only be called from within the
  * #MHD_AccessHandlerCallback (otherwise, access maybe improperly
  * synchronized).  Furthermore, the client must guarantee that the key
@@ -215,12 +215,12 @@
   if (NULL == connection)
     return NULL;
   for (pos = connection->headers_received; NULL != pos; pos = pos->next)
-    if ((0 != (pos->kind & kind)) && 
+    if ((0 != (pos->kind & kind)) &&
        ( (key == pos->header) ||
          ( (NULL != pos->header) &&
            (NULL != key) &&
            (0 == strcasecmp (key, pos->header))) ))
-      return pos->value;    
+      return pos->value;
   return NULL;
 }
 
@@ -265,13 +265,13 @@
 
   daemon = connection->daemon;
   if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO))
-    SHUTDOWN (connection->socket_fd, 
+    SHUTDOWN (connection->socket_fd,
              (MHD_YES == connection->read_closed) ? SHUT_WR : SHUT_RDWR);
   connection->state = MHD_CONNECTION_CLOSED;
   connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP;
   if ( (NULL != daemon->notify_completed) &&
        (MHD_YES == connection->client_aware) )
-    daemon->notify_completed (daemon->notify_completed_cls, 
+    daemon->notify_completed (daemon->notify_completed_cls,
                              connection,
                              &connection->client_context,
                              termination_code);
@@ -342,25 +342,16 @@
        (0 == (connection->daemon->options & MHD_USE_SSL)) )
     {
       /* will use sendfile, no need to bother response crc */
-      return MHD_YES; 
+      return MHD_YES;
     }
 #endif
-  
+
   ret = response->crc (response->crc_cls,
                        connection->response_write_position,
                        response->data,
                        MHD_MIN (response->data_buffer_size,
                                 response->total_size -
                                 connection->response_write_position));
-  if ((0 == ret) &&
-      (0 != (connection->daemon->options & MHD_USE_SELECT_INTERNALLY)))
-    mhd_panic (mhd_panic_cls, __FILE__, __LINE__
-#if HAVE_MESSAGES
-              , "API violation"
-#else
-              , NULL
-#endif
-              );
   if ( (MHD_CONTENT_READER_END_OF_STREAM == ret) ||
        (MHD_CONTENT_READER_END_WITH_ERROR == ret) )
     {
@@ -368,7 +359,7 @@
       response->total_size = connection->response_write_position;
       if (NULL != response->crc)
        pthread_mutex_unlock (&response->mutex);
-      if (MHD_CONTENT_READER_END_OF_STREAM == ret) 
+      if (MHD_CONTENT_READER_END_OF_STREAM == ret)
        MHD_connection_close (connection, MHD_REQUEST_TERMINATED_COMPLETED_OK);
       else
        CONNECTION_CLOSE_ERROR (connection,
@@ -470,14 +461,14 @@
       response->total_size = connection->response_write_position;
       return MHD_YES;
     }
-  if (0 == ret) 
+  if (0 == ret)
     {
       connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY;
       return MHD_NO;
     }
   if (ret > 0xFFFFFF)
     ret = 0xFFFFFF;
-  snprintf (cbuf, 
+  snprintf (cbuf,
            sizeof (cbuf),
            "%X\r\n", (unsigned int) ret);
   cblen = strlen (cbuf);
@@ -528,7 +519,7 @@
             if the client asked for a close, no need to start chunk'ing */
           if ((NULL == client_close) &&
              (NULL != connection->version) &&
-              (0 == strcasecmp (connection->version, MHD_HTTP_VERSION_1_1))) 
+              (0 == strcasecmp (connection->version, MHD_HTTP_VERSION_1_1)))
             {
               connection->have_chunked_upload = MHD_YES;
               have_encoding = MHD_get_response_header (connection->response,
@@ -562,17 +553,17 @@
                               MHD_HTTP_METHOD_CONNECT)) ||
             (0 != connection->response->total_size) ) )
        {
-         /* 
+         /*
             Here we add a content-length if one is missing; however,
-            for 'connect' methods, the responses MUST NOT include a 
+            for 'connect' methods, the responses MUST NOT include a
             content-length header *if* the response code is 2xx (in
             which case we expect there to be no body).  Still,
-            as we don't know the response code here in some cases, we 
+            as we don't know the response code here in some cases, we
             simply only force adding a content-length header if this
             is not a 'connect' or if the response is not empty
             (which is kind of more sane, because if some crazy
             application did return content with a 2xx status code,
-            then having a content-length might again be a good idea). 
+            then having a content-length might again be a good idea).
 
             Note that the change from 'SHOULD NOT' to 'MUST NOT' is
             a recent development of the HTTP 1.1 specification.
@@ -616,8 +607,8 @@
            (unsigned int) now.tm_mday,
            mons[now.tm_mon % 12],
            (unsigned int) (1900 + now.tm_year),
-          (unsigned int) now.tm_hour, 
-          (unsigned int) now.tm_min, 
+          (unsigned int) now.tm_hour,
+          (unsigned int) now.tm_min,
           (unsigned int) now.tm_sec);
 }
 
@@ -626,7 +617,7 @@
  * Try growing the read buffer.  We initially claim half the
  * available buffer space for the read buffer (the other half
  * being left for management data structures; the write
- * buffer can in the end take virtually everything as the 
+ * buffer can in the end take virtually everything as the
  * read buffer can be reduced to the minimum necessary at that
  * point.
  *
@@ -696,18 +687,18 @@
       SPRINTF (code,
                "%s %u %s\r\n",
               (0 != (connection->responseCode & MHD_ICY_FLAG))
-              ? "ICY" 
+              ? "ICY"
               : ( (0 == strcasecmp (MHD_HTTP_VERSION_1_0,
-                                    connection->version)) 
-                  ? MHD_HTTP_VERSION_1_0 
+                                    connection->version))
+                  ? MHD_HTTP_VERSION_1_0
                   : MHD_HTTP_VERSION_1_1),
-              rc, 
+              rc,
               reason_phrase);
       off = strlen (code);
       /* estimate size */
       size = off + 2;           /* extra \r\n at the end */
       kind = MHD_HEADER_KIND;
-      if ( (0 == (connection->daemon->options & MHD_SUPPRESS_DATE_NO_CLOCK)) 
&& 
+      if ( (0 == (connection->daemon->options & MHD_SUPPRESS_DATE_NO_CLOCK)) &&
           (NULL == MHD_get_response_header (connection->response,
                                             MHD_HTTP_HEADER_DATE)) )
         get_date_string (date);
@@ -757,9 +748,9 @@
     }
   for (pos = connection->response->first_header; NULL != pos; pos = pos->next)
     if (pos->kind == kind)
-      off += SPRINTF (&data[off], 
+      off += SPRINTF (&data[off],
                      "%s: %s\r\n",
-                     pos->header, 
+                     pos->header,
                      pos->value);
   if (connection->state == MHD_CONNECTION_FOOTERS_RECEIVED)
     {
@@ -790,7 +781,7 @@
  */
 static void
 transmit_error_response (struct MHD_Connection *connection,
-                         unsigned int status_code, 
+                         unsigned int status_code,
                         const char *message)
 {
   struct MHD_Response *response;
@@ -810,7 +801,7 @@
 #endif
   EXTRA_CHECK (NULL == connection->response);
   response = MHD_create_response_from_buffer (strlen (message),
-                                             (void *) message, 
+                                             (void *) message,
                                              MHD_RESPMEM_PERSISTENT);
   MHD_queue_response (connection, status_code, response);
   EXTRA_CHECK (NULL != connection->response);
@@ -834,7 +825,7 @@
  * perform other updates to the connection if needed to prepare for
  * the next round of the event loop.
  *
- * @param connection connetion to get poll set for 
+ * @param connection connetion to get poll set for
  */
 static void
 MHD_connection_update_event_loop_info (struct MHD_Connection *connection)
@@ -847,7 +838,7 @@
 #endif
       switch (connection->state)
         {
-#if HTTPS_SUPPORT     
+#if HTTPS_SUPPORT
        case MHD_TLS_CONNECTION_INIT:
          if (0 == gnutls_record_get_direction (connection->tls_session))
             connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
@@ -921,7 +912,7 @@
              read buffer if needed, no size-check required */
           if (MHD_YES == connection->read_closed)
             {
-             CONNECTION_CLOSE_ERROR (connection, 
+             CONNECTION_CLOSE_ERROR (connection,
                                      NULL);
               continue;
             }
@@ -1000,7 +991,7 @@
     {
       /* not found, consider growing... */
       if ( (connection->read_buffer_offset == connection->read_buffer_size) &&
-          (MHD_NO == 
+          (MHD_NO ==
            try_grow_read_buffer (connection)) )
        {
          transmit_error_response (connection,
@@ -1008,7 +999,7 @@
                                   ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE
                                   : MHD_HTTP_REQUEST_URI_TOO_LONG,
                                   REQUEST_TOO_BIG);
-       }        
+       }
       return NULL;
     }
   /* found, check if we have proper LFCR */
@@ -1064,7 +1055,7 @@
  */
 static int
 parse_arguments (enum MHD_ValueKind kind,
-                 struct MHD_Connection *connection, 
+                 struct MHD_Connection *connection,
                 char *args)
 {
   char *equals;
@@ -1086,7 +1077,7 @@
              return connection_add_header (connection,
                                            args,
                                            NULL,
-                                           kind);            
+                                           kind);
            }
          /* got 'foo=bar' */
          equals[0] = '\0';
@@ -1261,7 +1252,7 @@
     }
   if (NULL != connection->daemon->uri_log_callback)
     connection->client_context
-      = connection->daemon->uri_log_callback 
(connection->daemon->uri_log_callback_cls, 
+      = connection->daemon->uri_log_callback 
(connection->daemon->uri_log_callback_cls,
                                              uri,
                                              connection);
   args = strchr (uri, '?');
@@ -1296,7 +1287,7 @@
   size_t processed;
 
   if (NULL != connection->response)
-    return;                     /* already queued a response */  
+    return;                     /* already queued a response */
   processed = 0;
   connection->client_aware = MHD_YES;
   if (MHD_NO ==
@@ -1309,7 +1300,7 @@
                                           &connection->client_context))
     {
       /* serious internal error, close connection */
-      CONNECTION_CLOSE_ERROR (connection, 
+      CONNECTION_CLOSE_ERROR (connection,
                              "Internal application error, closing 
connection.\n");
       return;
     }
@@ -1438,7 +1429,7 @@
       else
         {
           /* no chunked encoding, give all to the client */
-          if ( (0 != connection->remaining_upload_size) && 
+          if ( (0 != connection->remaining_upload_size) &&
               (MHD_SIZE_UNKNOWN != connection->remaining_upload_size) &&
               (connection->remaining_upload_size < available) )
            {
@@ -1527,7 +1518,7 @@
                  "Failed to receive data: %s\n",
                  gnutls_strerror (bytes_read));
       else
-#endif      
+#endif
        MHD_DLOG (connection->daemon,
                  "Failed to receive data: %s\n", STRERROR (errno));
 #endif
@@ -1577,7 +1568,7 @@
                  "Failed to send data: %s\n",
                  gnutls_strerror (ret));
       else
-#endif      
+#endif
        MHD_DLOG (connection->daemon,
                  "Failed to send data: %s\n", STRERROR (errno));
 #endif
@@ -1613,7 +1604,7 @@
   connection->write_buffer_append_offset = 0;
   connection->write_buffer_send_offset = 0;
   connection->state = next_state;
-  MHD_pool_reallocate (connection->pool, 
+  MHD_pool_reallocate (connection->pool,
                       connection->write_buffer,
                        connection->write_buffer_size, 0);
   connection->write_buffer = NULL;
@@ -1641,7 +1632,7 @@
   if (NULL == colon)
     {
       /* error in header line, die hard */
-      CONNECTION_CLOSE_ERROR (connection, 
+      CONNECTION_CLOSE_ERROR (connection,
                              "Received malformed line (no colon), closing 
connection.\n");
       return MHD_NO;
     }
@@ -1689,7 +1680,7 @@
       /* skip whitespace at start of 2nd line */
       tmp = line;
       while ((tmp[0] == ' ') || (tmp[0] == '\t'))
-        tmp++;                  
+        tmp++;
       tmp_len = strlen (tmp);
       /* FIXME: we might be able to do this better (faster!), as most
         likely 'last' and 'line' should already be adjacent in
@@ -1833,7 +1824,7 @@
   /* move connection to head of timeout list (by remove + add operation) */
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
        (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
-    MHD_PANIC ("Failed to acquire cleanup mutex\n");    
+    MHD_PANIC ("Failed to acquire cleanup mutex\n");
   XDLL_remove (daemon->normal_timeout_head,
               daemon->normal_timeout_tail,
               connection);
@@ -1842,13 +1833,13 @@
               connection);
   if  ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
        (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
-    MHD_PANIC ("Failed to release cleanup mutex\n");    
+    MHD_PANIC ("Failed to release cleanup mutex\n");
 }
 
 
 /**
  * This function handles a particular connection when it has been
- * determined that there is data to be read off a socket. 
+ * determined that there is data to be read off a socket.
  *
  * @param connection connection to handle
  * @return always #MHD_YES (we should continue to process the
@@ -1982,10 +1973,10 @@
           break;
         case MHD_CONNECTION_NORMAL_BODY_READY:
           response = connection->response;
-          if (response->crc != NULL)
+          if (NULL != response->crc)
             pthread_mutex_lock (&response->mutex);
-          if (MHD_YES != try_ready_normal_body (connection))            
-           break;            
+          if (MHD_YES != try_ready_normal_body (connection))
+           break;
          ret = connection->send_cls (connection,
                                      &response->data
                                      [connection->response_write_position
@@ -2001,7 +1992,7 @@
                      &response->data[connection->response_write_position -
                                      response->data_start]);
 #endif
-          if (response->crc != NULL)
+          if (NULL != response->crc)
             pthread_mutex_unlock (&response->mutex);
           if (ret < 0)
             {
@@ -2078,8 +2069,8 @@
       connection->response = NULL;
     }
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )         
-    MHD_PANIC ("Failed to acquire cleanup mutex\n");           
+       (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
+    MHD_PANIC ("Failed to acquire cleanup mutex\n");
   if (connection->connection_timeout == daemon->connection_timeout)
     XDLL_remove (daemon->normal_timeout_head,
                 daemon->normal_timeout_tail,
@@ -2095,15 +2086,15 @@
              daemon->cleanup_tail,
              connection);
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) )        
        
-    MHD_PANIC ("Failed to release cleanup mutex\n");       
+       (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) )
+    MHD_PANIC ("Failed to release cleanup mutex\n");
   connection->in_idle = MHD_NO;
 }
 
 
 /**
  * This function was created to handle per-connection processing that
- * has to happen even if the socket cannot be read or written to. 
+ * has to happen even if the socket cannot be read or written to.
  *
  * @param connection connection to handle
  * @return #MHD_YES if we should continue to process the
@@ -2135,7 +2126,7 @@
                 continue;
               if (MHD_YES == connection->read_closed)
                 {
-                 CONNECTION_CLOSE_ERROR (connection, 
+                 CONNECTION_CLOSE_ERROR (connection,
                                          NULL);
                   continue;
                 }
@@ -2154,7 +2145,7 @@
                 continue;
               if (MHD_YES == connection->read_closed)
                 {
-                 CONNECTION_CLOSE_ERROR (connection, 
+                 CONNECTION_CLOSE_ERROR (connection,
                                          NULL);
                   continue;
                 }
@@ -2182,7 +2173,7 @@
                 continue;
               if (MHD_YES == connection->read_closed)
                 {
-                 CONNECTION_CLOSE_ERROR (connection, 
+                 CONNECTION_CLOSE_ERROR (connection,
                                          NULL);
                   continue;
                 }
@@ -2262,7 +2253,7 @@
                 continue;
               if (MHD_YES == connection->read_closed)
                 {
-                 CONNECTION_CLOSE_ERROR (connection, 
+                 CONNECTION_CLOSE_ERROR (connection,
                                          NULL);
                   continue;
                 }
@@ -2290,7 +2281,7 @@
                 continue;
               if (MHD_YES == connection->read_closed)
                 {
-                 CONNECTION_CLOSE_ERROR (connection, 
+                 CONNECTION_CLOSE_ERROR (connection,
                                          NULL);
                   continue;
                 }
@@ -2314,7 +2305,7 @@
           if (MHD_NO == build_header_response (connection))
             {
               /* oops - close! */
-             CONNECTION_CLOSE_ERROR (connection, 
+             CONNECTION_CLOSE_ERROR (connection,
                                      "Closing connection (failed to create 
response header)\n");
               continue;
             }
@@ -2342,11 +2333,11 @@
           /* nothing to do here */
           break;
         case MHD_CONNECTION_NORMAL_BODY_UNREADY:
-          if (connection->response->crc != NULL)
+          if (NULL != connection->response->crc)
             pthread_mutex_lock (&connection->response->mutex);
           if (0 == connection->response->total_size)
             {
-              if (connection->response->crc != NULL)
+              if (NULL != connection->response->crc)
                 pthread_mutex_unlock (&connection->response->mutex);
               connection->state = MHD_CONNECTION_BODY_SENT;
               continue;
@@ -2364,23 +2355,23 @@
           /* nothing to do here */
           break;
         case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
-          if (connection->response->crc != NULL)
+          if (NULL != connection->response->crc)
             pthread_mutex_lock (&connection->response->mutex);
           if (0 == connection->response->total_size)
             {
-              if (connection->response->crc != NULL)
+              if (NULL != connection->response->crc)
                 pthread_mutex_unlock (&connection->response->mutex);
               connection->state = MHD_CONNECTION_BODY_SENT;
               continue;
             }
           if (MHD_YES == try_ready_chunked_body (connection))
             {
-              if (connection->response->crc != NULL)
+              if (NULL != connection->response->crc)
                 pthread_mutex_unlock (&connection->response->mutex);
               connection->state = MHD_CONNECTION_CHUNKED_BODY_READY;
               continue;
             }
-          if (connection->response->crc != NULL)
+          if (NULL != connection->response->crc)
             pthread_mutex_unlock (&connection->response->mutex);
           break;
         case MHD_CONNECTION_BODY_SENT:
@@ -2404,7 +2395,7 @@
           }
 #endif
           end =
-            MHD_get_response_header (connection->response, 
+            MHD_get_response_header (connection->response,
                                     MHD_HTTP_HEADER_CONNECTION);
          rend = ( (MHD_YES == connection->read_closed) ||
                   ( (end != NULL) && (0 == strcasecmp (end, "close")) ) );
@@ -2414,7 +2405,7 @@
            daemon->notify_completed (daemon->notify_completed_cls,
                                      connection,
                                      &connection->client_context,
-                                                 
MHD_REQUEST_TERMINATED_COMPLETED_OK);     
+                                                 
MHD_REQUEST_TERMINATED_COMPLETED_OK);
          connection->client_aware = MHD_NO;
           end =
             MHD_lookup_connection_value (connection, MHD_HEADER_KIND,
@@ -2478,7 +2469,7 @@
       return MHD_YES;
     }
   MHD_connection_update_event_loop_info (connection);
-#if EPOLL_SUPPORT   
+#if EPOLL_SUPPORT
   switch (connection->event_loop_info)
     {
     case MHD_EVENT_LOOP_INFO_READ:
@@ -2492,7 +2483,7 @@
        }
       break;
     case MHD_EVENT_LOOP_INFO_WRITE:
-      if ( (connection->read_buffer_size > connection->read_buffer_offset) && 
+      if ( (connection->read_buffer_size > connection->read_buffer_offset) &&
           (0 != (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) &&
           (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) )
        {
@@ -2517,7 +2508,7 @@
        {
          EDLL_insert (daemon->eready_head,
                       daemon->eready_tail,
-                      connection);      
+                      connection);
          connection->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
        }
       break;
@@ -2540,13 +2531,13 @@
  * @param connection connection to process
  * @return #MHD_YES if we should continue to process the
  *         connection (not dead yet), #MHD_NO if it died
- */ 
+ */
 int
 MHD_connection_epoll_update_ (struct MHD_Connection *connection)
 {
   struct MHD_Daemon *daemon = connection->daemon;
 
-  if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&  
+  if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
        (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) &&
        ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_WRITE_READY)) ||
         ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) &&
@@ -2558,7 +2549,7 @@
       struct epoll_event event;
 
       event.events = EPOLLIN | EPOLLOUT | EPOLLET;
-      event.data.ptr = connection;       
+      event.data.ptr = connection;
       if (0 != epoll_ctl (daemon->epoll_fd,
                          EPOLL_CTL_ADD,
                          connection->socket_fd,
@@ -2566,8 +2557,8 @@
        {
 #if HAVE_MESSAGES
          if (0 != (daemon->options & MHD_USE_DEBUG))
-           MHD_DLOG (daemon, 
-                     "Call to epoll_ctl failed: %s\n", 
+           MHD_DLOG (daemon,
+                     "Call to epoll_ctl failed: %s\n",
                      STRERROR (errno));
 #endif
          connection->state = MHD_CONNECTION_CLOSED;
@@ -2649,7 +2640,7 @@
  * @return #MHD_YES on success, #MHD_NO if setting the option failed
  * @ingroup specialized
  */
-int 
+int
 MHD_set_connection_option (struct MHD_Connection *connection,
                           enum MHD_CONNECTION_OPTION option,
                           ...)
@@ -2657,13 +2648,13 @@
   va_list ap;
   struct MHD_Daemon *daemon;
 
-  daemon = connection->daemon;      
+  daemon = connection->daemon;
   switch (option)
     {
     case MHD_CONNECTION_OPTION_TIMEOUT:
       if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
           (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
-       MHD_PANIC ("Failed to acquire cleanup mutex\n");    
+       MHD_PANIC ("Failed to acquire cleanup mutex\n");
       if (connection->connection_timeout == daemon->connection_timeout)
        XDLL_remove (daemon->normal_timeout_head,
                     daemon->normal_timeout_tail,
@@ -2685,7 +2676,7 @@
                     connection);
       if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
           (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
-       MHD_PANIC ("Failed to release cleanup mutex\n");    
+       MHD_PANIC ("Failed to release cleanup mutex\n");
       return MHD_YES;
     default:
       return MHD_NO;

Modified: libmicrohttpd/src/microhttpd/daemon.c
===================================================================
--- libmicrohttpd/src/microhttpd/daemon.c       2013-10-24 08:39:55 UTC (rev 
30401)
+++ libmicrohttpd/src/microhttpd/daemon.c       2013-10-24 08:41:04 UTC (rev 
30402)
@@ -104,7 +104,7 @@
  * @param line line number with the problem
  * @param reason error message with details
  */
-static void 
+static void
 mhd_panic_std (void *cls,
               const char *file,
               unsigned int line,
@@ -133,7 +133,7 @@
  * Trace up to and return master daemon. If the supplied daemon
  * is a master, then return the daemon itself.
  *
- * @param daemon handle to a daemon 
+ * @param daemon handle to a daemon
  * @return master daemon handle
  */
 static struct MHD_Daemon*
@@ -162,12 +162,12 @@
   {
     /**
      * IPv4 address.
-     */ 
+     */
     struct in_addr ipv4;
 #if HAVE_IPV6
     /**
      * IPv6 address.
-     */ 
+     */
     struct in6_addr ipv6;
 #endif
   } addr;
@@ -213,7 +213,7 @@
  * Tree comparison function for IP addresses (supplied to tsearch() family).
  * We compare everything in the struct up through the beginning of the
  * 'count' field.
- * 
+ *
  * @param a1 first address to compare
  * @param a2 second address to compare
  * @return -1, 0 or 1 depending on result of compare
@@ -234,7 +234,7 @@
  * @return #MHD_YES on success and #MHD_NO otherwise (e.g., invalid address 
type)
  */
 static int
-MHD_ip_addr_to_key (const struct sockaddr *addr, 
+MHD_ip_addr_to_key (const struct sockaddr *addr,
                    socklen_t addrlen,
                    struct MHD_IPCount *key)
 {
@@ -302,14 +302,14 @@
   MHD_ip_count_lock (daemon);
 
   /* Search for the IP address */
-  if (NULL == (nodep = TSEARCH (key, 
-                               &daemon->per_ip_connection_count, 
+  if (NULL == (nodep = TSEARCH (key,
+                               &daemon->per_ip_connection_count,
                                &MHD_ip_addr_compare)))
     {
 #if HAVE_MESSAGES
       MHD_DLOG (daemon,
                "Failed to add IP connection count node\n");
-#endif      
+#endif
       MHD_ip_count_unlock (daemon);
       free (key);
       return MHD_NO;
@@ -358,10 +358,10 @@
   MHD_ip_count_lock (daemon);
 
   /* Search for the IP address */
-  if (NULL == (nodep = TFIND (&search_key, 
-                             &daemon->per_ip_connection_count, 
+  if (NULL == (nodep = TFIND (&search_key,
+                             &daemon->per_ip_connection_count,
                              &MHD_ip_addr_compare)))
-    {      
+    {
       /* Something's wrong if we couldn't find an IP address
        * that was previously added */
       MHD_PANIC ("Failed to find previously-added IP address\n");
@@ -375,8 +375,8 @@
   /* Remove the node entirely if count reduces to 0 */
   if (0 == --found_key->count)
     {
-      TDELETE (found_key, 
-              &daemon->per_ip_connection_count, 
+      TDELETE (found_key,
+              &daemon->per_ip_connection_count,
               &MHD_ip_addr_compare);
       free (found_key);
     }
@@ -409,7 +409,7 @@
        (GNUTLS_E_INTERRUPTED == res) )
     {
       errno = EINTR;
-#if EPOLL_SUPPORT   
+#if EPOLL_SUPPORT
       connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
 #endif
       return -1;
@@ -451,7 +451,7 @@
     {
       fprintf (stderr, "WAGAIN!\n");
       errno = EINTR;
-#if EPOLL_SUPPORT   
+#if EPOLL_SUPPORT
       connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
 #endif
       return -1;
@@ -472,12 +472,12 @@
   gnutls_datum_t key;
   gnutls_datum_t cert;
 
-  if (NULL != daemon->https_mem_trust) 
+  if (NULL != daemon->https_mem_trust)
     {
       cert.data = (unsigned char *) daemon->https_mem_trust;
       cert.size = strlen (daemon->https_mem_trust);
       if (gnutls_certificate_set_x509_trust_mem (daemon->x509_cred, &cert,
-                                                GNUTLS_X509_FMT_PEM) < 0) 
+                                                GNUTLS_X509_FMT_PEM) < 0)
        {
 #if HAVE_MESSAGES
          MHD_DLOG(daemon,
@@ -486,9 +486,9 @@
          return -1;
        }
     }
-  
+
   /* certificate & key loaded from memory */
-  if ( (NULL != daemon->https_mem_cert) && 
+  if ( (NULL != daemon->https_mem_cert) &&
        (NULL != daemon->https_mem_key) )
     {
       key.data = (unsigned char *) daemon->https_mem_key;
@@ -544,8 +544,8 @@
  * @param max_fd maximum value to potentially update
  */
 static void
-add_to_fd_set (int fd, 
-              fd_set *set, 
+add_to_fd_set (int fd,
+              fd_set *set,
               int *max_fd)
 {
   FD_SET (fd, set);
@@ -572,17 +572,17 @@
 int
 MHD_get_fdset (struct MHD_Daemon *daemon,
                fd_set *read_fd_set,
-               fd_set *write_fd_set, 
+               fd_set *write_fd_set,
               fd_set *except_fd_set,
               int *max_fd)
 {
   struct MHD_Connection *pos;
   int fd;
 
-  if ( (NULL == daemon) 
-       || (NULL == read_fd_set) 
+  if ( (NULL == daemon)
+       || (NULL == read_fd_set)
        || (NULL == write_fd_set)
-       || (NULL == except_fd_set) 
+       || (NULL == except_fd_set)
        || (NULL == max_fd)
        || (MHD_YES == daemon->shutdown)
        || (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
@@ -597,7 +597,7 @@
       if (daemon->epoll_fd >= FD_SETSIZE)
        return MHD_NO; /* poll fd too big, fail hard */
       FD_SET (daemon->epoll_fd, read_fd_set);
-      if ((*max_fd) < daemon->epoll_fd) 
+      if ((*max_fd) < daemon->epoll_fd)
        *max_fd = daemon->epoll_fd;
       return MHD_YES;
     }
@@ -607,7 +607,7 @@
   {
     FD_SET (fd, read_fd_set);
     /* update max file descriptor */
-    if ((*max_fd) < fd) 
+    if ((*max_fd) < fd)
       *max_fd = fd;
   }
   for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
@@ -643,7 +643,7 @@
 /**
  * Main function of the thread that handles an individual
  * connection when #MHD_USE_THREAD_PER_CONNECTION is set.
- * 
+ *
  * @param data the 'struct MHD_Connection' this thread will handle
  * @return always NULL
  */
@@ -664,8 +664,8 @@
 #endif
 
   timeout = con->daemon->connection_timeout;
-  while ( (MHD_YES != con->daemon->shutdown) && 
-         (MHD_CONNECTION_CLOSED != con->state) ) 
+  while ( (MHD_YES != con->daemon->shutdown) &&
+         (MHD_CONNECTION_CLOSED != con->state) )
     {
       tvp = NULL;
       if (timeout > 0)
@@ -715,13 +715,13 @@
              goto exit;
            }
          num_ready = SELECT (max + 1, &rs, &ws, NULL, tvp);
-         if (num_ready < 0) 
+         if (num_ready < 0)
            {
              if (EINTR == errno)
                continue;
 #if HAVE_MESSAGES
              MHD_DLOG (con->daemon,
-                       "Error during select (%d): `%s'\n", 
+                       "Error during select (%d): `%s'\n",
                        max,
                        STRERROR (errno));
 #endif
@@ -730,7 +730,7 @@
          /* call appropriate connection handler if necessary */
          if ( (FD_ISSET (con->socket_fd, &rs))
 #if HTTPS_SUPPORT
-              || (MHD_YES == con->tls_read_ready) 
+              || (MHD_YES == con->tls_read_ready)
 #endif
               )
            con->read_handler (con);
@@ -748,16 +748,16 @@
          switch (con->event_loop_info)
            {
            case MHD_EVENT_LOOP_INFO_READ:
-             p[0].events |= POLLIN;  
+             p[0].events |= POLLIN;
              break;
            case MHD_EVENT_LOOP_INFO_WRITE:
              p[0].events |= POLLOUT;
              if (con->read_buffer_size > con->read_buffer_offset)
-               p[0].events |= POLLIN;  
+               p[0].events |= POLLIN;
              break;
            case MHD_EVENT_LOOP_INFO_BLOCK:
              if (con->read_buffer_size > con->read_buffer_offset)
-               p[0].events |= POLLIN;  
+               p[0].events |= POLLIN;
              tv.tv_sec = 0;
              tv.tv_usec = 0;
              tvp = &tv;
@@ -766,27 +766,27 @@
              /* how did we get here!? */
              goto exit;
            }
-         if (poll (p, 1, 
+         if (poll (p, 1,
                    (NULL == tvp) ? -1 : tv.tv_sec * 1000) < 0)
            {
              if (EINTR == errno)
                continue;
 #if HAVE_MESSAGES
-             MHD_DLOG (con->daemon, "Error during poll: `%s'\n", 
+             MHD_DLOG (con->daemon, "Error during poll: `%s'\n",
                        STRERROR (errno));
 #endif
              break;
            }
-         if ( (0 != (p[0].revents & POLLIN)) 
+         if ( (0 != (p[0].revents & POLLIN))
 #if HTTPS_SUPPORT
-              || (MHD_YES == con->tls_read_ready) 
+              || (MHD_YES == con->tls_read_ready)
 #endif
               )
-           con->read_handler (con);        
-         if (0 != (p[0].revents & POLLOUT)) 
-           con->write_handler (con);        
-         if (0 != (p[0].revents & (POLLERR | POLLHUP))) 
-           MHD_connection_close (con, MHD_REQUEST_TERMINATED_WITH_ERROR);      
+           con->read_handler (con);
+         if (0 != (p[0].revents & POLLOUT))
+           con->write_handler (con);
+         if (0 != (p[0].revents & (POLLERR | POLLHUP)))
+           MHD_connection_close (con, MHD_REQUEST_TERMINATED_WITH_ERROR);
          if (MHD_NO == con->idle_handler (con))
            goto exit;
        }
@@ -801,7 +801,7 @@
 #endif
 #endif
       if (MHD_CONNECTION_CLOSED != con->state)
-       MHD_connection_close (con, 
+       MHD_connection_close (con,
                              MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN);
       con->idle_handler (con);
     }
@@ -825,7 +825,7 @@
  */
 static ssize_t
 recv_param_adapter (struct MHD_Connection *connection,
-                   void *other, 
+                   void *other,
                    size_t i)
 {
   ssize_t ret;
@@ -887,7 +887,7 @@
       left = connection->response->total_size - 
connection->response_write_position;
       if (left > SSIZE_MAX)
        left = SSIZE_MAX; /* cap at return value limit */
-      if (-1 != (ret = sendfile (connection->socket_fd, 
+      if (-1 != (ret = sendfile (connection->socket_fd,
                                 fd,
                                 &offset,
                                 (size_t) left)))
@@ -904,7 +904,7 @@
       if ( (EINTR == errno) || (EAGAIN == errno) )
        return 0;
       if ( (EINVAL == errno) || (EBADF == errno) )
-       return -1; 
+       return -1;
       /* None of the 'usual' sendfile errors occurred, so we should try
         to fall back to 'SEND'; see also this thread for info on
         odd libc/Linux behavior with sendfile:
@@ -934,7 +934,7 @@
 
 /**
  * Create a thread and set the attributes according to our options.
- * 
+ *
  * @param thread handle to initialize
  * @param daemon daemon with options
  * @param start_routine main function of thread
@@ -950,10 +950,10 @@
   pthread_attr_t attr;
   pthread_attr_t *pattr;
   int ret;
-  
-  if (0 != daemon->thread_stack_size) 
+
+  if (0 != daemon->thread_stack_size)
     {
-      if (0 != (ret = pthread_attr_init (&attr))) 
+      if (0 != (ret = pthread_attr_init (&attr)))
        goto ERR;
       if (0 != (ret = pthread_attr_setstacksize (&attr, 
daemon->thread_stack_size)))
        {
@@ -973,7 +973,7 @@
   (void) pthread_setname_np (*thread, "libmicrohttpd");
 #endif
 #endif
-  if (0 != daemon->thread_stack_size) 
+  if (0 != daemon->thread_stack_size)
     pthread_attr_destroy (&attr);
   return ret;
  ERR:
@@ -987,11 +987,11 @@
 
 
 /**
- * Add another client connection to the set of connections 
+ * Add another client connection to the set of connections
  * managed by MHD.  This API is usually not needed (since
  * MHD will accept inbound connections on the server socket).
  * Use this API in special cases, for example if your HTTP
- * server is behind NAT and needs to connect out to the 
+ * server is behind NAT and needs to connect out to the
  * HTTP client.
  *
  * The given client socket will be managed (and closed!) by MHD after
@@ -1012,8 +1012,8 @@
  *        The socket will be closed in any case; 'errno' is
  *        set to indicate further details about the error.
  */
-static int 
-internal_add_connection (struct MHD_Daemon *daemon, 
+static int
+internal_add_connection (struct MHD_Daemon *daemon,
                         int client_socket,
                         const struct sockaddr *addr,
                         socklen_t addrlen,
@@ -1025,7 +1025,7 @@
   int eno;
 #if OSX
   static int on = 1;
-#endif  
+#endif
 
   if (NULL != daemon->worker_pool)
     {
@@ -1044,7 +1044,7 @@
 #if ENFILE
       errno = ENFILE;
 #endif
-      return MHD_NO;      
+      return MHD_NO;
     }
 
 #ifndef WINDOWS
@@ -1089,8 +1089,8 @@
     }
 
   /* apply connection acceptance policy if present */
-  if ( (NULL != daemon->apc) && 
-       (MHD_NO == daemon->apc (daemon->apc_cls, 
+  if ( (NULL != daemon->apc) &&
+       (MHD_NO == daemon->apc (daemon->apc_cls,
                               addr, addrlen)) )
     {
 #if DEBUG_CLOSE
@@ -1110,8 +1110,8 @@
 #if OSX
 #ifdef SOL_SOCKET
 #ifdef SO_NOSIGPIPE
-  setsockopt (client_socket, 
-             SOL_SOCKET, SO_NOSIGPIPE, 
+  setsockopt (client_socket,
+             SOL_SOCKET, SO_NOSIGPIPE,
              &on, sizeof (on));
 #endif
 #endif
@@ -1121,8 +1121,8 @@
     {
       eno = errno;
 #if HAVE_MESSAGES
-      MHD_DLOG (daemon, 
-               "Error allocating memory: %s\n", 
+      MHD_DLOG (daemon,
+               "Error allocating memory: %s\n",
                STRERROR (errno));
 #endif
       if (0 != CLOSE (client_socket))
@@ -1136,14 +1136,14 @@
   if (NULL == connection->pool)
     {
 #if HAVE_MESSAGES
-      MHD_DLOG (daemon, 
-               "Error allocating memory: %s\n", 
+      MHD_DLOG (daemon,
+               "Error allocating memory: %s\n",
                STRERROR (errno));
 #endif
       if (0 != CLOSE (client_socket))
        MHD_PANIC ("close failed\n");
       MHD_ip_limit_del (daemon, addr, addrlen);
-      free (connection);      
+      free (connection);
 #if ENOMEM
       errno = ENOMEM;
 #endif
@@ -1155,8 +1155,8 @@
     {
       eno = errno;
 #if HAVE_MESSAGES
-      MHD_DLOG (daemon, 
-               "Error allocating memory: %s\n", 
+      MHD_DLOG (daemon,
+               "Error allocating memory: %s\n",
                STRERROR (errno));
 #endif
       if (0 != CLOSE (client_socket))
@@ -1172,7 +1172,7 @@
   connection->socket_fd = client_socket;
   connection->daemon = daemon;
   connection->last_activity = MHD_monotonic_time();
-  
+
   /* set default connection handlers  */
   MHD_set_http_callbacks_ (connection);
   connection->recv_cls = &recv_param_adapter;
@@ -1196,7 +1196,7 @@
            {
 #if HAVE_MESSAGES
              MHD_DLOG (daemon,
-                       "Failed to make socket %d non-blocking: %s\n", 
+                       "Failed to make socket %d non-blocking: %s\n",
                        connection->socket_fd,
                        STRERROR (errno));
 #endif
@@ -1206,8 +1206,8 @@
          if (0 != ioctlsocket (connection->socket_fd, FIONBIO, &flags))
            {
 #if HAVE_MESSAGES
-             MHD_DLOG (daemon, 
-                       "Failed to make socket non-blocking: %s\n", 
+             MHD_DLOG (daemon,
+                       "Failed to make socket non-blocking: %s\n",
                        STRERROR (errno));
 #endif
            }
@@ -1258,14 +1258,14 @@
                                          (gnutls_push_func) 
&send_param_adapter);
 
       if (daemon->https_mem_trust)
-         gnutls_certificate_server_set_request (connection->tls_session, 
+         gnutls_certificate_server_set_request (connection->tls_session,
                                                 GNUTLS_CERT_REQUEST);
     }
 #endif
 
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
        (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
-    MHD_PANIC ("Failed to acquire cleanup mutex\n");    
+    MHD_PANIC ("Failed to acquire cleanup mutex\n");
   XDLL_insert (daemon->normal_timeout_head,
               daemon->normal_timeout_tail,
               connection);
@@ -1274,7 +1274,7 @@
              connection);
   if  ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
        (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
-    MHD_PANIC ("Failed to release cleanup mutex\n");    
+    MHD_PANIC ("Failed to release cleanup mutex\n");
 
   /* attempt to create handler thread */
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
@@ -1307,9 +1307,9 @@
       if (0 == (daemon->options & MHD_USE_EPOLL_TURBO))
        {
          struct epoll_event event;
-         
+
          event.events = EPOLLIN | EPOLLOUT | EPOLLET;
-         event.data.ptr = connection;    
+         event.data.ptr = connection;
          if (0 != epoll_ctl (daemon->epoll_fd,
                              EPOLL_CTL_ADD,
                              client_socket,
@@ -1317,10 +1317,9 @@
            {
              eno = errno;
 #if HAVE_MESSAGES
-             if (0 != (daemon->options & MHD_USE_DEBUG))
-               MHD_DLOG (daemon, 
-                         "Call to epoll_ctl failed: %s\n", 
-                         STRERROR (errno));
+              MHD_DLOG (daemon,
+                        "Call to epoll_ctl failed: %s\n",
+                        STRERROR (errno));
 #endif
              goto cleanup;
            }
@@ -1336,15 +1335,15 @@
        }
     }
 #endif
-  daemon->max_connections--;  
-  return MHD_YES;  
+  daemon->max_connections--;
+  return MHD_YES;
  cleanup:
   if (0 != CLOSE (client_socket))
     MHD_PANIC ("close failed\n");
   MHD_ip_limit_del (daemon, addr, addrlen);
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )    
-    MHD_PANIC ("Failed to acquire cleanup mutex\n");    
+       (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
+    MHD_PANIC ("Failed to acquire cleanup mutex\n");
   DLL_remove (daemon->connections_head,
              daemon->connections_tail,
              connection);
@@ -1354,7 +1353,7 @@
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
        (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to release cleanup mutex\n");
-  MHD_pool_destroy (connection->pool); 
+  MHD_pool_destroy (connection->pool);
   free (connection->addr);
   free (connection);
 #if EINVAL
@@ -1365,11 +1364,150 @@
 
 
 /**
+ * Suspend handling of network data for a given connection.  This can
+ * be used to dequeue a connection from MHD's event loop (external
+ * select, internal select or thread pool; not applicable to
+ * thread-per-connection!) for a while.
+ *
+ * If you use this API in conjunction with a internal select or a
+ * thread pool, you must set the option #MHD_USE_PIPE_FOR_SHUTDOWN to
+ * ensure that a resumed connection is immediately processed by MHD.
+ *
+ * Suspended connections continue to count against the total number of
+ * connections allowed (per daemon, as well as per IP, if such limits
+ * are set).  Suspended connections will NOT time out; timeouts will
+ * restart when the connection handling is resumed.  While a
+ * connection is suspended, MHD will not detect disconnects by the
+ * client.
+ *
+ * The only safe time to suspend a connection is from the
+ * #MHD_AccessHandlerCallback.
+ *
+ * Finally, it is an API violation to call #MHD_stop_daemon while
+ * having suspended connections (this will at least create memory and
+ * socket leaks or lead to undefined behavior).  You must explicitly
+ * resume all connections before stopping the daemon.
+ *
+ * @param connection the connection to suspend
+ */
+void
+MHD_suspend_connection (struct MHD_Connection *connection)
+{
+  struct MHD_Daemon *daemon;
+
+  daemon = connection->daemon;
+  if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
+    MHD_PANIC ("Cannot suspend connections in THREAD_PER_CONNECTION mode!\n");
+  DLL_remove (daemon->connections_head,
+              daemon->connections_tail,
+              connection);
+  if (connection->connection_timeout == daemon->connection_timeout)
+    XDLL_remove (daemon->normal_timeout_head,
+                 daemon->normal_timeout_tail,
+                 connection);
+  else
+    XDLL_remove (daemon->manual_timeout_head,
+                 daemon->manual_timeout_tail,
+                 connection);
+#if EPOLL_SUPPORT
+  if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
+    {
+      EDLL_remove (daemon->eready_head,
+                   daemon->eready_tail,
+                   connection);
+    }
+  if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET))
+    {
+      if (0 != epoll_ctl (daemon->epoll_fd,
+                          EPOLL_CTL_DEL,
+                          connection->socket_fd,
+                          NULL))
+        MHD_PANIC ("Failed to remove FD from epoll set\n");
+      connection->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET;
+    }
+#endif
+}
+
+
+/**
+ * Resume handling of network data for suspended connection.  It is
+ * safe to resume a suspended connection at any time.  Calling this function
+ * on a connection that was not previously suspended will result
+ * in undefined behavior.
+ *
+ * @param connection the connection to resume
+ */
+void
+MHD_resume_connection (struct MHD_Connection *connection)
+{
+  struct MHD_Daemon *daemon;
+
+  daemon = connection->daemon;
+  if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
+    MHD_PANIC ("Cannot resume connections in THREAD_PER_CONNECTION mode!\n");
+  if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
+       (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
+    MHD_PANIC ("Failed to acquire cleanup mutex\n");
+  DLL_insert (daemon->connections_head,
+              daemon->connections_tail,
+              connection);
+  if (connection->connection_timeout == daemon->connection_timeout)
+    XDLL_insert (daemon->normal_timeout_head,
+                 daemon->normal_timeout_tail,
+                 connection);
+  else
+    XDLL_insert (daemon->manual_timeout_head,
+                 daemon->manual_timeout_tail,
+                 connection);
+#if EPOLL_SUPPORT
+  if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
+    {
+      EDLL_insert (daemon->eready_head,
+                   daemon->eready_tail,
+                   connection);
+    }
+  else
+    {
+      struct epoll_event event;
+
+      event.events = EPOLLIN | EPOLLOUT | EPOLLET;
+      event.data.ptr = connection;
+      if (0 != epoll_ctl (daemon->epoll_fd,
+                          EPOLL_CTL_ADD,
+                          connection->socket_fd,
+                          &event))
+        {
+#if HAVE_MESSAGES
+          MHD_DLOG (daemon,
+                    "Call to epoll_ctl failed: %s\n",
+                    STRERROR (errno));
+#endif
+          /* and now, good luck with this... */
+        }
+      else
+        connection->epoll_state |= MHD_EPOLL_STATE_IN_EPOLL_SET;
+    }
+#endif
+  if ( (-1 != daemon->wpipe[1]) &&
+       (1 != WRITE (daemon->wpipe[1], "n", 1)) )
+    {
+#if HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                "failed to signal resume via pipe");
+#endif
+    }
+  if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
+       (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
+    MHD_PANIC ("Failed to release cleanup mutex\n");
+}
+
+
+/**
  * Change socket options to be non-blocking, non-inheritable.
  *
  * @param daemon daemon context
  * @param sock socket to manipulate
- */ 
+ */
 static void
 make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
                                 int sock)
@@ -1389,12 +1527,12 @@
 #ifdef WINDOWS
   DWORD dwFlags;
   unsigned long flags = 1;
-  
+
   if (0 != ioctlsocket (sock, FIONBIO, &flags))
     {
 #if HAVE_MESSAGES
-      MHD_DLOG (daemon, 
-               "Failed to make socket non-blocking: %s\n", 
+      MHD_DLOG (daemon,
+               "Failed to make socket non-blocking: %s\n",
                STRERROR (errno));
 #endif
     }
@@ -1405,13 +1543,13 @@
 #if HAVE_MESSAGES
       SetErrnoFromWinError (GetLastError ());
       MHD_DLOG (daemon,
-               "Failed to make socket non-inheritable: %s\n", 
+               "Failed to make socket non-inheritable: %s\n",
                STRERROR (errno));
 #endif
-    }    
+    }
 #else
   int flags;
-  
+
   nonblock = O_NONBLOCK;
 #ifdef CYGWIN
   if (0 == (daemon->options & MHD_USE_SSL))
@@ -1424,7 +1562,7 @@
     {
 #if HAVE_MESSAGES
       MHD_DLOG (daemon,
-               "Failed to make socket non-inheritable: %s\n", 
+               "Failed to make socket non-inheritable: %s\n",
                STRERROR (errno));
 #endif
     }
@@ -1461,13 +1599,13 @@
  *        set to indicate further details about the error.
  * @ingroup specialized
  */
-int 
-MHD_add_connection (struct MHD_Daemon *daemon, 
+int
+MHD_add_connection (struct MHD_Daemon *daemon,
                    int client_socket,
                    const struct sockaddr *addr,
                    socklen_t addrlen)
 {
-  make_nonblocking_noninheritable (daemon, 
+  make_nonblocking_noninheritable (daemon,
                                   client_socket);
   return internal_add_connection (daemon,
                                  client_socket,
@@ -1480,7 +1618,7 @@
  * Accept an incoming connection and create the MHD_Connection object for
  * it.  This function also enforces policy by way of checking with the
  * accept policy callback.
- * 
+ *
  * @param daemon handle with the listen socket
  * @return MHD_YES on success (connections denied by policy or due
  *         to 'out of memory' and similar errors) are still considered
@@ -1525,8 +1663,8 @@
 #if HAVE_MESSAGES
       /* This could be a common occurance with multiple worker threads */
       if ((EAGAIN != errno) && (EWOULDBLOCK != errno))
-        MHD_DLOG (daemon, 
-                 "Error accepting connection: %s\n", 
+        MHD_DLOG (daemon,
+                 "Error accepting connection: %s\n",
                  STRERROR (errno));
 #endif
       if (-1 != s)
@@ -1567,7 +1705,7 @@
 
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
        (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
-    MHD_PANIC ("Failed to acquire cleanup mutex\n");    
+    MHD_PANIC ("Failed to acquire cleanup mutex\n");
   while (NULL != (pos = daemon->cleanup_head))
     {
       DLL_remove (daemon->cleanup_head,
@@ -1575,7 +1713,7 @@
                  pos);
       if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
           (MHD_NO == pos->thread_joined) )
-       { 
+       {
          if (0 != (rc = pthread_join (pos->pid, &unused)))
            {
              MHD_PANIC ("Failed to join a thread\n");
@@ -1586,8 +1724,8 @@
       if (pos->tls_session != NULL)
        gnutls_deinit (pos->tls_session);
 #endif
-      MHD_ip_limit_del (daemon, 
-                       (struct sockaddr *) pos->addr, 
+      MHD_ip_limit_del (daemon,
+                       (struct sockaddr *) pos->addr,
                        pos->addr_len);
 #if EPOLL_SUPPORT
       if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
@@ -1633,9 +1771,9 @@
       free (pos);
       daemon->max_connections++;
     }
-  if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 
-       (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )    
-    MHD_PANIC ("Failed to release cleanup mutex\n");    
+  if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
+       (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
+    MHD_PANIC ("Failed to release cleanup mutex\n");
 }
 
 
@@ -1666,7 +1804,7 @@
     {
 #if HAVE_MESSAGES
       MHD_DLOG (daemon, "Illegal call to MHD_get_timeout\n");
-#endif  
+#endif
       return MHD_NO;
     }
 
@@ -1683,7 +1821,7 @@
   have_timeout = MHD_NO;
   for (pos = daemon->manual_timeout_head; NULL != pos; pos = pos->nextX)
     {
-      if (0 != pos->connection_timeout) 
+      if (0 != pos->connection_timeout)
        {
          if ( (! have_timeout) ||
               (earliest_deadline > pos->last_activity + 
pos->connection_timeout) )
@@ -1743,7 +1881,7 @@
  * @ingroup event
  */
 int
-MHD_run_from_select (struct MHD_Daemon *daemon, 
+MHD_run_from_select (struct MHD_Daemon *daemon,
                     const fd_set *read_fd_set,
                     const fd_set *write_fd_set,
                     const fd_set *except_fd_set)
@@ -1790,7 +1928,7 @@
            case MHD_EVENT_LOOP_INFO_READ:
              if ( (FD_ISSET (ds, read_fd_set))
 #if HTTPS_SUPPORT
-                  || (MHD_YES == pos->tls_read_ready) 
+                  || (MHD_YES == pos->tls_read_ready)
 #endif
                   )
                pos->read_handler (pos);
@@ -1811,7 +1949,7 @@
              /* should never happen */
              break;
            }
-         pos->idle_handler (pos);      
+         pos->idle_handler (pos);
         }
     }
   MHD_cleanup_connections (daemon);
@@ -1828,7 +1966,7 @@
  * @return #MHD_NO on serious errors, #MHD_YES on success
  */
 static int
-MHD_select (struct MHD_Daemon *daemon, 
+MHD_select (struct MHD_Daemon *daemon,
            int may_block)
 {
   int num_ready;
@@ -1856,14 +1994,14 @@
 
       /* If we're at the connection limit, no need to
          accept new connections. */
-      if ( (0 == daemon->max_connections) && 
+      if ( (0 == daemon->max_connections) &&
           (-1 != daemon->socket_fd) )
         FD_CLR (daemon->socket_fd, &rs);
     }
   else
     {
       /* accept only, have one thread per connection */
-      if (-1 != daemon->socket_fd) 
+      if (-1 != daemon->socket_fd)
        {
          max = daemon->socket_fd;
          FD_SET (daemon->socket_fd, &rs);
@@ -1938,7 +2076,7 @@
     int timeout;
     unsigned int poll_server;
     int poll_listen;
-    
+
     memset (p, 0, sizeof (p));
     poll_server = 0;
     poll_listen = -1;
@@ -1952,7 +2090,7 @@
        poll_listen = (int) poll_server;
        poll_server++;
       }
-    if (-1 != daemon->wpipe[0]) 
+    if (-1 != daemon->wpipe[0])
       {
        p[poll_server].fd = daemon->wpipe[0];
        p[poll_server].events = POLLIN;
@@ -1966,7 +2104,7 @@
       timeout = -1;
     else
       timeout = (ltimeout > INT_MAX) ? INT_MAX : (int) ltimeout;
-    
+
     i = 0;
     for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
       {
@@ -1974,16 +2112,16 @@
        switch (pos->event_loop_info)
          {
          case MHD_EVENT_LOOP_INFO_READ:
-           p[poll_server+i].events |= POLLIN;        
+           p[poll_server+i].events |= POLLIN;
            break;
          case MHD_EVENT_LOOP_INFO_WRITE:
            p[poll_server+i].events |= POLLOUT;
            if (pos->read_buffer_size > pos->read_buffer_offset)
-             p[poll_server+i].events |= POLLIN;        
+             p[poll_server+i].events |= POLLIN;
            break;
          case MHD_EVENT_LOOP_INFO_BLOCK:
            if (pos->read_buffer_size > pos->read_buffer_offset)
-             p[poll_server+i].events |= POLLIN;        
+             p[poll_server+i].events |= POLLIN;
            break;
          case MHD_EVENT_LOOP_INFO_CLEANUP:
            /* should never happen */
@@ -1993,20 +2131,20 @@
       }
     if (0 == poll_server + num_connections)
       return MHD_YES;
-    if (poll (p, poll_server + num_connections, timeout) < 0) 
+    if (poll (p, poll_server + num_connections, timeout) < 0)
       {
        if (EINTR == errno)
          return MHD_YES;
 #if HAVE_MESSAGES
-       MHD_DLOG (daemon, 
-                 "poll failed: %s\n", 
+       MHD_DLOG (daemon,
+                 "poll failed: %s\n",
                  STRERROR (errno));
 #endif
        return MHD_NO;
       }
     /* handle shutdown */
     if (MHD_YES == daemon->shutdown)
-      return MHD_NO;  
+      return MHD_NO;
     i = 0;
     next = daemon->connections_head;
     while (NULL != (pos = next))
@@ -2017,11 +2155,11 @@
          case MHD_EVENT_LOOP_INFO_READ:
            /* first, sanity checks */
            if (i >= num_connections)
-             break; /* connection list changed somehow, retry later ... */     
+             break; /* connection list changed somehow, retry later ... */
            if (p[poll_server+i].fd != pos->socket_fd)
              break; /* fd mismatch, something else happened, retry later ... */
            /* normal handling */
-           if (0 != (p[poll_server+i].revents & POLLIN)) 
+           if (0 != (p[poll_server+i].revents & POLLIN))
              pos->read_handler (pos);
            pos->idle_handler (pos);
            i++;
@@ -2029,19 +2167,19 @@
          case MHD_EVENT_LOOP_INFO_WRITE:
            /* first, sanity checks */
            if (i >= num_connections)
-             break; /* connection list changed somehow, retry later ... */     
+             break; /* connection list changed somehow, retry later ... */
            if (p[poll_server+i].fd != pos->socket_fd)
              break; /* fd mismatch, something else happened, retry later ... */
            /* normal handling */
-           if (0 != (p[poll_server+i].revents & POLLIN)) 
+           if (0 != (p[poll_server+i].revents & POLLIN))
              pos->read_handler (pos);
-           if (0 != (p[poll_server+i].revents & POLLOUT)) 
+           if (0 != (p[poll_server+i].revents & POLLOUT))
              pos->write_handler (pos);
            pos->idle_handler (pos);
            i++;
            break;
          case MHD_EVENT_LOOP_INFO_BLOCK:
-           if (0 != (p[poll_server+i].revents & POLLIN)) 
+           if (0 != (p[poll_server+i].revents & POLLIN))
              pos->read_handler (pos);
            pos->idle_handler (pos);
            break;
@@ -2074,7 +2212,7 @@
   int timeout;
   unsigned int poll_count;
   int poll_listen;
-    
+
   memset (&p, 0, sizeof (p));
   poll_count = 0;
   poll_listen = -1;
@@ -2110,10 +2248,10 @@
     }
   /* handle shutdown */
   if (MHD_YES == daemon->shutdown)
-    return MHD_NO;  
+    return MHD_NO;
   if ( (-1 != poll_listen) &&
        (0 != (p[poll_listen].revents & POLLIN)) )
-    (void) MHD_accept_connection (daemon);  
+    (void) MHD_accept_connection (daemon);
   return MHD_YES;
 }
 #endif
@@ -2175,7 +2313,7 @@
   int timeout_ms;
   MHD_UNSIGNED_LONG_LONG timeout_ll;
   int num_events;
-  unsigned int i;  
+  unsigned int i;
   unsigned int series_length;
 
   if (-1 == daemon->epoll_fd)
@@ -2187,7 +2325,7 @@
        (MHD_NO == daemon->listen_socket_in_epoll) )
     {
       event.events = EPOLLIN;
-      event.data.ptr = daemon;   
+      event.data.ptr = daemon;
       if (0 != epoll_ctl (daemon->epoll_fd,
                          EPOLL_CTL_ADD,
                          daemon->socket_fd,
@@ -2195,8 +2333,8 @@
        {
 #if HAVE_MESSAGES
          if (0 != (daemon->options & MHD_USE_DEBUG))
-           MHD_DLOG (daemon, 
-                     "Call to epoll_ctl failed: %s\n", 
+           MHD_DLOG (daemon,
+                     "Call to epoll_ctl failed: %s\n",
                      STRERROR (errno));
 #endif
          return MHD_NO;
@@ -2247,8 +2385,8 @@
            return MHD_YES;
 #if HAVE_MESSAGES
          if (0 != (daemon->options & MHD_USE_DEBUG))
-           MHD_DLOG (daemon, 
-                     "Call to epoll_wait failed: %s\n", 
+           MHD_DLOG (daemon,
+                     "Call to epoll_wait failed: %s\n",
                      STRERROR (errno));
 #endif
          return MHD_NO;
@@ -2270,7 +2408,7 @@
                         (pos->read_buffer_size > pos->read_buffer_offset) ) &&
                       (0 == (pos->epoll_state & 
MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
                    {
-                     EDLL_insert (daemon->eready_head, 
+                     EDLL_insert (daemon->eready_head,
                                   daemon->eready_tail,
                                   pos);
                      pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
@@ -2282,7 +2420,7 @@
                  if ( (MHD_EVENT_LOOP_INFO_WRITE == pos->event_loop_info) &&
                       (0 == (pos->epoll_state & 
MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
                    {
-                     EDLL_insert (daemon->eready_head, 
+                     EDLL_insert (daemon->eready_head,
                                   daemon->eready_tail,
                                   pos);
                      pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
@@ -2368,25 +2506,25 @@
 int
 MHD_run (struct MHD_Daemon *daemon)
 {
-  if ( (MHD_YES == daemon->shutdown) || 
+  if ( (MHD_YES == daemon->shutdown) ||
        (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ||
        (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) )
     return MHD_NO;
-  if (0 != (daemon->options & MHD_USE_POLL)) 
+  if (0 != (daemon->options & MHD_USE_POLL))
   {
-    MHD_poll (daemon, MHD_NO);    
+    MHD_poll (daemon, MHD_NO);
     MHD_cleanup_connections (daemon);
   }
-#if EPOLL_SUPPORT     
-  else if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) 
+#if EPOLL_SUPPORT
+  else if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY))
   {
     MHD_epoll (daemon, MHD_NO);
     MHD_cleanup_connections (daemon);
   }
 #endif
   else
-  { 
-    MHD_select (daemon, MHD_NO);    
+  {
+    MHD_select (daemon, MHD_NO);
     /* MHD_select does MHD_cleanup_connections already */
   }
   return MHD_YES;
@@ -2407,13 +2545,13 @@
 
   while (MHD_YES != daemon->shutdown)
     {
-      if (0 != (daemon->options & MHD_USE_POLL)) 
-       MHD_poll (daemon, MHD_YES); 
-#if EPOLL_SUPPORT     
-      else if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) 
+      if (0 != (daemon->options & MHD_USE_POLL))
+       MHD_poll (daemon, MHD_YES);
+#if EPOLL_SUPPORT
+      else if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY))
        MHD_epoll (daemon, MHD_YES);
 #endif
-      else 
+      else
        MHD_select (daemon, MHD_YES);
       MHD_cleanup_connections (daemon);
     }
@@ -2469,7 +2607,7 @@
  * #MHD_start_daemon, this function will return -1.
  *
  * @param daemon daemon to stop accepting new connections for
- * @return old listen socket on success, -1 if the daemon was 
+ * @return old listen socket on success, -1 if the daemon was
  *         already not listening anymore
  * @ingroup specialized
  */
@@ -2486,7 +2624,7 @@
        (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) )
     {
 #if HAVE_MESSAGES
-      MHD_DLOG (daemon, 
+      MHD_DLOG (daemon,
                "Using MHD_quiesce_daemon in this mode requires 
MHD_USE_PIPE_FOR_SHUTDOWN\n");
 #endif
       return -1;
@@ -2536,13 +2674,13 @@
  * @param va arguments to the format string (fprintf-style)
  */
 typedef void (*VfprintfFunctionPointerType)(void *cls,
-                                           const char *format, 
+                                           const char *format,
                                            va_list va);
 
 
 /**
  * Parse a list of options given as varargs.
- * 
+ *
  * @param daemon the daemon to initialize
  * @param servaddr where to store the server's listen address
  * @param ap the options
@@ -2556,7 +2694,7 @@
 
 /**
  * Parse a list of options given as varargs.
- * 
+ *
  * @param daemon the daemon to initialize
  * @param servaddr where to store the server's listen address
  * @param ... the options
@@ -2579,7 +2717,7 @@
 
 /**
  * Parse a list of options given as varargs.
- * 
+ *
  * @param daemon the daemon to initialize
  * @param servaddr where to store the server's listen address
  * @param ap the options
@@ -2597,7 +2735,7 @@
   int ret;
   const char *pstr;
 #endif
-  
+
   while (MHD_OPTION_END != (opt = (enum MHD_OPTION) va_arg (ap, int)))
     {
       switch (opt)
@@ -2650,7 +2788,7 @@
          else
            MHD_DLOG (daemon,
                      "MHD HTTPS option %d passed to MHD but MHD_USE_SSL not 
set\n",
-                     opt);       
+                     opt);
 #endif
           break;
         case MHD_OPTION_HTTPS_MEM_CERT:
@@ -2660,7 +2798,7 @@
          else
            MHD_DLOG (daemon,
                      "MHD HTTPS option %d passed to MHD but MHD_USE_SSL not 
set\n",
-                     opt);       
+                     opt);
 #endif
           break;
         case MHD_OPTION_HTTPS_MEM_TRUST:
@@ -2690,7 +2828,7 @@
                          "Setting priorities to `%s' failed: %s\n",
                          pstr,
                          gnutls_strerror (ret));
-#endif   
+#endif
                daemon->priority_cache = NULL;
                return MHD_NO;
              }
@@ -2707,7 +2845,7 @@
          break;
 #endif
        case MHD_OPTION_LISTEN_SOCKET:
-         daemon->socket_fd = va_arg (ap, int);   
+         daemon->socket_fd = va_arg (ap, int);
          break;
         case MHD_OPTION_EXTERNAL_LOGGER:
 #if HAVE_MESSAGES
@@ -2829,7 +2967,7 @@
 #endif
          return MHD_NO;
         }
-    }  
+    }
   return MHD_YES;
 }
 
@@ -2848,7 +2986,7 @@
 {
   int ctype = type | SOCK_CLOEXEC;
   int fd;
- 
+
   /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo
    * implementations do not set ai_socktype, e.g. RHL6.2. */
   fd = SOCKET (domain, ctype, protocol);
@@ -2883,19 +3021,19 @@
     {
 #if HAVE_MESSAGES
       if (0 != (daemon->options & MHD_USE_DEBUG))
-       MHD_DLOG (daemon, 
-                 "Call to epoll_create1 failed: %s\n", 
+       MHD_DLOG (daemon,
+                 "Call to epoll_create1 failed: %s\n",
                  STRERROR (errno));
 #endif
       return MHD_NO;
     }
   if (0 == EPOLL_CLOEXEC)
-    make_nonblocking_noninheritable (daemon, 
+    make_nonblocking_noninheritable (daemon,
                                     daemon->epoll_fd);
   if (-1 == daemon->socket_fd)
     return MHD_YES; /* non-listening daemon */
   event.events = EPOLLIN;
-  event.data.ptr = daemon;       
+  event.data.ptr = daemon;
   if (0 != epoll_ctl (daemon->epoll_fd,
                      EPOLL_CTL_ADD,
                      daemon->socket_fd,
@@ -2903,8 +3041,8 @@
     {
 #if HAVE_MESSAGES
       if (0 != (daemon->options & MHD_USE_DEBUG))
-       MHD_DLOG (daemon, 
-                 "Call to epoll_ctl failed: %s\n", 
+       MHD_DLOG (daemon,
+                 "Call to epoll_ctl failed: %s\n",
                  STRERROR (errno));
 #endif
       return MHD_NO;
@@ -2955,15 +3093,15 @@
 
 #ifndef HAVE_INET6
   if (0 != (flags & MHD_USE_IPv6))
-    return NULL;    
+    return NULL;
 #endif
 #ifndef HAVE_POLL_H
   if (0 != (flags & MHD_USE_POLL))
-    return NULL;    
+    return NULL;
 #endif
 #if ! HTTPS_SUPPORT
   if (0 != (flags & MHD_USE_SSL))
-    return NULL;    
+    return NULL;
 #endif
   if (NULL == dh)
     return NULL;
@@ -3021,7 +3159,7 @@
     )
     {
 #if HAVE_MESSAGES
-      MHD_DLOG (daemon, 
+      MHD_DLOG (daemon,
                "Failed to create control pipe: %s\n",
                STRERROR (errno));
 #endif
@@ -3034,7 +3172,7 @@
        (daemon->wpipe[0] >= FD_SETSIZE) )
     {
 #if HAVE_MESSAGES
-      MHD_DLOG (daemon, 
+      MHD_DLOG (daemon,
                "file descriptor for control pipe exceeds maximum value\n");
 #endif
       if (0 != CLOSE (daemon->wpipe[0]))
@@ -3069,9 +3207,9 @@
       return NULL;
     }
 #ifdef DAUTH_SUPPORT
-  if (daemon->nonce_nc_size > 0) 
+  if (daemon->nonce_nc_size > 0)
     {
-      if ( ( (size_t) (daemon->nonce_nc_size * sizeof (struct MHD_NonceNc))) / 
+      if ( ( (size_t) (daemon->nonce_nc_size * sizeof (struct MHD_NonceNc))) /
           sizeof(struct MHD_NonceNc) != daemon->nonce_nc_size)
        {
 #if HAVE_MESSAGES
@@ -3083,7 +3221,7 @@
            gnutls_priority_deinit (daemon->priority_cache);
 #endif
          free (daemon);
-         return NULL;    
+         return NULL;
        }
       daemon->nnc = malloc (daemon->nonce_nc_size * sizeof (struct 
MHD_NonceNc));
       if (NULL == daemon->nnc)
@@ -3101,7 +3239,7 @@
          return NULL;
        }
     }
-  
+
   if (0 != pthread_mutex_init (&daemon->nnc_lock, NULL))
     {
 #if HAVE_MESSAGES
@@ -3119,7 +3257,7 @@
 #endif
 
   /* Thread pooling currently works only with internal select thread model */
-  if ( (0 == (flags & MHD_USE_SELECT_INTERNALLY)) && 
+  if ( (0 == (flags & MHD_USE_SELECT_INTERNALLY)) &&
        (daemon->worker_pool_size > 0) )
     {
 #if HAVE_MESSAGES
@@ -3179,8 +3317,8 @@
        {
 #if HAVE_MESSAGES
          if (0 != (flags & MHD_USE_DEBUG))
-           MHD_DLOG (daemon, 
-                     "Call to socket failed: %s\n", 
+           MHD_DLOG (daemon,
+                     "Call to socket failed: %s\n",
                      STRERROR (errno));
 #endif
          goto free_and_fail;
@@ -3188,16 +3326,16 @@
       if ( (0 > SETSOCKOPT (socket_fd,
                            SOL_SOCKET,
                            SO_REUSEADDR,
-                           &on, sizeof (on))) && 
+                           &on, sizeof (on))) &&
           (0 != (flags & MHD_USE_DEBUG)) )
        {
 #if HAVE_MESSAGES
-         MHD_DLOG (daemon, 
-                   "setsockopt failed: %s\n", 
+         MHD_DLOG (daemon,
+                   "setsockopt failed: %s\n",
                    STRERROR (errno));
 #endif
        }
-      
+
       /* check for user supplied sockaddr */
 #if HAVE_INET6
       if (0 != (flags & MHD_USE_IPv6))
@@ -3237,8 +3375,8 @@
        {
 #ifdef IPPROTO_IPV6
 #ifdef IPV6_V6ONLY
-         /* Note: "IPV6_V6ONLY" is declared by Windows Vista ff., see 
"IPPROTO_IPV6 Socket Options" 
-            
(http://msdn.microsoft.com/en-us/library/ms738574%28v=VS.85%29.aspx); 
+         /* Note: "IPV6_V6ONLY" is declared by Windows Vista ff., see 
"IPPROTO_IPV6 Socket Options"
+            
(http://msdn.microsoft.com/en-us/library/ms738574%28v=VS.85%29.aspx);
             and may also be missing on older POSIX systems; good luck if you 
have any of those,
             your IPv6 socket may then also bind against IPv4 anyway... */
 #ifndef WINDOWS
@@ -3246,14 +3384,14 @@
 #else
          const char on = 1;
 #endif
-         if ( (0 > SETSOCKOPT (socket_fd, 
-                               IPPROTO_IPV6, IPV6_V6ONLY, 
+         if ( (0 > SETSOCKOPT (socket_fd,
+                               IPPROTO_IPV6, IPV6_V6ONLY,
                                &on, sizeof (on))) &&
               (0 != (flags & MHD_USE_DEBUG)) )
            {
 #if HAVE_MESSAGES
-             MHD_DLOG (daemon, 
-                       "setsockopt failed: %s\n", 
+             MHD_DLOG (daemon,
+                       "setsockopt failed: %s\n",
                        STRERROR (errno));
 #endif
            }
@@ -3265,8 +3403,8 @@
 #if HAVE_MESSAGES
          if (0 != (flags & MHD_USE_DEBUG))
            MHD_DLOG (daemon,
-                     "Failed to bind to port %u: %s\n", 
-                     (unsigned int) port, 
+                     "Failed to bind to port %u: %s\n",
+                     (unsigned int) port,
                      STRERROR (errno));
 #endif
          if (0 != CLOSE (socket_fd))
@@ -3281,12 +3419,12 @@
            {
 #if HAVE_MESSAGES
              MHD_DLOG (daemon,
-                       "Failed to make listen socket non-blocking: %s\n", 
+                       "Failed to make listen socket non-blocking: %s\n",
                        STRERROR (errno));
 #endif
              if (0 != CLOSE (socket_fd))
-               MHD_PANIC ("close failed\n");         
-             goto free_and_fail;             
+               MHD_PANIC ("close failed\n");
+             goto free_and_fail;
            }
        }
 #endif
@@ -3295,13 +3433,13 @@
 #if HAVE_MESSAGES
          if (0 != (flags & MHD_USE_DEBUG))
            MHD_DLOG (daemon,
-                     "Failed to listen for connections: %s\n", 
+                     "Failed to listen for connections: %s\n",
                      STRERROR (errno));
 #endif
-         if (0 != CLOSE (socket_fd))     
+         if (0 != CLOSE (socket_fd))
            MHD_PANIC ("close failed\n");
          goto free_and_fail;
-       }      
+       }
     }
   else
     {
@@ -3353,7 +3491,7 @@
   if ((0 != (flags & MHD_USE_SSL)) && (0 != MHD_TLS_init (daemon)))
     {
 #if HAVE_MESSAGES
-      MHD_DLOG (daemon, 
+      MHD_DLOG (daemon,
                "Failed to initialize TLS support\n");
 #endif
       if ( (-1 != socket_fd) &&
@@ -3366,14 +3504,14 @@
 #endif
   if ( ( (0 != (flags & MHD_USE_THREAD_PER_CONNECTION)) ||
         ( (0 != (flags & MHD_USE_SELECT_INTERNALLY)) &&
-          (0 == daemon->worker_pool_size)) ) && 
+          (0 == daemon->worker_pool_size)) ) &&
        (0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) &&
        (0 != (res_thread_create =
              create_thread (&daemon->pid, daemon, &MHD_select_thread, 
daemon))))
     {
 #if HAVE_MESSAGES
       MHD_DLOG (daemon,
-                "Failed to create listen thread: %s\n", 
+                "Failed to create listen thread: %s\n",
                STRERROR (res_thread_create));
 #endif
       pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
@@ -3465,12 +3603,12 @@
             }
 
           /* Spawn the worker thread */
-          if (0 != (res_thread_create = 
+          if (0 != (res_thread_create =
                    create_thread (&d->pid, daemon, &MHD_select_thread, d)))
             {
 #if HAVE_MESSAGES
               MHD_DLOG (daemon,
-                        "Failed to create pool thread: %s\n", 
+                        "Failed to create pool thread: %s\n",
                        STRERROR (res_thread_create));
 #endif
               /* Free memory for this worker; cleanup below handles
@@ -3508,9 +3646,9 @@
   return NULL;
 
  free_and_fail:
-  /* clean up basic memory state in 'daemon' and return NULL to 
+  /* clean up basic memory state in 'daemon' and return NULL to
      indicate failure */
-#if EPOLL_SUPPORT   
+#if EPOLL_SUPPORT
   if (-1 != daemon->epoll_fd)
     close (daemon->epoll_fd);
 #endif
@@ -3571,26 +3709,26 @@
   struct MHD_Connection *pos;
   void *unused;
   int rc;
-  
+
   /* first, make sure all threads are aware of shutdown; need to
      traverse DLLs in peace... */
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )    
-    MHD_PANIC ("Failed to acquire cleanup mutex\n");    
-  for (pos = daemon->connections_head; NULL != pos; pos = pos->nextX)    
-    SHUTDOWN (pos->socket_fd, 
-             (pos->read_closed == MHD_YES) ? SHUT_WR : SHUT_RDWR);    
+       (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
+    MHD_PANIC ("Failed to acquire cleanup mutex\n");
+  for (pos = daemon->connections_head; NULL != pos; pos = pos->nextX)
+    SHUTDOWN (pos->socket_fd,
+             (pos->read_closed == MHD_YES) ? SHUT_WR : SHUT_RDWR);
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )    
-    MHD_PANIC ("Failed to release cleanup mutex\n");    
+       (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
+    MHD_PANIC ("Failed to release cleanup mutex\n");
 
   /* now, collect threads from thread pool */
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
     {
       while (NULL != (pos = daemon->connections_head))
        {
-         if (0 != (rc = pthread_join (pos->pid, &unused)))         
-           MHD_PANIC ("Failed to join a thread\n");        
+         if (0 != (rc = pthread_join (pos->pid, &unused)))
+           MHD_PANIC ("Failed to join a thread\n");
          pos->thread_joined = MHD_YES;
        }
     }
@@ -3612,19 +3750,19 @@
 epoll_shutdown (struct MHD_Daemon *daemon)
 {
   struct epoll_event event;
-  
-  if (-1 == daemon->wpipe[1]) 
+
+  if (-1 == daemon->wpipe[1])
     {
       /* wpipe was required in this mode, how could this happen? */
       MHD_PANIC ("Internal error\n");
     }
   event.events = EPOLLOUT;
-  event.data.ptr = NULL;         
+  event.data.ptr = NULL;
   if (0 != epoll_ctl (daemon->epoll_fd,
                      EPOLL_CTL_ADD,
                      daemon->wpipe[1],
                      &event))
-    MHD_PANIC ("Failed to add wpipe to epoll set to signal termination\n");    
+    MHD_PANIC ("Failed to add wpipe to epoll set to signal termination\n");
 }
 #endif
 
@@ -3681,7 +3819,7 @@
   if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
        (-1 != daemon->epoll_fd) &&
        (-1 == fd) )
-    epoll_shutdown (daemon);    
+    epoll_shutdown (daemon);
 #endif
 
 #if DEBUG_CLOSE
@@ -3697,11 +3835,11 @@
       /* MHD_USE_NO_LISTEN_SOCKET disables thread pools, hence we need to 
check */
       for (i = 0; i < daemon->worker_pool_size; ++i)
        {
-         if (0 != (rc = pthread_join (daemon->worker_pool[i].pid, &unused)))   
   
-             MHD_PANIC ("Failed to join a thread\n");      
-         close_all_connections (&daemon->worker_pool[i]);        
+         if (0 != (rc = pthread_join (daemon->worker_pool[i].pid, &unused)))
+             MHD_PANIC ("Failed to join a thread\n");
+         close_all_connections (&daemon->worker_pool[i]);
          pthread_mutex_destroy 
(&daemon->worker_pool[i].cleanup_connection_mutex);
-#if EPOLL_SUPPORT   
+#if EPOLL_SUPPORT
          if ( (-1 != daemon->worker_pool[i].epoll_fd) &&
               (0 != CLOSE (daemon->worker_pool[i].epoll_fd)) )
            MHD_PANIC ("close failed\n");
@@ -3739,7 +3877,7 @@
 #if EPOLL_SUPPORT
   if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
        (-1 != daemon->epoll_fd) &&
-       (0 != CLOSE (daemon->epoll_fd)) )    
+       (0 != CLOSE (daemon->epoll_fd)) )
     MHD_PANIC ("close failed\n");
 #endif
 
@@ -3774,7 +3912,7 @@
  */
 const union MHD_DaemonInfo *
 MHD_get_daemon_info (struct MHD_Daemon *daemon,
-                    enum MHD_DaemonInfoType info_type, 
+                    enum MHD_DaemonInfoType info_type,
                     ...)
 {
   switch (info_type)
@@ -3811,7 +3949,7 @@
  * @param cls passed to @a cb
  * @ingroup logging
  */
-void 
+void
 MHD_set_panic_func (MHD_PanicCallback cb, void *cls)
 {
   mhd_panic = cb;
@@ -3850,7 +3988,7 @@
 /**
  * Initialize do setup work.
  */
-void ATTRIBUTE_CONSTRUCTOR 
+void ATTRIBUTE_CONSTRUCTOR
 MHD_init ()
 {
   mhd_panic = &mhd_panic_std;
@@ -3869,7 +4007,7 @@
 }
 
 
-void ATTRIBUTE_DESTRUCTOR 
+void ATTRIBUTE_DESTRUCTOR
 MHD_fini ()
 {
 #if HTTPS_SUPPORT




reply via email to

[Prev in Thread] Current Thread [Next in Thread]