aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r--src/microhttpd/daemon.c143
1 files changed, 87 insertions, 56 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 8f85c49a..7f366966 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -548,7 +548,7 @@ add_to_fd_set (int fd,
548 548
549 549
550/** 550/**
551 * Obtain the select sets for this daemon. 551 * Obtain the `select()` sets for this daemon.
552 * 552 *
553 * @param daemon daemon to get sets from 553 * @param daemon daemon to get sets from
554 * @param read_fd_set read set 554 * @param read_fd_set read set
@@ -556,9 +556,10 @@ add_to_fd_set (int fd,
556 * @param except_fd_set except set 556 * @param except_fd_set except set
557 * @param max_fd increased to largest FD added (if larger 557 * @param max_fd increased to largest FD added (if larger
558 * than existing value); can be NULL 558 * than existing value); can be NULL
559 * @return MHD_YES on success, MHD_NO if this 559 * @return #MHD_YES on success, #MHD_NO if this
560 * daemon was not started with the right 560 * daemon was not started with the right
561 * options for this call. 561 * options for this call.
562 * @ingroup event
562 */ 563 */
563int 564int
564MHD_get_fdset (struct MHD_Daemon *daemon, 565MHD_get_fdset (struct MHD_Daemon *daemon,
@@ -1406,12 +1407,16 @@ make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
1406 1407
1407 1408
1408/** 1409/**
1409 * Add another client connection to the set of connections 1410 * Add another client connection to the set of connections managed by
1410 * managed by MHD. This API is usually not needed (since 1411 * MHD. This API is usually not needed (since MHD will accept inbound
1411 * MHD will accept inbound connections on the server socket). 1412 * connections on the server socket). Use this API in special cases,
1412 * Use this API in special cases, for example if your HTTP 1413 * for example if your HTTP server is behind NAT and needs to connect
1413 * server is behind NAT and needs to connect out to the 1414 * out to the HTTP client, or if you are building a proxy.
1414 * HTTP client. 1415 *
1416 * If you use this API in conjunction with a internal select or a
1417 * thread pool, you must set the option
1418 * #MHD_USE_PIPE_FOR_SHUTDOWN to ensure that the freshly added
1419 * connection is immediately processed by MHD.
1415 * 1420 *
1416 * The given client socket will be managed (and closed!) by MHD after 1421 * The given client socket will be managed (and closed!) by MHD after
1417 * this call and must no longer be used directly by the application 1422 * this call and must no longer be used directly by the application
@@ -1423,11 +1428,12 @@ make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
1423 * @param client_socket socket to manage (MHD will expect 1428 * @param client_socket socket to manage (MHD will expect
1424 * to receive an HTTP request from this socket next). 1429 * to receive an HTTP request from this socket next).
1425 * @param addr IP address of the client 1430 * @param addr IP address of the client
1426 * @param addrlen number of bytes in addr 1431 * @param addrlen number of bytes in @a addr
1427 * @return MHD_YES on success, MHD_NO if this daemon could 1432 * @return #MHD_YES on success, #MHD_NO if this daemon could
1428 * not handle the connection (i.e. malloc failed, etc). 1433 * not handle the connection (i.e. `malloc()` failed, etc).
1429 * The socket will be closed in any case; 'errno' is 1434 * The socket will be closed in any case; `errno` is
1430 * set to indicate further details about the error. 1435 * set to indicate further details about the error.
1436 * @ingroup specialized
1431 */ 1437 */
1432int 1438int
1433MHD_add_connection (struct MHD_Daemon *daemon, 1439MHD_add_connection (struct MHD_Daemon *daemon,
@@ -1602,16 +1608,18 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
1602 1608
1603 1609
1604/** 1610/**
1605 * Obtain timeout value for select for this daemon 1611 * Obtain timeout value for `select()` for this daemon (only needed if
1606 * (only needed if connection timeout is used). The 1612 * connection timeout is used). The returned value is how long
1607 * returned value is how long select should at most 1613 * `select()` or `poll()` should at most block, not the timeout value set
1608 * block, not the timeout value set for connections. 1614 * for connections. This function MUST NOT be called if MHD is
1615 * running with #MHD_USE_THREAD_PER_CONNECTION.
1609 * 1616 *
1610 * @param daemon daemon to query for timeout 1617 * @param daemon daemon to query for timeout
1611 * @param timeout set to the timeout (in milliseconds) 1618 * @param timeout set to the timeout (in milliseconds)
1612 * @return MHD_YES on success, MHD_NO if timeouts are 1619 * @return #MHD_YES on success, #MHD_NO if timeouts are
1613 * not used (or no connections exist that would 1620 * not used (or no connections exist that would
1614 * necessiate the use of a timeout right now). 1621 * necessiate the use of a timeout right now).
1622 * @ingroup event
1615 */ 1623 */
1616int 1624int
1617MHD_get_timeout (struct MHD_Daemon *daemon, 1625MHD_get_timeout (struct MHD_Daemon *daemon,
@@ -1685,21 +1693,22 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
1685 1693
1686/** 1694/**
1687 * Run webserver operations. This method should be called by clients 1695 * Run webserver operations. This method should be called by clients
1688 * in combination with MHD_get_fdset if the client-controlled select 1696 * in combination with #MHD_get_fdset if the client-controlled select
1689 * method is used. 1697 * method is used.
1690 * 1698 *
1691 * You can use this function instead of "MHD_run" if you called 1699 * You can use this function instead of #MHD_run if you called
1692 * 'select' on the result from "MHD_get_fdset". File descriptors in 1700 * `select()` on the result from #MHD_get_fdset. File descriptors in
1693 * the sets that are not controlled by MHD will be ignored. Calling 1701 * the sets that are not controlled by MHD will be ignored. Calling
1694 * this function instead of "MHD_run" is more efficient as MHD will 1702 * this function instead of #MHD_run is more efficient as MHD will
1695 * not have to call 'select' again to determine which operations are 1703 * not have to call `select()` again to determine which operations are
1696 * ready. 1704 * ready.
1697 * 1705 *
1698 * @param daemon daemon to run select loop for 1706 * @param daemon daemon to run select loop for
1699 * @param read_fd_set read set 1707 * @param read_fd_set read set
1700 * @param write_fd_set write set 1708 * @param write_fd_set write set
1701 * @param except_fd_set except set (not used, can be NULL) 1709 * @param except_fd_set except set (not used, can be NULL)
1702 * @return MHD_NO on serious errors, MHD_YES on success 1710 * @return #MHD_NO on serious errors, #MHD_YES on success
1711 * @ingroup event
1703 */ 1712 */
1704int 1713int
1705MHD_run_from_select (struct MHD_Daemon *daemon, 1714MHD_run_from_select (struct MHD_Daemon *daemon,
@@ -2295,18 +2304,23 @@ MHD_epoll (struct MHD_Daemon *daemon,
2295 2304
2296 2305
2297/** 2306/**
2298 * Run webserver operations (without blocking unless 2307 * Run webserver operations (without blocking unless in client
2299 * in client callbacks). This method should be called 2308 * callbacks). This method should be called by clients in combination
2300 * by clients in combination with MHD_get_fdset 2309 * with #MHD_get_fdset if the client-controlled select method is used.
2301 * if the client-controlled select method is used.
2302 * 2310 *
2303 * This function will work for external 'poll' and 'select' mode. 2311 * This function is a convenience method, which is useful if the
2304 * However, if using external 'select' mode, you may want to 2312 * fd_sets from #MHD_get_fdset were not directly passed to `select()`;
2305 * instead use 'MHD_run_from_select', as it is more efficient. 2313 * with this function, MHD will internally do the appropriate `select()`
2314 * call itself again. While it is always safe to call #MHD_run (in
2315 * external select mode), you should call #MHD_run_from_select if
2316 * performance is important (as it saves an expensive call to
2317 * `select()`).
2306 * 2318 *
2307 * @return MHD_YES on success, MHD_NO if this 2319 * @param daemon daemon to run
2320 * @return #MHD_YES on success, #MHD_NO if this
2308 * daemon was not started with the right 2321 * daemon was not started with the right
2309 * options for this call. 2322 * options for this call.
2323 * @ingroup event
2310 */ 2324 */
2311int 2325int
2312MHD_run (struct MHD_Daemon *daemon) 2326MHD_run (struct MHD_Daemon *daemon)
@@ -2365,16 +2379,20 @@ MHD_select_thread (void *cls)
2365 2379
2366 2380
2367/** 2381/**
2368 * Start a webserver on the given port. 2382 * Start a webserver on the given port. Variadic version of
2383 * #MHD_start_daemon_va.
2369 * 2384 *
2370 * @param flags combination of MHD_FLAG values 2385 * @param flags combination of `enum MHD_FLAG` values
2371 * @param port port to bind to 2386 * @param port port to bind to
2372 * @param apc callback to call to check which clients 2387 * @param apc callback to call to check which clients
2373 * will be allowed to connect 2388 * will be allowed to connect; you can pass NULL
2389 * in which case connections from any IP will be
2390 * accepted
2374 * @param apc_cls extra argument to apc 2391 * @param apc_cls extra argument to apc
2375 * @param dh default handler for all URIs 2392 * @param dh handler called for all requests (repeatedly)
2376 * @param dh_cls extra argument to dh 2393 * @param dh_cls extra argument to @a dh
2377 * @return NULL on error, handle to daemon on success 2394 * @return NULL on error, handle to daemon on success
2395 * @ingroup event
2378 */ 2396 */
2379struct MHD_Daemon * 2397struct MHD_Daemon *
2380MHD_start_daemon (unsigned int flags, 2398MHD_start_daemon (unsigned int flags,
@@ -2399,12 +2417,18 @@ MHD_start_daemon (unsigned int flags,
2399 * connections. Note that the caller is responsible for closing the 2417 * connections. Note that the caller is responsible for closing the
2400 * returned socket; however, if MHD is run using threads (anything but 2418 * returned socket; however, if MHD is run using threads (anything but
2401 * external select mode), it must not be closed until AFTER 2419 * external select mode), it must not be closed until AFTER
2402 * "MHD_stop_daemon" has been called (as it is theoretically possible 2420 * #MHD_stop_daemon has been called (as it is theoretically possible
2403 * that an existing thread is still using it). 2421 * that an existing thread is still using it).
2404 * 2422 *
2423 * Note that some thread modes require the caller to have passed
2424 * #MHD_USE_PIPE_FOR_SHUTDOWN when using this API. If this daemon is
2425 * in one of those modes and this option was not given to
2426 * #MHD_start_daemon, this function will return -1.
2427 *
2405 * @param daemon daemon to stop accepting new connections for 2428 * @param daemon daemon to stop accepting new connections for
2406 * @return old listen socket on success, -1 if the daemon was 2429 * @return old listen socket on success, -1 if the daemon was
2407 * already not listening anymore 2430 * already not listening anymore
2431 * @ingroup specialized
2408 */ 2432 */
2409int 2433int
2410MHD_quiesce_daemon (struct MHD_Daemon *daemon) 2434MHD_quiesce_daemon (struct MHD_Daemon *daemon)
@@ -2877,20 +2901,22 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
2877#endif 2901#endif
2878 2902
2879 2903
2880
2881/** 2904/**
2882 * Start a webserver on the given port. 2905 * Start a webserver on the given port.
2883 * 2906 *
2884 * @param flags combination of MHD_FLAG values 2907 * @param flags combination of `enum MHD_FLAG` values
2885 * @param port port to bind to 2908 * @param port port to bind to (in host byte order)
2886 * @param apc callback to call to check which clients 2909 * @param apc callback to call to check which clients
2887 * will be allowed to connect 2910 * will be allowed to connect; you can pass NULL
2911 * in which case connections from any IP will be
2912 * accepted
2888 * @param apc_cls extra argument to apc 2913 * @param apc_cls extra argument to apc
2889 * @param dh default handler for all URIs 2914 * @param dh handler called for all requests (repeatedly)
2890 * @param dh_cls extra argument to dh 2915 * @param dh_cls extra argument to @a dh
2891 * @param ap list of options (type-value pairs, 2916 * @param ap list of options (type-value pairs,
2892 * terminated with MHD_OPTION_END). 2917 * terminated with #MHD_OPTION_END).
2893 * @return NULL on error, handle to daemon on success 2918 * @return NULL on error, handle to daemon on success
2919 * @ingroup event
2894 */ 2920 */
2895struct MHD_Daemon * 2921struct MHD_Daemon *
2896MHD_start_daemon_va (unsigned int flags, 2922MHD_start_daemon_va (unsigned int flags,
@@ -3587,9 +3613,10 @@ epoll_shutdown (struct MHD_Daemon *daemon)
3587 3613
3588 3614
3589/** 3615/**
3590 * Shutdown an http daemon 3616 * Shutdown an HTTP daemon.
3591 * 3617 *
3592 * @param daemon daemon to stop 3618 * @param daemon daemon to stop
3619 * @ingroup event
3593 */ 3620 */
3594void 3621void
3595MHD_stop_daemon (struct MHD_Daemon *daemon) 3622MHD_stop_daemon (struct MHD_Daemon *daemon)
@@ -3722,16 +3749,18 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3722 * (not fully implemented!). 3749 * (not fully implemented!).
3723 * 3750 *
3724 * @param daemon what daemon to get information about 3751 * @param daemon what daemon to get information about
3725 * @param infoType what information is desired? 3752 * @param info_type what information is desired?
3726 * @param ... depends on infoType 3753 * @param ... depends on @a info_type
3727 * @return NULL if this information is not available 3754 * @return NULL if this information is not available
3728 * (or if the infoType is unknown) 3755 * (or if the @a info_type is unknown)
3756 * @ingroup specialized
3729 */ 3757 */
3730const union MHD_DaemonInfo * 3758const union MHD_DaemonInfo *
3731MHD_get_daemon_info (struct MHD_Daemon *daemon, 3759MHD_get_daemon_info (struct MHD_Daemon *daemon,
3732 enum MHD_DaemonInfoType infoType, ...) 3760 enum MHD_DaemonInfoType info_type,
3761 ...)
3733{ 3762{
3734 switch (infoType) 3763 switch (info_type)
3735 { 3764 {
3736 case MHD_DAEMON_INFO_KEY_SIZE: 3765 case MHD_DAEMON_INFO_KEY_SIZE:
3737 return NULL; /* no longer supported */ 3766 return NULL; /* no longer supported */
@@ -3750,19 +3779,20 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon,
3750 3779
3751 3780
3752/** 3781/**
3753 * Sets the global error handler to a different implementation. "cb" 3782 * Sets the global error handler to a different implementation. @a cb
3754 * will only be called in the case of typically fatal, serious 3783 * will only be called in the case of typically fatal, serious
3755 * internal consistency issues. These issues should only arise in the 3784 * internal consistency issues. These issues should only arise in the
3756 * case of serious memory corruption or similar problems with the 3785 * case of serious memory corruption or similar problems with the
3757 * architecture. While "cb" is allowed to return and MHD will then 3786 * architecture. While @a cb is allowed to return and MHD will then
3758 * try to continue, this is never safe. 3787 * try to continue, this is never safe.
3759 * 3788 *
3760 * The default implementation that is used if no panic function is set 3789 * The default implementation that is used if no panic function is set
3761 * simply prints an error message and calls "abort". Alternative 3790 * simply prints an error message and calls `abort()`. Alternative
3762 * implementations might call "exit" or other similar functions. 3791 * implementations might call `exit()` or other similar functions.
3763 * 3792 *
3764 * @param cb new error handler 3793 * @param cb new error handler
3765 * @param cls passed to error handler 3794 * @param cls passed to @a cb
3795 * @ingroup logging
3766 */ 3796 */
3767void 3797void
3768MHD_set_panic_func (MHD_PanicCallback cb, void *cls) 3798MHD_set_panic_func (MHD_PanicCallback cb, void *cls)
@@ -3775,7 +3805,8 @@ MHD_set_panic_func (MHD_PanicCallback cb, void *cls)
3775/** 3805/**
3776 * Obtain the version of this library 3806 * Obtain the version of this library
3777 * 3807 *
3778 * @return static version string, e.g. "0.4.1" 3808 * @return static version string, e.g. "0.9.9"
3809 * @ingroup specialized
3779 */ 3810 */
3780const char * 3811const char *
3781MHD_get_version (void) 3812MHD_get_version (void)