GNU libmicrohttpd 1.0.2
Loading...
Searching...
No Matches
event-loop control

Macros

#define MHD_get_fdset(daemon, read_fd_set, write_fd_set, except_fd_set, max_fd)
 
#define MHD_run_from_select(d, r, w, e)
 

Functions

_MHD_EXTERN struct MHD_DaemonMHD_start_daemon_va (unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls, va_list ap)
 
_MHD_EXTERN struct MHD_DaemonMHD_start_daemon (unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls,...)
 
_MHD_EXTERN void MHD_stop_daemon (struct MHD_Daemon *daemon)
 
_MHD_EXTERN enum MHD_Result MHD_get_fdset (struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd)
 
_MHD_EXTERN enum MHD_Result MHD_get_fdset2 (struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, unsigned int fd_setsize)
 
_MHD_EXTERN enum MHD_Result MHD_get_timeout (struct MHD_Daemon *daemon, MHD_UNSIGNED_LONG_LONG *timeout)
 
_MHD_EXTERN enum MHD_Result MHD_get_timeout64 (struct MHD_Daemon *daemon, uint64_t *timeout)
 
_MHD_EXTERN int64_t MHD_get_timeout64s (struct MHD_Daemon *daemon)
 
_MHD_EXTERN int MHD_get_timeout_i (struct MHD_Daemon *daemon)
 
_MHD_EXTERN enum MHD_Result MHD_run (struct MHD_Daemon *daemon)
 
_MHD_EXTERN enum MHD_Result MHD_run_wait (struct MHD_Daemon *daemon, int32_t millisec)
 
_MHD_EXTERN enum MHD_Result 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)
 
_MHD_EXTERN enum MHD_Result MHD_run_from_select2 (struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set, unsigned int fd_setsize)
 
static enum MHD_Result internal_get_fdset2 (struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, int fd_setsize)
 
static enum MHD_Result internal_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, int fd_setsize)
 

Detailed Description

MHD API to start and stop the HTTP server and manage the event loop.

Macro Definition Documentation

◆ MHD_get_fdset

#define MHD_get_fdset ( daemon,
read_fd_set,
write_fd_set,
except_fd_set,
max_fd )
Value:
MHD_get_fdset2 ((daemon),(read_fd_set),(write_fd_set),(except_fd_set), \
(max_fd),FD_SETSIZE)
_MHD_EXTERN enum MHD_Result MHD_get_fdset2(struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, unsigned int fd_setsize)
Definition daemon.c:1188

Obtain the select() sets for this daemon. Daemon's FDs will be added to fd_sets. To get only daemon FDs in fd_sets, call FD_ZERO for each fd_set before calling this function. Size of fd_set is determined by current value of FD_SETSIZE.

This function should be called only when MHD is configured to use "external" sockets polling with 'select()' or with 'epoll'. In the latter case, it will only add the single 'epoll' file descriptor used by MHD to the sets. It's necessary to use MHD_get_timeout() to get maximum timeout value for select(). Usage of select() with indefinite timeout (or timeout larger than returned by MHD_get_timeout()) will violate MHD API and may results in pending unprocessed data.

This function must be called only for daemon started without MHD_USE_INTERNAL_POLLING_THREAD flag.

Parameters
daemondaemon to get sets from
read_fd_setread set
write_fd_setwrite set
except_fd_setexcept set
max_fdincreased to largest FD added (if larger than existing value); can be NULL
Returns
MHD_YES on success, MHD_NO if this daemon was not started with the right options for this call or any FD didn't fit fd_set.

Definition at line 3162 of file microhttpd.h.

◆ MHD_run_from_select

#define MHD_run_from_select ( d,
r,
w,
e )
Value:
MHD_run_from_select2 ((d),(r),(w),(e),(unsigned int) (FD_SETSIZE))
_MHD_EXTERN enum MHD_Result MHD_run_from_select2(struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set, unsigned int fd_setsize)
Definition daemon.c:4650

Run webserver operations. This method should be called by clients in combination with MHD_get_fdset and MHD_get_timeout() if the client-controlled select method is used. This macro automatically substitutes current FD_SETSIZE value. It is important on platforms where FD_SETSIZE can be overridden.

You can use this function instead of MHD_run if you called 'select()' on the result from MHD_get_fdset2(). File descriptors in the sets that are not controlled by MHD will be ignored. Calling this function instead of MHD_run() is more efficient as MHD will not have to call 'select()' again to determine which operations are ready.

If MHD_get_timeout() returned MHD_YES, than this function must be called right after 'select()' returns regardless of detected activity on the daemon's FDs.

This function cannot be used with daemon started with MHD_USE_INTERNAL_POLLING_THREAD flag.

Parameters
daemonthe daemon to run select loop for
read_fd_setthe read set
write_fd_setthe write set
except_fd_setthe except set
fd_setsizethe value of FD_SETSIZE
Returns
MHD_NO on serious errors, MHD_YES on success
See also
MHD_get_fdset2(), MHD_OPTION_APP_FD_SETSIZE

Definition at line 3516 of file microhttpd.h.

Function Documentation

◆ internal_get_fdset2()

static enum MHD_Result internal_get_fdset2 ( struct MHD_Daemon * daemon,
fd_set * read_fd_set,
fd_set * write_fd_set,
fd_set * except_fd_set,
MHD_socket * max_fd,
int fd_setsize )
static

Internal version of MHD_get_fdset2().

Parameters
daemondaemon to get sets from
read_fd_setread set
write_fd_setwrite set
except_fd_setexcept set
max_fdincreased to largest FD added (if larger than existing value); can be NULL
fd_setsizevalue of FD_SETSIZE
Returns
MHD_YES on success, MHD_NO if any FD didn't fit fd_set.

Definition at line 987 of file daemon.c.

References _, MHD_Daemon::at_limit, MHD_Daemon::connection_limit, MHD_Daemon::connections, MHD_Daemon::connections_tail, MHD_Connection::daemon, MHD_Connection::event_loop_info, MHD_Daemon::itc, MHD_Daemon::listen_fd, MHD_add_to_fd_set_(), MHD_EVENT_LOOP_INFO_CLEANUP, MHD_EVENT_LOOP_INFO_PROCESS, MHD_EVENT_LOOP_INFO_PROCESS_READ, MHD_EVENT_LOOP_INFO_READ, MHD_EVENT_LOOP_INFO_WRITE, MHD_INVALID_SOCKET, MHD_NO, MHD_YES, NULL, MHD_Connection::prev, MHD_Daemon::shutdown, MHD_Connection::socket_fd, and MHD_Daemon::was_quiesced.

Referenced by MHD_get_fdset2(), and MHD_select().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_run_from_select()

static enum MHD_Result internal_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,
int fd_setsize )
static

◆ MHD_get_fdset()

_MHD_EXTERN enum MHD_Result MHD_get_fdset ( struct MHD_Daemon * daemon,
fd_set * read_fd_set,
fd_set * write_fd_set,
fd_set * except_fd_set,
MHD_socket * max_fd )

Obtain the select() sets for this daemon. Daemon's FDs will be added to fd_sets. To get only daemon FDs in fd_sets, call FD_ZERO for each fd_set before calling this function. FD_SETSIZE is assumed to be platform's default.

This function should be called only when MHD is configured to use "external" sockets polling with 'select()' or with 'epoll'. In the latter case, it will only add the single 'epoll' file descriptor used by MHD to the sets. It's necessary to use MHD_get_timeout() to get maximum timeout value for select(). Usage of select() with indefinite timeout (or timeout larger than returned by MHD_get_timeout()) will violate MHD API and may results in pending unprocessed data.

This function must be called only for daemon started without MHD_USE_INTERNAL_POLLING_THREAD flag.

Parameters
daemondaemon to get sets from
read_fd_setread set
write_fd_setwrite set
except_fd_setexcept set
max_fdincreased to largest FD added (if larger than existing value); can be NULL
Returns
MHD_YES on success, MHD_NO if this daemon was not started with the right options for this call or any FD didn't fit fd_set.

Definition at line 688 of file daemon.c.

References _MHD_SYS_DEFAULT_FD_SETSIZE, and MHD_get_fdset2().

Here is the call graph for this function:

◆ MHD_get_fdset2()

_MHD_EXTERN enum MHD_Result MHD_get_fdset2 ( struct MHD_Daemon * daemon,
fd_set * read_fd_set,
fd_set * write_fd_set,
fd_set * except_fd_set,
MHD_socket * max_fd,
unsigned int fd_setsize )

Obtain the select() sets for this daemon. Daemon's FDs will be added to fd_sets. To get only daemon FDs in fd_sets, call FD_ZERO for each fd_set before calling this function.

Passing custom FD_SETSIZE as fd_setsize allow usage of larger/smaller than platform's default fd_sets.

This function should be called only when MHD is configured to use "external" sockets polling with 'select()' or with 'epoll'. In the latter case, it will only add the single 'epoll' file descriptor used by MHD to the sets. It's necessary to use MHD_get_timeout() to get maximum timeout value for select(). Usage of select() with indefinite timeout (or timeout larger than returned by MHD_get_timeout()) will violate MHD API and may results in pending unprocessed data.

This function must be called only for daemon started without MHD_USE_INTERNAL_POLLING_THREAD flag.

Parameters
daemondaemon to get sets from
read_fd_setread set
write_fd_setwrite set
except_fd_setexcept set
max_fdincreased to largest FD added (if larger than existing value); can be NULL
fd_setsizevalue of FD_SETSIZE
Returns
MHD_YES on success, MHD_NO if this daemon was not started with the right options for this call or any FD didn't fit fd_set.

Definition at line 1188 of file daemon.c.

References _, INT_MAX, internal_get_fdset2(), MHD_add_to_fd_set_(), MHD_D_IS_USING_EPOLL_, MHD_D_IS_USING_POLL_, MHD_D_IS_USING_THREADS_, MHD_NO, MHD_YES, NULL, and MHD_Daemon::shutdown.

Referenced by MHD_get_fdset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_get_timeout()

_MHD_EXTERN enum MHD_Result MHD_get_timeout ( struct MHD_Daemon * daemon,
MHD_UNSIGNED_LONG_LONG * timeout )

Obtain timeout value for polling function for this daemon.

This function set value to the amount of milliseconds for which polling function (select(), poll() or epoll) should at most block, not the timeout value set for connections.

Any "external" sockets polling function must be called with the timeout value provided by this function. Smaller timeout values can be used for polling function if it is required for any reason, but using larger timeout value or no timeout (indefinite timeout) when this function return MHD_YES will break MHD processing logic and result in "hung" connections with data pending in network buffers and other problems.

It is important to always use this function (or MHD_get_timeout64(), MHD_get_timeout64s(), MHD_get_timeout_i() functions) when "external" polling is used. If this function returns MHD_YES then MHD_run() (or MHD_run_from_select()) must be called right after return from polling function, regardless of the states of MHD FDs.

In practice, if MHD_YES is returned then MHD_run() (or MHD_run_from_select()) must be called not later than timeout millisecond even if no activity is detected on sockets by sockets polling function.

Parameters
daemondaemon to query for timeout
[out]timeoutset to the timeout (in milliseconds)
Returns
MHD_YES on success, MHD_NO if timeouts are not used and no data processing is pending.

Obtain timeout value for polling function for this daemon.

This function set value to the amount of milliseconds for which polling function (select(), poll() or epoll) should at most block, not the timeout value set for connections.

Any "external" sockets polling function must be called with the timeout value provided by this function. Smaller timeout values can be used for polling function if it is required for any reason, but using larger timeout value or no timeout (indefinite timeout) when this function return MHD_YES will break MHD processing logic and result in "hung" connections with data pending in network buffers and other problems.

It is important to always use this function (or MHD_get_timeout64(), MHD_get_timeout64s(), MHD_get_timeout_i() functions) when "external" polling is used. If this function returns MHD_YES then MHD_run() (or MHD_run_from_select()) must be called right after return from polling function, regardless of the states of MHD FDs.

In practice, if MHD_YES is returned then MHD_run() (or MHD_run_from_select()) must be called not later than timeout millisecond even if no activity is detected on sockets by sockets polling function.

Remarks
To be called only from thread that process daemon's select()/poll()/etc.
Parameters
daemondaemon to query for timeout
[out]timeoutset to the timeout (in milliseconds)
Returns
MHD_YES on success, MHD_NO if timeouts are not used and no data processing is pending.

Definition at line 4173 of file daemon.c.

References MHD_Connection::daemon, MHD_get_timeout64(), MHD_NO, MHD_UNSIGNED_LONG_LONG, MHD_YES, and ULLONG_MAX.

Here is the call graph for this function:

◆ MHD_get_timeout64()

_MHD_EXTERN enum MHD_Result MHD_get_timeout64 ( struct MHD_Daemon * daemon,
uint64_t * timeout64 )

Obtain timeout value for external polling function for this daemon.

This function set value to the amount of milliseconds for which polling function (select(), poll() or epoll) should at most block, not the timeout value set for connections.

Any "external" sockets polling function must be called with the timeout value provided by this function. Smaller timeout values can be used for polling function if it is required for any reason, but using larger timeout value or no timeout (indefinite timeout) when this function return MHD_YES will break MHD processing logic and result in "hung" connections with data pending in network buffers and other problems.

It is important to always use this function (or MHD_get_timeout(), MHD_get_timeout64s(), MHD_get_timeout_i() functions) when "external" polling is used. If this function returns MHD_YES then MHD_run() (or MHD_run_from_select()) must be called right after return from polling function, regardless of the states of MHD FDs.

In practice, if MHD_YES is returned then MHD_run() (or MHD_run_from_select()) must be called not later than timeout millisecond even if no activity is detected on sockets by sockets polling function.

Parameters
daemondaemon to query for timeout
[out]timeout64the pointer to the variable to be set to the timeout (in milliseconds)
Returns
MHD_YES if timeout value has been set, MHD_NO if timeouts are not used and no data processing is pending.
Note
Available since MHD_VERSION 0x00097701

Obtain timeout value for external polling function for this daemon.

This function set value to the amount of milliseconds for which polling function (select(), poll() or epoll) should at most block, not the timeout value set for connections.

Any "external" sockets polling function must be called with the timeout value provided by this function. Smaller timeout values can be used for polling function if it is required for any reason, but using larger timeout value or no timeout (indefinite timeout) when this function return MHD_YES will break MHD processing logic and result in "hung" connections with data pending in network buffers and other problems.

It is important to always use this function (or MHD_get_timeout(), MHD_get_timeout64s(), MHD_get_timeout_i() functions) when "external" polling is used. If this function returns MHD_YES then MHD_run() (or MHD_run_from_select()) must be called right after return from polling function, regardless of the states of MHD FDs.

In practice, if MHD_YES is returned then MHD_run() (or MHD_run_from_select()) must be called not later than timeout millisecond even if no activity is detected on sockets by sockets polling function.

Remarks
To be called only from thread that process daemon's select()/poll()/etc.
Parameters
daemondaemon to query for timeout
[out]timeout64the pointer to the variable to be set to the timeout (in milliseconds)
Returns
MHD_YES if timeout value has been set, MHD_NO if timeouts are not used and no data processing is pending.
Note
Available since MHD_VERSION 0x00097701

< the connection with earliest timeout

Definition at line 4227 of file daemon.c.

References _, MHD_Daemon::cleanup_head, MHD_Connection::connection_timeout_ms, MHD_Connection::daemon, MHD_Daemon::data_already_pending, MHD_Daemon::have_new, MHD_Connection::last_activity, MHD_Daemon::manual_timeout_tail, mhd_assert, MHD_D_IS_USING_EPOLL_, MHD_D_IS_USING_THREAD_PER_CONN_, MHD_D_IS_USING_THREADS_, MHD_NO, MHD_thread_handle_ID_is_current_thread_, MHD_YES, MHD_Daemon::normal_timeout_tail, NULL, MHD_Connection::prevX, MHD_Daemon::resuming, and MHD_Daemon::shutdown.

Referenced by MHD_get_timeout(), and MHD_select().

Here is the caller graph for this function:

◆ MHD_get_timeout64s()

_MHD_EXTERN int64_t MHD_get_timeout64s ( struct MHD_Daemon * daemon)

Obtain timeout value for external polling function for this daemon.

This function set value to the amount of milliseconds for which polling function (select(), poll() or epoll) should at most block, not the timeout value set for connections.

Any "external" sockets polling function must be called with the timeout value provided by this function (if returned value is non-negative). Smaller timeout values can be used for polling function if it is required for any reason, but using larger timeout value or no timeout (indefinite timeout) when this function returns non-negative value will break MHD processing logic and result in "hung" connections with data pending in network buffers and other problems.

It is important to always use this function (or MHD_get_timeout(), MHD_get_timeout64(), MHD_get_timeout_i() functions) when "external" polling is used. If this function returns non-negative value then MHD_run() (or MHD_run_from_select()) must be called right after return from polling function, regardless of the states of MHD FDs.

In practice, if zero or positive value is returned then MHD_run() (or MHD_run_from_select()) must be called not later than returned amount of millisecond even if no activity is detected on sockets by sockets polling function.

Parameters
daemonthe daemon to query for timeout
Returns
-1 if connections' timeouts are not set and no data processing is pending, so external polling function may wait for sockets activity for indefinite amount of time, otherwise returned value is the the maximum amount of millisecond that external polling function must wait for the activity of FDs.
Note
Available since MHD_VERSION 0x00097701

References _MHD_EXTERN.

◆ MHD_get_timeout_i()

_MHD_EXTERN int MHD_get_timeout_i ( struct MHD_Daemon * daemon)

Obtain timeout value for external polling function for this daemon.

This function set value to the amount of milliseconds for which polling function (select(), poll() or epoll) should at most block, not the timeout value set for connections.

Any "external" sockets polling function must be called with the timeout value provided by this function (if returned value is non-negative). Smaller timeout values can be used for polling function if it is required for any reason, but using larger timeout value or no timeout (indefinite timeout) when this function returns non-negative value will break MHD processing logic and result in "hung" connections with data pending in network buffers and other problems.

It is important to always use this function (or MHD_get_timeout(), MHD_get_timeout64(), MHD_get_timeout64s() functions) when "external" polling is used. If this function returns non-negative value then MHD_run() (or MHD_run_from_select()) must be called right after return from polling function, regardless of the states of MHD FDs.

In practice, if zero or positive value is returned then MHD_run() (or MHD_run_from_select()) must be called not later than returned amount of millisecond even if no activity is detected on sockets by sockets polling function.

Parameters
daemonthe daemon to query for timeout
Returns
-1 if connections' timeouts are not set and no data processing is pending, so external polling function may wait for sockets activity for indefinite amount of time, otherwise returned value is the the maximum amount of millisecond (capped at INT_MAX) that external polling function must wait for the activity of FDs.
Note
Available since MHD_VERSION 0x00097701

References _MHD_EXTERN.

◆ MHD_run()

_MHD_EXTERN enum MHD_Result MHD_run ( struct MHD_Daemon * daemon)

Run webserver operations (without blocking unless in client callbacks).

This method should be called by clients in combination with MHD_get_fdset() (or MHD_get_daemon_info() with MHD_DAEMON_INFO_EPOLL_FD if epoll is used) and MHD_get_timeout() if the client-controlled connection polling method is used (i.e. daemon was started without MHD_USE_INTERNAL_POLLING_THREAD flag).

This function is a convenience method, which is useful if the fd_sets from MHD_get_fdset were not directly passed to select(); with this function, MHD will internally do the appropriate select() call itself again. While it is acceptable to call MHD_run (if MHD_USE_INTERNAL_POLLING_THREAD is not set) at any moment, you should call MHD_run_from_select() if performance is important (as it saves an expensive call to select()).

If MHD_get_timeout() returned MHD_YES, than this function must be called right after polling function returns regardless of detected activity on the daemon's FDs.

Parameters
daemondaemon to run
Returns
MHD_YES on success, MHD_NO if this daemon was not started with the right options for this call.

Definition at line 5824 of file daemon.c.

References MHD_D_IS_USING_THREADS_, MHD_NO, MHD_run_wait(), MHD_YES, and MHD_Daemon::shutdown.

Here is the call graph for this function:

◆ MHD_run_from_select()

_MHD_EXTERN enum MHD_Result 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 )

Run webserver operations. This method should be called by clients in combination with MHD_get_fdset and MHD_get_timeout() if the client-controlled select method is used.

You can use this function instead of MHD_run if you called select() on the result from MHD_get_fdset. File descriptors in the sets that are not controlled by MHD will be ignored. Calling this function instead of MHD_run is more efficient as MHD will not have to call select() again to determine which operations are ready.

If MHD_get_timeout() returned MHD_YES, than this function must be called right after select() returns regardless of detected activity on the daemon's FDs.

This function cannot be used with daemon started with MHD_USE_INTERNAL_POLLING_THREAD flag.

Parameters
daemondaemon to run select loop for
read_fd_setread set
write_fd_setwrite set
except_fd_setexcept set
Returns
MHD_NO on serious errors, MHD_YES on success

Definition at line 4764 of file daemon.c.

References _MHD_SYS_DEFAULT_FD_SETSIZE, MHD_Connection::daemon, and MHD_run_from_select2().

Here is the call graph for this function:

◆ MHD_run_from_select2()

_MHD_EXTERN enum MHD_Result MHD_run_from_select2 ( struct MHD_Daemon * daemon,
const fd_set * read_fd_set,
const fd_set * write_fd_set,
const fd_set * except_fd_set,
unsigned int fd_setsize )

Run webserver operations. This method should be called by clients in combination with MHD_get_fdset and MHD_get_timeout() if the client-controlled select method is used. This function specifies FD_SETSIZE used when provided fd_sets were created. It is important on platforms where FD_SETSIZE can be overridden.

You can use this function instead of MHD_run if you called 'select()' on the result from MHD_get_fdset2(). File descriptors in the sets that are not controlled by MHD will be ignored. Calling this function instead of MHD_run() is more efficient as MHD will not have to call 'select()' again to determine which operations are ready.

If MHD_get_timeout() returned MHD_YES, than this function must be called right after 'select()' returns regardless of detected activity on the daemon's FDs.

This function cannot be used with daemon started with MHD_USE_INTERNAL_POLLING_THREAD flag.

Parameters
daemonthe daemon to run select loop for
read_fd_setthe read set
write_fd_setthe write set
except_fd_setthe except set
fd_setsizethe value of FD_SETSIZE
Returns
MHD_NO on serious errors, MHD_YES on success
See also
MHD_get_fdset2(), MHD_OPTION_APP_FD_SETSIZE

Definition at line 4650 of file daemon.c.

References _, MHD_Connection::daemon, INT_MAX, internal_run_from_select(), MHD_cleanup_connections(), MHD_D_IS_USING_EPOLL_, MHD_D_IS_USING_POLL_, MHD_D_IS_USING_THREADS_, MHD_NO, MHD_TEST_ALLOW_SUSPEND_RESUME, NULL, MHD_Daemon::options, and resume_suspended_connections().

Referenced by MHD_run_from_select().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_run_wait()

_MHD_EXTERN enum MHD_Result MHD_run_wait ( struct MHD_Daemon * daemon,
int32_t millisec )

Run websever operation with possible blocking.

This function does the following: waits for any network event not more than specified number of milliseconds, processes all incoming and outgoing data, processes new connections, processes any timed-out connection, and does other things required to run webserver. Once all connections are processed, function returns.

This function is useful for quick and simple (lazy) webserver implementation if application needs to run a single thread only and does not have any other network activity.

This function calls MHD_get_timeout() internally and use returned value as maximum wait time if it less than value of millisec parameter.

It is expected that the "external" socket polling function is not used in conjunction with this function unless the millisec is set to zero.

Parameters
daemonthe daemon to run
millisecthe maximum time in milliseconds to wait for network and other events. Note: there is no guarantee that function blocks for the specified amount of time. The real processing time can be shorter (if some data or connection timeout comes earlier) or longer (if data processing requires more time, especially in user callbacks). If set to '0' then function does not block and processes only already available data (if any). If set to '-1' then function waits for events indefinitely (blocks until next network activity or connection timeout).
Returns
MHD_YES on success, MHD_NO if this daemon was not started with the right options for this call or some serious unrecoverable error occurs.
Note
Available since MHD_VERSION 0x00097206

Run webserver operation with possible blocking.

This function does the following: waits for any network event not more than specified number of milliseconds, processes all incoming and outgoing data, processes new connections, processes any timed-out connection, and does other things required to run webserver. Once all connections are processed, function returns.

This function is useful for quick and simple (lazy) webserver implementation if application needs to run a single thread only and does not have any other network activity.

This function calls MHD_get_timeout() internally and use returned value as maximum wait time if it less than value of millisec parameter.

It is expected that the "external" socket polling function is not used in conjunction with this function unless the millisec is set to zero.

Parameters
daemonthe daemon to run
millisecthe maximum time in milliseconds to wait for network and other events. Note: there is no guarantee that function blocks for the specified amount of time. The real processing time can be shorter (if some data or connection timeout comes earlier) or longer (if data processing requires more time, especially in user callbacks). If set to '0' then function does not block and processes only already available data (if any). If set to '-1' then function waits for events indefinitely (blocks until next network activity or connection timeout).
Returns
MHD_YES on success, MHD_NO if this daemon was not started with the right options for this call or some serious unrecoverable error occurs.
Note
Available since MHD_VERSION 0x00097206

Definition at line 5874 of file daemon.c.

References _, mhd_assert, MHD_cleanup_connections(), MHD_D_IS_USING_EPOLL_, MHD_D_IS_USING_POLL_, MHD_D_IS_USING_SELECT_, MHD_D_IS_USING_THREADS_, MHD_NO, MHD_select(), MHD_thread_handle_ID_is_valid_handle_, and MHD_Daemon::shutdown.

Referenced by MHD_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_start_daemon()

_MHD_EXTERN struct MHD_Daemon * MHD_start_daemon ( unsigned int flags,
uint16_t port,
MHD_AcceptPolicyCallback apc,
void * apc_cls,
MHD_AccessHandlerCallback dh,
void * dh_cls,
... )

Start a webserver on the given port. Variadic version of MHD_start_daemon_va.

Parameters
flagscombination of enum MHD_FLAG values
portport to bind to (in host byte order), use '0' to bind to random free port, ignored if MHD_OPTION_SOCK_ADDR or MHD_OPTION_LISTEN_SOCKET is provided or MHD_USE_NO_LISTEN_SOCKET is specified
apccallback to call to check which clients will be allowed to connect; you can pass NULL in which case connections from any IP will be accepted
apc_clsextra argument to apc
dhhandler called for all requests (repeatedly)
dh_clsextra argument to dh
Returns
NULL on error, handle to daemon on success

Start a webserver on the given port. Variadic version of MHD_start_daemon_va.

Parameters
flagscombination of enum MHD_FLAG values
portport to bind to (in host byte order), use '0' to bind to random free port, ignored if MHD_OPTION_SOCK_ADDR or MHD_OPTION_LISTEN_SOCKET is provided or MHD_USE_NO_LISTEN_SOCKET is specified
apccallback to call to check which clients will be allowed to connect; you can pass NULL in which case connections from any IP will be accepted
apc_clsextra argument to apc
dhhandler called for all requests (repeatedly)
dh_clsextra argument to dh
Returns
NULL on error, handle to daemon on success

Definition at line 6103 of file daemon.c.

References MHD_Daemon::apc, MHD_Daemon::apc_cls, MHD_start_daemon_va(), and MHD_Daemon::port.

Here is the call graph for this function:

◆ MHD_start_daemon_va()

_MHD_EXTERN struct MHD_Daemon * MHD_start_daemon_va ( unsigned int flags,
uint16_t port,
MHD_AcceptPolicyCallback apc,
void * apc_cls,
MHD_AccessHandlerCallback dh,
void * dh_cls,
va_list ap )

Start a webserver on the given port.

Parameters
flagscombination of enum MHD_FLAG values
portport to bind to (in host byte order), use '0' to bind to random free port, ignored if MHD_OPTION_SOCK_ADDR or MHD_OPTION_LISTEN_SOCKET is provided or MHD_USE_NO_LISTEN_SOCKET is specified
apccallback to call to check which clients will be allowed to connect; you can pass NULL in which case connections from any IP will be accepted
apc_clsextra argument to apc
dhhandler called for all requests (repeatedly)
dh_clsextra argument to dh
aplist of options (type-value pairs, terminated with MHD_OPTION_END).
Returns
NULL on error, handle to daemon on success

Start a webserver on the given port.

Parameters
flagscombination of enum MHD_FLAG values
portport to bind to (in host byte order), use '0' to bind to random free port, ignored if MHD_OPTION_SOCK_ADDR or MHD_OPTION_LISTEN_SOCKET is provided or MHD_USE_NO_LISTEN_SOCKET is specified
apccallback to call to check which clients will be allowed to connect; you can pass NULL in which case connections from any IP will be accepted
apc_clsextra argument to apc
dhhandler called for all requests (repeatedly)
dh_clsextra argument to dh
aplist of options (type-value pairs, terminated with MHD_OPTION_END).
Returns
NULL on error, handle to daemon on success

Definition at line 7665 of file daemon.c.

References _, _MHD_NO, _MHD_UNKNOWN, _MHD_YES, MHD_Daemon::apc, MHD_Daemon::apc_cls, MHD_Daemon::client_discipline, MHD_Daemon::connection_limit, MHD_Daemon::connection_timeout_ms, MHD_Daemon::connections, MHD_Daemon::default_handler, MHD_Daemon::default_handler_cls, MHD_Daemon::itc, MHD_Daemon::listen_backlog_size, MHD_Daemon::listen_fd, MHD_Daemon::listen_is_unix, MHD_Daemon::listen_nonblk, MHD_Daemon::listening_address_reuse, MHD_Daemon::master, MHD_ALLOW_SUSPEND_RESUME, MHD_ALLOW_UPGRADE, mhd_assert, MHD_BUF_INC_SIZE, MHD_calloc_(), MHD_check_global_init_(), MHD_create_named_thread_, MHD_D_DOES_SCKT_FIT_FDSET_, MHD_D_GET_FD_SETSIZE_, MHD_D_IS_USING_EPOLL_, MHD_D_IS_USING_SELECT_, MHD_D_IS_USING_THREAD_PER_CONN_, MHD_D_IS_USING_THREADS_, MHD_DAUTH_DEF_MAX_NC_, MHD_DAUTH_DEF_TIMEOUT_, MHD_INVALID_SOCKET, MHD_itc_destroy_chk_, MHD_MAX_CONNECTIONS_DEFAULT, MHD_mutex_destroy_chk_, MHD_mutex_init_, MHD_NO, MHD_PANIC, MHD_POOL_SIZE_DEFAULT, MHD_POSIX_SOCKETS, MHD_socket_close_, MHD_socket_create_listen_(), MHD_socket_last_strerr_, MHD_socket_nonblocking_(), MHD_stop_daemon(), MHD_strerror_, MHD_thread_handle_ID_set_invalid_, MHD_USE_AUTO, MHD_USE_DUAL_STACK, MHD_USE_EPOLL, MHD_USE_INTERNAL_POLLING_THREAD, MHD_USE_IPv6, MHD_USE_ITC, MHD_USE_NO_LISTEN_SOCKET, MHD_USE_NO_THREAD_SAFETY, MHD_USE_PEDANTIC_CHECKS, MHD_USE_POLL, MHD_USE_TCP_FASTOPEN, MHD_USE_THREAD_PER_CONNECTION, MHD_USE_TLS, MHD_Daemon::notify_completed, MHD_Daemon::notify_connection, NULL, MHD_Daemon::options, parse_options_va(), MHD_Daemon::pool_increment, MHD_Daemon::pool_size, MHD_Daemon::port, process_interim_params(), MHD_Daemon::sigpipe_blocked, MHD_Daemon::unescape_callback, and unescape_wrapper().

Referenced by MHD_start_daemon().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_stop_daemon()