aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-24 08:41:04 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-24 08:41:04 +0000
commit8e6b1e789978929efd84aedf44943514dfe1a7e3 (patch)
treebc58d70919f93fdc43ab94d7da17c874aafe367c /doc
parenta79c58be3d55fb21d9d47bd6f7a3b5367ad70569 (diff)
downloadlibmicrohttpd-8e6b1e789978929efd84aedf44943514dfe1a7e3.tar.gz
libmicrohttpd-8e6b1e789978929efd84aedf44943514dfe1a7e3.zip
experimental code to support flow control for connections via MHD_suspend_connection and MHD_resume_connection
Diffstat (limited to 'doc')
-rw-r--r--doc/libmicrohttpd.texi239
1 files changed, 151 insertions, 88 deletions
diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi
index 3ff8c2ac..e18c3014 100644
--- a/doc/libmicrohttpd.texi
+++ b/doc/libmicrohttpd.texi
@@ -63,6 +63,7 @@ Free Documentation License".
63* microhttpd-inspect:: Implementing external @code{select}. 63* microhttpd-inspect:: Implementing external @code{select}.
64* microhttpd-requests:: Handling requests. 64* microhttpd-requests:: Handling requests.
65* microhttpd-responses:: Building responses to requests. 65* microhttpd-responses:: Building responses to requests.
66* microhttpd-flow:: Flow control.
66* microhttpd-dauth:: Utilizing Authentication. 67* microhttpd-dauth:: Utilizing Authentication.
67* microhttpd-post:: Adding a @code{POST} processor. 68* microhttpd-post:: Adding a @code{POST} processor.
68* microhttpd-info:: Obtaining and modifying status information. 69* microhttpd-info:: Obtaining and modifying status information.
@@ -132,7 +133,7 @@ used per connection to avoid resource exhaustion.
132 133
133@section Scope 134@section Scope
134 135
135MHD is currently used in a wide range of implementations. 136MHD is currently used in a wide range of implementations.
136Examples based on reports we've received from developers include: 137Examples based on reports we've received from developers include:
137@itemize 138@itemize
138@item Embedded HTTP server on a cortex M3 (128 KB code space) 139@item Embedded HTTP server on a cortex M3 (128 KB code space)
@@ -148,7 +149,7 @@ Examples based on reports we've received from developers include:
148@cindex select 149@cindex select
149 150
150MHD supports four basic thread modes and up to three event loop 151MHD supports four basic thread modes and up to three event loop
151styes. 152styes.
152 153
153The four basic thread modes are external (MHD creates no threads, 154The four basic thread modes are external (MHD creates no threads,
154event loop is fully managed by the application), internal (MHD creates 155event loop is fully managed by the application), internal (MHD creates
@@ -203,7 +204,7 @@ combinations.
203@item @b{external} @tab yes @tab no @tab yes 204@item @b{external} @tab yes @tab no @tab yes
204@item @b{internal} @tab yes @tab yes @tab yes 205@item @b{internal} @tab yes @tab yes @tab yes
205@item @b{thread pool} @tab yes @tab yes @tab yes 206@item @b{thread pool} @tab yes @tab yes @tab yes
206@item @b{thread-per-connection} @tab yes @tab yes @tab no 207@item @b{thread-per-connection} @tab yes @tab yes @tab no
207@end multitable 208@end multitable
208@caption{Supported combinations of event styles and thread modes.} 209@caption{Supported combinations of event styles and thread modes.}
209@end float 210@end float
@@ -239,7 +240,7 @@ full list of options run ``./configure --help''):
239@item ``--disable-curl'' 240@item ``--disable-curl''
240disable running testcases using libcurl 241disable running testcases using libcurl
241 242
242@item ``--disable-largefile'' 243@item ``--disable-largefile''
243disable support for 64-bit files 244disable support for 64-bit files
244 245
245@item ``--disable-messages'' 246@item ``--disable-messages''
@@ -285,7 +286,7 @@ conditional operations. For possible suggestions consult
285Once you have ensured that you manually (!) included the right headers 286Once you have ensured that you manually (!) included the right headers
286for your platform before "microhttpd.h", you should also add a line 287for your platform before "microhttpd.h", you should also add a line
287with @code{#define MHD_PLATFORM_H} which will prevent the 288with @code{#define MHD_PLATFORM_H} which will prevent the
288"microhttpd.h" header from trying (and, depending on your platform, 289"microhttpd.h" header from trying (and, depending on your platform,
289failing) to include the right headers. 290failing) to include the right headers.
290 291
291If you do not define MHD_PLATFORM_H, the "microhttpd.h" header will 292If you do not define MHD_PLATFORM_H, the "microhttpd.h" header will
@@ -297,12 +298,12 @@ causing problems when porting to other platforms).
297MHD does not install a signal handler for SIGPIPE. On platforms 298MHD does not install a signal handler for SIGPIPE. On platforms
298where this is possible (such as GNU/Linux), it disables SIGPIPE for 299where this is possible (such as GNU/Linux), it disables SIGPIPE for
299its I/O operations (by passing MSG_NOSIGNAL). On other platforms, 300its I/O operations (by passing MSG_NOSIGNAL). On other platforms,
300SIGPIPE signals may be generated from network operations by 301SIGPIPE signals may be generated from network operations by
301MHD and will cause the process to die unless the developer 302MHD and will cause the process to die unless the developer
302explicitly installs a signal handler for SIGPIPE. 303explicitly installs a signal handler for SIGPIPE.
303 304
304Hence portable code using MHD must install a SIGPIPE handler or 305Hence portable code using MHD must install a SIGPIPE handler or
305explicitly block the SIGPIPE signal. MHD does not do so in order 306explicitly block the SIGPIPE signal. MHD does not do so in order
306to avoid messing with other parts of the application that may 307to avoid messing with other parts of the application that may
307need to handle SIGPIPE in a particular way. You can make your application handle SIGPIPE by calling the following function in @code{main}: 308need to handle SIGPIPE in a particular way. You can make your application handle SIGPIPE by calling the following function in @code{main}:
308 309
@@ -422,8 +423,8 @@ No options selected.
422Run in debug mode. If this flag is used, the library should print error 423Run in debug mode. If this flag is used, the library should print error
423messages and warnings to stderr. Note that for this 424messages and warnings to stderr. Note that for this
424run-time option to have any effect, MHD needs to be 425run-time option to have any effect, MHD needs to be
425compiled with messages enabled. This is done by default except you ran 426compiled with messages enabled. This is done by default except you ran
426configure with the @code{--disable-messages} flag set. 427configure with the @code{--disable-messages} flag set.
427 428
428@item MHD_USE_SSL 429@item MHD_USE_SSL
429@cindex TLS 430@cindex TLS
@@ -519,7 +520,7 @@ ability to signal termination via the listen socket). In these modes,
519@code{MHD_quiesce_daemon} will fail if this option was not set. Also, 520@code{MHD_quiesce_daemon} will fail if this option was not set. Also,
520use of this option is automatic (as in, you do not even have to 521use of this option is automatic (as in, you do not even have to
521specify it), if @code{MHD_USE_NO_LISTEN_SOCKET} is specified. In 522specify it), if @code{MHD_USE_NO_LISTEN_SOCKET} is specified. In
522"external" select mode, this option is always simply ignored. 523"external" select mode, this option is always simply ignored.
523 524
524@end table 525@end table
525@end deftp 526@end deftp
@@ -533,7 +534,7 @@ MHD options. Passed in the varargs portion of
533@item MHD_OPTION_END 534@item MHD_OPTION_END
534No more options / last option. This is used to terminate the VARARGs 535No more options / last option. This is used to terminate the VARARGs
535list. 536list.
536 537
537@item MHD_OPTION_CONNECTION_MEMORY_LIMIT 538@item MHD_OPTION_CONNECTION_MEMORY_LIMIT
538@cindex memory, limiting memory utilization 539@cindex memory, limiting memory utilization
539Maximum memory size per connection (followed by a @code{size_t}). The 540Maximum memory size per connection (followed by a @code{size_t}). The
@@ -558,19 +559,19 @@ Maximum number of concurrent connections to accept (followed by an
558@code{unsigned int}). The default is @code{FD_SETSIZE - 4} (the 559@code{unsigned int}). The default is @code{FD_SETSIZE - 4} (the
559maximum number of file descriptors supported by @code{select} minus 560maximum number of file descriptors supported by @code{select} minus
560four for @code{stdin}, @code{stdout}, @code{stderr} and the server 561four for @code{stdin}, @code{stdout}, @code{stderr} and the server
561socket). In other words, the default is as large as possible. 562socket). In other words, the default is as large as possible.
562 563
563Note that if you set a low connection limit, you can easily get into 564Note that if you set a low connection limit, you can easily get into
564trouble with browsers doing request pipelining. For example, if your 565trouble with browsers doing request pipelining. For example, if your
565connection limit is ``1'', a browser may open a first connection to 566connection limit is ``1'', a browser may open a first connection to
566access your ``index.html'' file, keep it open but use a second 567access your ``index.html'' file, keep it open but use a second
567connection to retrieve CSS files, images and the like. In fact, modern 568connection to retrieve CSS files, images and the like. In fact, modern
568browsers are typically by default configured for up to 15 parallel 569browsers are typically by default configured for up to 15 parallel
569connections to a single server. If this happens, MHD will refuse to 570connections to a single server. If this happens, MHD will refuse to
570even accept the second connection until the first connection is 571even accept the second connection until the first connection is
571closed --- which does not happen until timeout. As a result, the 572closed --- which does not happen until timeout. As a result, the
572browser will fail to render the page and seem to hang. If you expect 573browser will fail to render the page and seem to hang. If you expect
573your server to operate close to the connection limit, you should 574your server to operate close to the connection limit, you should
574first consider using a lower timeout value and also possibly add 575first consider using a lower timeout value and also possibly add
575a ``Connection: close'' header to your response to ensure that 576a ``Connection: close'' header to your response to ensure that
576request pipelining is not used and connections are closed immediately 577request pipelining is not used and connections are closed immediately
@@ -613,8 +614,8 @@ from the same IP address.
613@item MHD_OPTION_SOCK_ADDR 614@item MHD_OPTION_SOCK_ADDR
614@cindex bind, restricting bind 615@cindex bind, restricting bind
615Bind daemon to the supplied socket address. This option should be followed by a 616Bind daemon to the supplied socket address. This option should be followed by a
616@code{struct sockaddr *}. If @code{MHD_USE_IPv6} is specified, 617@code{struct sockaddr *}. If @code{MHD_USE_IPv6} is specified,
617the @code{struct sockaddr*} should point to a @code{struct sockaddr_in6}, 618the @code{struct sockaddr*} should point to a @code{struct sockaddr_in6},
618otherwise to a @code{struct sockaddr_in}. If this option is not specified, 619otherwise to a @code{struct sockaddr_in}. If this option is not specified,
619the daemon will listen to incoming connections from anywhere. If you use this 620the daemon will listen to incoming connections from anywhere. If you use this
620option, the 'port' argument from @code{MHD_start_daemon} is ignored and the port 621option, the 'port' argument from @code{MHD_start_daemon} is ignored and the port
@@ -655,7 +656,7 @@ Memory pointer to the private key to be used by the
655HTTPS daemon. This option should be followed by an 656HTTPS daemon. This option should be followed by an
656"const char*" argument. 657"const char*" argument.
657This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_CERT'. 658This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_CERT'.
658 659
659@item MHD_OPTION_HTTPS_MEM_CERT 660@item MHD_OPTION_HTTPS_MEM_CERT
660@cindex SSL 661@cindex SSL
661@cindex TLS 662@cindex TLS
@@ -663,7 +664,7 @@ Memory pointer to the certificate to be used by the
663HTTPS daemon. This option should be followed by an 664HTTPS daemon. This option should be followed by an
664"const char*" argument. 665"const char*" argument.
665This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_KEY'. 666This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_KEY'.
666 667
667@item MHD_OPTION_HTTPS_MEM_TRUST 668@item MHD_OPTION_HTTPS_MEM_TRUST
668@cindex SSL 669@cindex SSL
669@cindex TLS 670@cindex TLS
@@ -677,14 +678,14 @@ of the certificate if needed.
677Note that most browsers will only present a client certificate 678Note that most browsers will only present a client certificate
678only if they have one matching the specified CA, not sending 679only if they have one matching the specified CA, not sending
679any certificate otherwise. 680any certificate otherwise.
680 681
681@item MHD_OPTION_HTTPS_CRED_TYPE 682@item MHD_OPTION_HTTPS_CRED_TYPE
682@cindex SSL 683@cindex SSL
683@cindex TLS 684@cindex TLS
684Daemon credentials type. Either certificate or anonymous, 685Daemon credentials type. Either certificate or anonymous,
685this option should be followed by one of the values listed in 686this option should be followed by one of the values listed in
686"enum gnutls_credentials_type_t". 687"enum gnutls_credentials_type_t".
687 688
688@item MHD_OPTION_HTTPS_PRIORITIES 689@item MHD_OPTION_HTTPS_PRIORITIES
689@cindex SSL 690@cindex SSL
690@cindex TLS 691@cindex TLS
@@ -706,7 +707,7 @@ type "size_t" which specifies the size of the buffer pointed to by the
706second argument in bytes. Note that the application must ensure that 707second argument in bytes. Note that the application must ensure that
707the buffer of the second argument remains allocated and unmodified 708the buffer of the second argument remains allocated and unmodified
708while the daemon is running. For security, you SHOULD provide a fresh 709while the daemon is running. For security, you SHOULD provide a fresh
709random nonce when using MHD with Digest Authentication. 710random nonce when using MHD with Digest Authentication.
710 711
711@item MHD_OPTION_NONCE_NC_SIZE 712@item MHD_OPTION_NONCE_NC_SIZE
712@cindex digest auth 713@cindex digest auth
@@ -737,7 +738,7 @@ Listen socket to use. Pass a listen socket for MHD to use
737(systemd-style). If this option is used, MHD will not open its own 738(systemd-style). If this option is used, MHD will not open its own
738listen socket(s). The argument passed must be of type "int" and refer 739listen socket(s). The argument passed must be of type "int" and refer
739to an existing socket that has been bound to a port and is listening. 740to an existing socket that has been bound to a port and is listening.
740 741
741@item MHD_OPTION_EXTERNAL_LOGGER 742@item MHD_OPTION_EXTERNAL_LOGGER
742@cindex logging 743@cindex logging
743Use the given function for logging error messages. 744Use the given function for logging error messages.
@@ -746,10 +747,10 @@ first must be a pointer to a function
746of type 'void fun(void * arg, const char * fmt, va_list ap)' 747of type 'void fun(void * arg, const char * fmt, va_list ap)'
747and the second a pointer of type 'void*' which will 748and the second a pointer of type 'void*' which will
748be passed as the "arg" argument to "fun". 749be passed as the "arg" argument to "fun".
749 750
750Note that MHD will not generate any log messages without 751Note that MHD will not generate any log messages without
751the MHD_USE_DEBUG flag set and if MHD was compiled 752the MHD_USE_DEBUG flag set and if MHD was compiled
752with the "--disable-messages" flag. 753with the "--disable-messages" flag.
753 754
754@item MHD_OPTION_THREAD_POOL_SIZE 755@item MHD_OPTION_THREAD_POOL_SIZE
755@cindex performance 756@cindex performance
@@ -806,7 +807,7 @@ updated. Note that the unescape function must not lengthen @code{s}
806@code{cls} will be set to the second argument following 807@code{cls} will be set to the second argument following
807MHD_OPTION_UNESCAPE_CALLBACK. 808MHD_OPTION_UNESCAPE_CALLBACK.
808 809
809 810
810@item MHD_OPTION_THREAD_STACK_SIZE 811@item MHD_OPTION_THREAD_STACK_SIZE
811@cindex stack 812@cindex stack
812@cindex thread 813@cindex thread
@@ -814,7 +815,7 @@ MHD_OPTION_UNESCAPE_CALLBACK.
814@cindex embedded systems 815@cindex embedded systems
815Maximum stack size for threads created by MHD. This option must be 816Maximum stack size for threads created by MHD. This option must be
816followed by a @code{size_t}). Not specifying this option or using 817followed by a @code{size_t}). Not specifying this option or using
817a value of zero means using the system default (which is likely to 818a value of zero means using the system default (which is likely to
818differ based on your platform). 819differ based on your platform).
819 820
820@end table 821@end table
@@ -823,7 +824,7 @@ differ based on your platform).
823 824
824@deftp {C Struct} MHD_OptionItem 825@deftp {C Struct} MHD_OptionItem
825Entry in an MHD_OPTION_ARRAY. See the @code{MHD_OPTION_ARRAY} option 826Entry in an MHD_OPTION_ARRAY. See the @code{MHD_OPTION_ARRAY} option
826argument for its use. 827argument for its use.
827 828
828The @code{option} member is used to specify which option is specified 829The @code{option} member is used to specify which option is specified
829in the array. The other members specify the respective argument. 830in the array. The other members specify the respective argument.
@@ -895,7 +896,7 @@ We had to close the session since MHD was being shut down.
895 896
896@deftp {Enumeration} MHD_ResponseMemoryMode 897@deftp {Enumeration} MHD_ResponseMemoryMode
897The @code{MHD_ResponeMemoryMode} specifies how MHD should treat 898The @code{MHD_ResponeMemoryMode} specifies how MHD should treat
898the memory buffer given for the response in 899the memory buffer given for the response in
899@code{MHD_create_response_from_buffer}. 900@code{MHD_create_response_from_buffer}.
900 901
901@table @code 902@table @code
@@ -903,12 +904,12 @@ the memory buffer given for the response in
903Buffer is a persistent (static/global) buffer that won't change 904Buffer is a persistent (static/global) buffer that won't change
904for at least the lifetime of the response, MHD should just use 905for at least the lifetime of the response, MHD should just use
905it, not free it, not copy it, just keep an alias to it. 906it, not free it, not copy it, just keep an alias to it.
906 907
907@item MHD_RESPMEM_MUST_FREE 908@item MHD_RESPMEM_MUST_FREE
908Buffer is heap-allocated with @code{malloc} (or equivalent) and 909Buffer is heap-allocated with @code{malloc} (or equivalent) and
909should be freed by MHD after processing the response has 910should be freed by MHD after processing the response has
910concluded (response reference counter reaches zero). 911concluded (response reference counter reaches zero).
911 912
912@item MHD_RESPMEM_MUST_COPY 913@item MHD_RESPMEM_MUST_COPY
913Buffer is in transient memory, but not on the heap (for example, 914Buffer is in transient memory, but not on the heap (for example,
914on the stack or non-malloc allocated) and only valid during the 915on the stack or non-malloc allocated) and only valid during the
@@ -1094,13 +1095,9 @@ Callback used by MHD in order to obtain content. The callback has to
1094copy at most @var{max} bytes of content into @var{buf}. The total 1095copy at most @var{max} bytes of content into @var{buf}. The total
1095number of bytes that has been placed into @var{buf} should be returned. 1096number of bytes that has been placed into @var{buf} should be returned.
1096 1097
1097Note that returning zero will cause MHD to try again, either 1098Note that returning zero will cause MHD to try again.
1098``immediately'' if in multi-threaded mode (in which case the callback 1099Thus, returning zero should only be used in conjunction
1099may want to do blocking operations to avoid busy waiting) or in the 1100with @code{MHD_suspend_connection()} to avoid busy waiting.
1100next round if @code{MHD_run} is used. Returning zero for a daemon
1101that runs in internal @code{select}-mode is an error (since it
1102would result in busy waiting) and cause the program to be aborted
1103(@code{abort()}).
1104 1101
1105While usually the callback simply returns the number of bytes written 1102While usually the callback simply returns the number of bytes written
1106into @var{buf}, there are two special return value: 1103into @var{buf}, there are two special return value:
@@ -1108,7 +1105,7 @@ into @var{buf}, there are two special return value:
1108@code{MHD_CONTENT_READER_END_OF_STREAM} (-1) should be returned 1105@code{MHD_CONTENT_READER_END_OF_STREAM} (-1) should be returned
1109for the regular end of transmission (with chunked encoding, MHD will then 1106for the regular end of transmission (with chunked encoding, MHD will then
1110terminate the chunk and send any HTTP footers that might be 1107terminate the chunk and send any HTTP footers that might be
1111present; without chunked encoding and given an unknown 1108present; without chunked encoding and given an unknown
1112response size, MHD will simply close the connection; note 1109response size, MHD will simply close the connection; note
1113that while returning @code{MHD_CONTENT_READER_END_OF_STREAM} is not technically 1110that while returning @code{MHD_CONTENT_READER_END_OF_STREAM} is not technically
1114legal if a response size was specified, MHD accepts this 1111legal if a response size was specified, MHD accepts this
@@ -1121,7 +1118,7 @@ given or if chunked encoding is in use, this will indicate
1121an error to the client. Note, however, that if the client 1118an error to the client. Note, however, that if the client
1122does not know a response size and chunked encoding is not in 1119does not know a response size and chunked encoding is not in
1123use, then clients will not be able to tell the difference between 1120use, then clients will not be able to tell the difference between
1124@code{MHD_CONTENT_READER_END_WITH_ERROR} and 1121@code{MHD_CONTENT_READER_END_WITH_ERROR} and
1125@code{MHD_CONTENT_READER_END_OF_STREAM}. 1122@code{MHD_CONTENT_READER_END_OF_STREAM}.
1126This is not a limitation of MHD but rather of the HTTP protocol. 1123This is not a limitation of MHD but rather of the HTTP protocol.
1127 1124
@@ -1198,7 +1195,7 @@ iteration.
1198Set a handler for fatal errors. 1195Set a handler for fatal errors.
1199 1196
1200@table @var 1197@table @var
1201@item cb 1198@item cb
1202function to call if MHD encounters a fatal internal error. If no handler was set explicitly, MHD will call @code{abort}. 1199function to call if MHD encounters a fatal internal error. If no handler was set explicitly, MHD will call @code{abort}.
1203 1200
1204@item cls 1201@item cls
@@ -1252,7 +1249,7 @@ is still using it).
1252 1249
1253This function is useful in the special case that a listen socket 1250This function is useful in the special case that a listen socket
1254is to be migrated to another process (i.e. a newer version of the 1251is to be migrated to another process (i.e. a newer version of the
1255HTTP server) while existing connections should continue to be 1252HTTP server) while existing connections should continue to be
1256processed until they are finished. 1253processed until they are finished.
1257 1254
1258Return @code{-1} on error (daemon not listening), the handle to the 1255Return @code{-1} on error (daemon not listening), the handle to the
@@ -1278,7 +1275,7 @@ However, if using external @code{select} mode, you may want to
1278instead use @code{MHD_run_from_select}, as it is more efficient. 1275instead use @code{MHD_run_from_select}, as it is more efficient.
1279 1276
1280@table @var 1277@table @var
1281@item daemon 1278@item daemon
1282daemon to process connections of 1279daemon to process connections of
1283@end table 1280@end table
1284 1281
@@ -1291,7 +1288,7 @@ started with the right options for this call.
1291Run webserver operations given sets of ready socket handles. 1288Run webserver operations given sets of ready socket handles.
1292@cindex select 1289@cindex select
1293 1290
1294This method should be called by clients in combination with 1291This method should be called by clients in combination with
1295@code{MHD_get_fdset} if the client-controlled (external) 1292@code{MHD_get_fdset} if the client-controlled (external)
1296select method is used. 1293select method is used.
1297 1294
@@ -1303,7 +1300,7 @@ not have to call @code{select} again to determine which operations are
1303ready. 1300ready.
1304 1301
1305@table @var 1302@table @var
1306@item daemon 1303@item daemon
1307daemon to process connections of 1304daemon to process connections of
1308@item read_fd_set 1305@item read_fd_set
1309set of descriptors that must be ready for reading without blocking 1306set of descriptors that must be ready for reading without blocking
@@ -1321,11 +1318,11 @@ errors.
1321 1318
1322 1319
1323@deftypefun void MHD_add_connection (struct MHD_Daemon *daemon, int client_socket, const struct sockaddr *addr, socklen_t addrlen) 1320@deftypefun void MHD_add_connection (struct MHD_Daemon *daemon, int client_socket, const struct sockaddr *addr, socklen_t addrlen)
1324Add another client connection to the set of connections 1321Add another client connection to the set of connections
1325managed by MHD. This API is usually not needed (since 1322managed by MHD. This API is usually not needed (since
1326MHD will accept inbound connections on the server socket). 1323MHD will accept inbound connections on the server socket).
1327Use this API in special cases, for example if your HTTP 1324Use this API in special cases, for example if your HTTP
1328server is behind NAT and needs to connect out to the 1325server is behind NAT and needs to connect out to the
1329HTTP client, or if you are building a proxy. 1326HTTP client, or if you are building a proxy.
1330 1327
1331If you use this API in conjunction with a internal select or a thread 1328If you use this API in conjunction with a internal select or a thread
@@ -1338,17 +1335,17 @@ this call and must no longer be used directly by the application
1338afterwards. 1335afterwards.
1339 1336
1340@table @var 1337@table @var
1341@item daemon 1338@item daemon
1342daemon that manages the connection 1339daemon that manages the connection
1343@item client_socket 1340@item client_socket
1344socket to manage (MHD will expect to receive an HTTP request from this socket next). 1341socket to manage (MHD will expect to receive an HTTP request from this socket next).
1345@item addr 1342@item addr
1346IP address of the client 1343IP address of the client
1347@item addrlen 1344@item addrlen
1348number of bytes in addr 1345number of bytes in addr
1349@end table 1346@end table
1350 1347
1351This function will return @code{MHD_YES} on success, 1348This function will return @code{MHD_YES} on success,
1352@code{MHD_NO} if this daemon could 1349@code{MHD_NO} if this daemon could
1353not handle the connection (i.e. malloc failed, etc). 1350not handle the connection (i.e. malloc failed, etc).
1354The socket will be closed in any case; 'errno' is set 1351The socket will be closed in any case; 'errno' is set
@@ -1387,7 +1384,7 @@ connection timeout is used). The returned value is how long
1387@code{select} should at most block, not the timeout value set for 1384@code{select} should at most block, not the timeout value set for
1388connections. This function must not be called if the 1385connections. This function must not be called if the
1389@code{MHD_USE_THREAD_PER_CONNECTION} mode is in use (since then it 1386@code{MHD_USE_THREAD_PER_CONNECTION} mode is in use (since then it
1390is not meaningful to ask for a timeout, after all, there is 1387is not meaningful to ask for a timeout, after all, there is
1391concurrenct activity). The function must also not be called by 1388concurrenct activity). The function must also not be called by
1392user-code if @code{MHD_USE_INTERNAL_SELECT} is in use. In the latter 1389user-code if @code{MHD_USE_INTERNAL_SELECT} is in use. In the latter
1393case, the behavior is undefined. 1390case, the behavior is undefined.
@@ -1411,7 +1408,7 @@ right now).
1411 1408
1412 1409
1413@deftypefun int MHD_get_connection_values (struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls) 1410@deftypefun int MHD_get_connection_values (struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls)
1414Get all the headers matching @var{kind} from the request. 1411Get all the headers matching @var{kind} from the request.
1415 1412
1416The @var{iterator} callback is invoked once for each header, with 1413The @var{iterator} callback is invoked once for each header, with
1417@var{iterator_cls} as first argument. After version 0.9.19, the 1414@var{iterator_cls} as first argument. After version 0.9.19, the
@@ -1439,9 +1436,9 @@ would contain the string ``key''.
1439 1436
1440@deftypefun int MHD_set_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char * key, const char * value) 1437@deftypefun int MHD_set_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char * key, const char * value)
1441This function can be used to append an entry to 1438This function can be used to append an entry to
1442the list of HTTP headers of a connection (so that the 1439the list of HTTP headers of a connection (so that the
1443@code{MHD_get_connection_values function} will return 1440@code{MHD_get_connection_values function} will return
1444them -- and the MHD PostProcessor will also 1441them -- and the MHD PostProcessor will also
1445see them). This maybe required in certain 1442see them). This maybe required in certain
1446situations (see Mantis #1399) where (broken) 1443situations (see Mantis #1399) where (broken)
1447HTTP implementations fail to supply values needed 1444HTTP implementations fail to supply values needed
@@ -1457,11 +1454,11 @@ are NOT freed until the connection is closed.
1457(The easiest way to do this is by passing only 1454(The easiest way to do this is by passing only
1458arguments to permanently allocated strings.). 1455arguments to permanently allocated strings.).
1459 1456
1460@var{connection} is the connection for which 1457@var{connection} is the connection for which
1461the entry for @var{key} of the given @var{kind} 1458the entry for @var{key} of the given @var{kind}
1462should be set to the given @var{value}. 1459should be set to the given @var{value}.
1463 1460
1464The function returns @code{MHD_NO} if the operation 1461The function returns @code{MHD_NO} if the operation
1465could not be performed due to insufficient memory 1462could not be performed due to insufficient memory
1466and @code{MHD_YES} on success. 1463and @code{MHD_YES} on success.
1467@end deftypefun 1464@end deftypefun
@@ -1636,8 +1633,8 @@ size of the file)
1636 1633
1637@item fd 1634@item fd
1638file descriptor referring to a file on disk with the data; will be 1635file descriptor referring to a file on disk with the data; will be
1639closed when response is destroyed; note that 'fd' must be an actual 1636closed when response is destroyed; note that 'fd' must be an actual
1640file descriptor (not a pipe or socket) since MHD might use 'sendfile' 1637file descriptor (not a pipe or socket) since MHD might use 'sendfile'
1641or 'seek' on it. The descriptor should be in blocking-IO mode. 1638or 'seek' on it. The descriptor should be in blocking-IO mode.
1642@end table 1639@end table
1643 1640
@@ -1678,8 +1675,8 @@ file starting at offset).
1678 1675
1679@item fd 1676@item fd
1680file descriptor referring to a file on disk with the data; will be 1677file descriptor referring to a file on disk with the data; will be
1681closed when response is destroyed; note that 'fd' must be an actual 1678closed when response is destroyed; note that 'fd' must be an actual
1682file descriptor (not a pipe or socket) since MHD might use 'sendfile' 1679file descriptor (not a pipe or socket) since MHD might use 'sendfile'
1683or 'seek' on it. The descriptor should be in blocking-IO mode. 1680or 'seek' on it. The descriptor should be in blocking-IO mode.
1684 1681
1685@item offset 1682@item offset
@@ -1701,8 +1698,8 @@ size of the data portion of the response;
1701@item buffer 1698@item buffer
1702the data itself; 1699the data itself;
1703 1700
1704@item mode 1701@item mode
1705memory management options for buffer; use 1702memory management options for buffer; use
1706MHD_RESPMEM_PERSISTENT if the buffer is static/global memory, 1703MHD_RESPMEM_PERSISTENT if the buffer is static/global memory,
1707use MHD_RESPMEM_MUST_FREE if the buffer is heap-allocated and 1704use MHD_RESPMEM_MUST_FREE if the buffer is heap-allocated and
1708should be freed by MHD and MHD_RESPMEM_MUST_COPY if the 1705should be freed by MHD and MHD_RESPMEM_MUST_COPY if the
@@ -1779,7 +1776,7 @@ memory allocation error).
1779@deftypefun int MHD_add_response_footer (struct MHD_Response *response, const char *footer, const char *content) 1776@deftypefun int MHD_add_response_footer (struct MHD_Response *response, const char *footer, const char *content)
1780Add a footer line to the response. The strings referenced by 1777Add a footer line to the response. The strings referenced by
1781@var{footer} and @var{content} must be zero-terminated and they are 1778@var{footer} and @var{content} must be zero-terminated and they are
1782duplicated into memory blocks embedded in @var{response}. 1779duplicated into memory blocks embedded in @var{response}.
1783 1780
1784Notice that the strings must not hold newlines, carriage returns or tab 1781Notice that the strings must not hold newlines, carriage returns or tab
1785chars. You can add response footers at any time before signalling the 1782chars. You can add response footers at any time before signalling the
@@ -1833,6 +1830,72 @@ We should not modify the value, unless we know what we are doing.
1833@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1830@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1834 1831
1835@c ------------------------------------------------------------ 1832@c ------------------------------------------------------------
1833@node microhttpd-flow
1834@chapter Flow control.
1835
1836@noindent
1837Sometimes it may be possible that clients upload data faster
1838than an application can process it, or that an application
1839needs an extended period of time to generate a response.
1840If @code{MHD_USE_THREAD_PER_CONNECTION} is used, applications
1841can simply deal with this by performing their logic within the
1842thread and thus effectively blocking connection processing
1843by MHD. In all other modes, blocking logic must not be
1844placed within the callbacks invoked by MHD as this would also
1845block processing of other requests, as a single thread may be
1846responsible for tens of thousands of connections.
1847
1848Instead, applications using thread modes other than
1849@code{MHD_USE_THREAD_PER_CONNECTION} should use the
1850following functions to perform flow control.
1851
1852@deftypefun int MHD_suspend_connection (struct MHD_Connection *connection)
1853Suspend handling of network data for a given connection. This can
1854be used to dequeue a connection from MHD's event loop (external
1855select, internal select or thread pool; not applicable to
1856thread-per-connection!) for a while.
1857
1858If you use this API in conjunction with a internal select or a
1859thread pool, you must set the option @code{MHD_USE_PIPE_FOR_SHUTDOWN} to
1860ensure that a resumed connection is immediately processed by MHD.
1861
1862Suspended connections continue to count against the total number of
1863connections allowed (per daemon, as well as per IP, if such limits
1864are set). Suspended connections will NOT time out; timeouts will
1865restart when the connection handling is resumed. While a
1866connection is suspended, MHD will not detect disconnects by the
1867client.
1868
1869The only safe time to suspend a connection is from the
1870@code{MHD_AccessHandlerCallback}.
1871
1872Finally, it is an API violation to call @code{MHD_stop_daemon} while
1873having suspended connections (this will at least create memory and
1874socket leaks or lead to undefined behavior). You must explicitly
1875resume all connections before stopping the daemon.
1876
1877@table @var
1878@item connection
1879the connection to suspend
1880@end table
1881@end deftypefun
1882
1883@deftypefun int MHD_resume_connection (struct MHD_Connection *connection)
1884Resume handling of network data for suspended connection. It is safe
1885to resume a suspended connection at any time. Calling this function
1886on a connection that was not previously suspended will result in
1887undefined behavior.
1888
1889@table @var
1890@item connection
1891the connection to resume
1892@end table
1893@end deftypefun
1894
1895
1896@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1897
1898@c ------------------------------------------------------------
1836@node microhttpd-dauth 1899@node microhttpd-dauth
1837@chapter Utilizing Authentication 1900@chapter Utilizing Authentication
1838 1901
@@ -1960,41 +2023,41 @@ ahc_echo (void *cls,
1960 int ret; 2023 int ret;
1961 2024
1962 username = MHD_digest_auth_get_username(connection); 2025 username = MHD_digest_auth_get_username(connection);
1963 if (username == NULL) 2026 if (username == NULL)
1964 @{ 2027 @{
1965 response = MHD_create_response_from_buffer(strlen (DENIED), 2028 response = MHD_create_response_from_buffer(strlen (DENIED),
1966 DENIED, 2029 DENIED,
1967 MHD_RESPMEM_PERSISTENT); 2030 MHD_RESPMEM_PERSISTENT);
1968 ret = MHD_queue_auth_fail_response(connection, realm, 2031 ret = MHD_queue_auth_fail_response(connection, realm,
1969 OPAQUE, 2032 OPAQUE,
1970 response, 2033 response,
1971 MHD_NO); 2034 MHD_NO);
1972 MHD_destroy_response(response); 2035 MHD_destroy_response(response);
1973 return ret; 2036 return ret;
1974 @} 2037 @}
1975 ret = MHD_digest_auth_check(connection, realm, 2038 ret = MHD_digest_auth_check(connection, realm,
1976 username, 2039 username,
1977 password, 2040 password,
1978 300); 2041 300);
1979 free(username); 2042 free(username);
1980 if ( (ret == MHD_INVALID_NONCE) || 2043 if ( (ret == MHD_INVALID_NONCE) ||
1981 (ret == MHD_NO) ) 2044 (ret == MHD_NO) )
1982 @{ 2045 @{
1983 response = MHD_create_response_from_buffer(strlen (DENIED), 2046 response = MHD_create_response_from_buffer(strlen (DENIED),
1984 DENIED, 2047 DENIED,
1985 MHD_RESPMEM_PERSISTENT); 2048 MHD_RESPMEM_PERSISTENT);
1986 if (NULL == response) 2049 if (NULL == response)
1987 return MHD_NO; 2050 return MHD_NO;
1988 ret = MHD_queue_auth_fail_response(connection, realm, 2051 ret = MHD_queue_auth_fail_response(connection, realm,
1989 OPAQUE, 2052 OPAQUE,
1990 response, 2053 response,
1991 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO); 2054 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);
1992 MHD_destroy_response(response); 2055 MHD_destroy_response(response);
1993 return ret; 2056 return ret;
1994 @} 2057 @}
1995 response = MHD_create_response_from_buffer (strlen(PAGE), PAGE, 2058 response = MHD_create_response_from_buffer (strlen(PAGE), PAGE,
1996 MHD_RESPMEM_PERSISTENT); 2059 MHD_RESPMEM_PERSISTENT);
1997 ret = MHD_queue_response(connection, MHD_HTTP_OK, response); 2060 ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
1998 MHD_destroy_response(response); 2061 MHD_destroy_response(response);
1999 return ret; 2062 return ret;
2000@} 2063@}
@@ -2026,7 +2089,7 @@ its @code{*@var{con_cls}} argument is set to @code{NULL}. When @code{POST}
2026data comes in the upload buffer it is @strong{mandatory} to use the 2089data comes in the upload buffer it is @strong{mandatory} to use the
2027@var{con_cls} to store a reference to per-connection data. The fact 2090@var{con_cls} to store a reference to per-connection data. The fact
2028that the pointer was initially @code{NULL} can be used to detect that 2091that the pointer was initially @code{NULL} can be used to detect that
2029this is a new request. 2092this is a new request.
2030 2093
2031One method to detect that a new connection was established is 2094One method to detect that a new connection was established is
2032to set @code{*con_cls} to an unused integer: 2095to set @code{*con_cls} to an unused integer:
@@ -2043,7 +2106,7 @@ access_handler (void *cls,
2043 static int old_connection_marker; 2106 static int old_connection_marker;
2044 int new_connection = (NULL == *con_cls); 2107 int new_connection = (NULL == *con_cls);
2045 2108
2046 if (new_connection) 2109 if (new_connection)
2047 @{ 2110 @{
2048 /* new connection with POST */ 2111 /* new connection with POST */
2049 *con_cls = &old_connection_marker; 2112 *con_cls = &old_connection_marker;
@@ -2070,13 +2133,13 @@ access_handler (void *cls,
2070@{ 2133@{
2071 struct MHD_PostProcessor * pp = *con_cls; 2134 struct MHD_PostProcessor * pp = *con_cls;
2072 2135
2073 if (pp == NULL) 2136 if (pp == NULL)
2074 @{ 2137 @{
2075 pp = MHD_create_post_processor(connection, ...); 2138 pp = MHD_create_post_processor(connection, ...);
2076 *con_cls = pp; 2139 *con_cls = pp;
2077 return MHD_YES; 2140 return MHD_YES;
2078 @} 2141 @}
2079 if (*upload_data_size) 2142 if (*upload_data_size)
2080 @{ 2143 @{
2081 MHD_post_process(pp, upload_data, *upload_data_size); 2144 MHD_post_process(pp, upload_data, *upload_data_size);
2082 *upload_data_size = 0; 2145 *upload_data_size = 0;
@@ -2161,7 +2224,7 @@ is no special call to the iterator to indicate the end of the post processing
2161stream. After destroying the PostProcessor, the programmer should 2224stream. After destroying the PostProcessor, the programmer should
2162perform any necessary work to complete the processing of the iterator. 2225perform any necessary work to complete the processing of the iterator.
2163 2226
2164Return @code{MHD_YES} if processing completed nicely, @code{MHD_NO} 2227Return @code{MHD_YES} if processing completed nicely, @code{MHD_NO}
2165if there were spurious characters or formatting problems with 2228if there were spurious characters or formatting problems with
2166the post request. It is common to ignore the return value 2229the post request. It is common to ignore the return value
2167of this function. 2230of this function.
@@ -2285,7 +2348,7 @@ connection is desired.
2285@table @code 2348@table @code
2286 2349
2287@item MHD_CONNECTION_INFO_CIPHER_ALGO 2350@item MHD_CONNECTION_INFO_CIPHER_ALGO
2288What cipher algorithm is being used (HTTPS connections only). 2351What cipher algorithm is being used (HTTPS connections only).
2289Takes no extra arguments. 2352Takes no extra arguments.
2290@code{NULL} is returned for non-HTTPS connections. 2353@code{NULL} is returned for non-HTTPS connections.
2291 2354
@@ -2295,7 +2358,7 @@ Takes no extra arguments. Allows finding out the TLS/SSL protocol used
2295@code{NULL} is returned for non-HTTPS connections. 2358@code{NULL} is returned for non-HTTPS connections.
2296 2359
2297@item MHD_CONNECTION_INFO_CLIENT_ADDRESS 2360@item MHD_CONNECTION_INFO_CLIENT_ADDRESS
2298Returns information about the address of the client. Returns 2361Returns information about the address of the client. Returns
2299essentially a @code{struct sockaddr **} (since the API returns 2362essentially a @code{struct sockaddr **} (since the API returns
2300a @code{union MHD_ConnectionInfo *} and that union contains 2363a @code{union MHD_ConnectionInfo *} and that union contains
2301a @code{struct sockaddr *}). 2364a @code{struct sockaddr *}).
@@ -2303,7 +2366,7 @@ a @code{struct sockaddr *}).
2303@item MHD_CONNECTION_INFO_GNUTLS_SESSION, 2366@item MHD_CONNECTION_INFO_GNUTLS_SESSION,
2304Takes no extra arguments. Allows access to the underlying GNUtls session, 2367Takes no extra arguments. Allows access to the underlying GNUtls session,
2305including access to the underlying GNUtls client certificate 2368including access to the underlying GNUtls client certificate
2306(HTTPS connections only). Takes no extra arguments. 2369(HTTPS connections only). Takes no extra arguments.
2307@code{NULL} is returned for non-HTTPS connections. 2370@code{NULL} is returned for non-HTTPS connections.
2308 2371
2309@item MHD_CONNECTION_INFO_GNUTLS_CLIENT_CERT, 2372@item MHD_CONNECTION_INFO_GNUTLS_CLIENT_CERT,
@@ -2367,7 +2430,7 @@ connection should be changed.
2367@item MHD_CONNECTION_OPTION_TIMEOUT 2430@item MHD_CONNECTION_OPTION_TIMEOUT
2368Set a custom timeout for the given connection. Specified 2431Set a custom timeout for the given connection. Specified
2369as the number of seconds, given as an @code{unsigned int}. Use 2432as the number of seconds, given as an @code{unsigned int}. Use
2370zero for no timeout. 2433zero for no timeout.
2371 2434
2372@end table 2435@end table
2373@end deftp 2436@end deftp