GNU libmicrohttpd 1.0.2
Loading...
Searching...
No Matches
connection.h File Reference

Methods for managing connections. More...

#include "internal.h"
Include dependency graph for connection.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MHD_ERR_AGAIN_   (-3073)
#define MHD_ERR_CONNRESET_   (-3074)
#define MHD_ERR_NOTCONN_   (-3075)
#define MHD_ERR_NOMEM_   (-3076)
#define MHD_ERR_BADF_   (-3077)
#define MHD_ERR_INVAL_   (-3078)
#define MHD_ERR_OPNOTSUPP_   (-3079)
#define MHD_ERR_PIPE_   (-3080)
#define MHD_ERR_TLS_   (-4097)
#define MHD_connection_finish_forward_(conn)

Functions

void MHD_set_http_callbacks_ (struct MHD_Connection *connection)
void MHD_connection_set_initial_state_ (struct MHD_Connection *c)
void MHD_connection_handle_read (struct MHD_Connection *connection, bool socket_error)
void MHD_connection_handle_write (struct MHD_Connection *connection)
enum MHD_Result MHD_connection_handle_idle (struct MHD_Connection *connection)
void MHD_connection_mark_closed_ (struct MHD_Connection *connection)
void MHD_connection_close_ (struct MHD_Connection *connection, enum MHD_RequestTerminationCode termination_code)
void MHD_update_last_activity_ (struct MHD_Connection *connection)
void * MHD_connection_alloc_memory_ (struct MHD_Connection *connection, size_t size)

Detailed Description

Methods for managing connections.

Author
Daniel Pittman
Christian Grothoff
Karlson2k (Evgeny Grin)

Definition in file connection.h.

Macro Definition Documentation

◆ MHD_connection_finish_forward_

#define MHD_connection_finish_forward_ ( conn)
Value:
(void) conn

Definition at line 174 of file connection.h.

Referenced by close_all_connections(), and internal_run_from_select().

◆ MHD_ERR_AGAIN_

#define MHD_ERR_AGAIN_   (-3073)

◆ MHD_ERR_BADF_

#define MHD_ERR_BADF_   (-3077)

"Bad FD" error code

Definition at line 58 of file connection.h.

Referenced by MHD_send_data_(), MHD_send_hdr_and_body_(), and recv_param_adapter().

◆ MHD_ERR_CONNRESET_

#define MHD_ERR_CONNRESET_   (-3074)

Connection was hard-closed by remote peer.

Definition at line 42 of file connection.h.

Referenced by MHD_connection_handle_read(), MHD_send_data_(), MHD_send_hdr_and_body_(), recv_param_adapter(), and recv_tls_adapter().

◆ MHD_ERR_INVAL_

#define MHD_ERR_INVAL_   (-3078)

Error code similar to EINVAL

Definition at line 63 of file connection.h.

Referenced by MHD_send_data_(), MHD_send_hdr_and_body_(), and recv_param_adapter().

◆ MHD_ERR_NOMEM_

#define MHD_ERR_NOMEM_   (-3076)

"Not enough memory" error code

Definition at line 53 of file connection.h.

Referenced by MHD_send_data_(), MHD_send_hdr_and_body_(), recv_param_adapter(), and recv_tls_adapter().

◆ MHD_ERR_NOTCONN_

#define MHD_ERR_NOTCONN_   (-3075)

Connection is not connected anymore due to network error or any other reason.

Definition at line 48 of file connection.h.

Referenced by MHD_send_data_(), MHD_send_hdr_and_body_(), recv_param_adapter(), and recv_tls_adapter().

◆ MHD_ERR_OPNOTSUPP_

#define MHD_ERR_OPNOTSUPP_   (-3079)

Argument values are not supported

Definition at line 68 of file connection.h.

Referenced by MHD_send_data_(), MHD_send_hdr_and_body_(), and recv_param_adapter().

◆ MHD_ERR_PIPE_

#define MHD_ERR_PIPE_   (-3080)

Socket is shut down for writing or no longer connected

Definition at line 73 of file connection.h.

Referenced by MHD_send_data_(), MHD_send_hdr_and_body_(), and recv_tls_adapter().

◆ MHD_ERR_TLS_

#define MHD_ERR_TLS_   (-4097)

General TLS encryption or decryption error

Definition at line 78 of file connection.h.

Referenced by MHD_send_data_(), and recv_tls_adapter().

Function Documentation

◆ MHD_connection_alloc_memory_()

void * MHD_connection_alloc_memory_ ( struct MHD_Connection * connection,
size_t size )

Allocate memory from connection's memory pool. If memory pool doesn't have enough free memory but read or write buffer have some unused memory, the size of the buffer will be reduced as needed.

Parameters
connectionthe connection to use
sizethe size of allocated memory area
Returns
pointer to allocated memory region in the pool or NULL if no memory is available

< The required amount of additional free memory

Definition at line 651 of file connection.c.

References mhd_assert, MHD_pool_allocate(), MHD_pool_is_resizable_inplace(), MHD_pool_reallocate(), MHD_pool_try_alloc(), NULL, MHD_Connection::pool, MHD_Connection::read_buffer, MHD_Connection::read_buffer_offset, MHD_Connection::read_buffer_size, MHD_Connection::write_buffer, MHD_Connection::write_buffer_append_offset, MHD_Connection::write_buffer_send_offset, and MHD_Connection::write_buffer_size.

Referenced by MHD_set_connection_value_n_nocheck_(), and try_ready_normal_body().

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

◆ MHD_connection_close_()

void MHD_connection_close_ ( struct MHD_Connection * connection,
enum MHD_RequestTerminationCode termination_code )

Close the given connection and give the specified termination code to the user.

Remarks
To be called only from thread that process connection's recv(), send() and response.
Parameters
connectionconnection to close
termination_codetermination reason to give

Definition at line 1246 of file connection.c.

References MHD_Request::client_aware, MHD_Request::client_context, MHD_Connection::daemon, mhd_assert, MHD_connection_mark_closed_(), MHD_D_IS_USING_THREADS_, MHD_destroy_response(), MHD_pool_destroy(), MHD_thread_handle_ID_is_current_thread_, MHD_Daemon::notify_completed, MHD_Daemon::notify_completed_cls, NULL, MHD_Connection::pool, MHD_Reply::response, MHD_Connection::rp, MHD_Connection::rq, and MHD_Connection::suspended.

Referenced by call_handlers(), close_connection(), connection_close_error(), connection_reset(), MHD_connection_handle_idle(), MHD_connection_handle_read(), MHD_run_tls_handshake_(), and try_ready_normal_body().

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

◆ MHD_connection_handle_idle()

enum MHD_Result MHD_connection_handle_idle ( struct MHD_Connection * connection)

This function was created to handle per-connection processing that has to happen even if the socket cannot be read or written to. All implementations (multithreaded, external select, internal select) call this function.

Remarks
To be called only from thread that process connection's recv(), send() and response.
Parameters
connectionconnection to handle
Returns
MHD_YES if we should continue to process the connection (not dead yet), MHD_NO if it died

Definition at line 7180 of file connection.c.

References _, build_connection_chunked_response_footer(), build_header_response(), call_connection_handler(), MHD_Reply_Properties::chunked, cleanup_connection(), connection_check_timedout(), CONNECTION_CLOSE_ERROR, connection_reset(), connection_switch_from_recv_to_send(), MHD_Connection::continue_message_write_offset, MHD_Response::crc, MHD_Connection::daemon, MHD_Connection::discard_request, get_req_headers(), get_request_line(), MHD_Request::have_chunked_upload, HTTP_100_CONTINUE, MHD_Request::http_ver, MHD_Connection::in_idle, MHD_Connection::keepalive, mhd_assert, MHD_CONN_USE_KEEPALIVE, MHD_CONNECTION_BODY_RECEIVED, MHD_CONNECTION_BODY_RECEIVING, MHD_CONNECTION_CHUNKED_BODY_READY, MHD_CONNECTION_CHUNKED_BODY_SENT, MHD_CONNECTION_CHUNKED_BODY_UNREADY, MHD_connection_close_(), MHD_CONNECTION_CLOSED, MHD_CONNECTION_CONTINUE_SENDING, MHD_CONNECTION_FOOTERS_RECEIVED, MHD_CONNECTION_FOOTERS_RECEIVING, MHD_CONNECTION_FOOTERS_SENDING, MHD_CONNECTION_FULL_REPLY_SENT, MHD_CONNECTION_FULL_REQ_RECEIVED, MHD_CONNECTION_HEADERS_PROCESSED, MHD_CONNECTION_HEADERS_RECEIVED, MHD_CONNECTION_HEADERS_SENDING, MHD_CONNECTION_HEADERS_SENT, MHD_CONNECTION_INIT, MHD_CONNECTION_NORMAL_BODY_READY, MHD_CONNECTION_NORMAL_BODY_UNREADY, MHD_CONNECTION_REQ_HEADERS_RECEIVING, MHD_CONNECTION_REQ_LINE_RECEIVED, MHD_CONNECTION_REQ_LINE_RECEIVING, MHD_CONNECTION_START_REPLY, MHD_connection_update_event_loop_info(), MHD_D_IS_USING_EPOLL_, MHD_D_IS_USING_THREADS_, MHD_destroy_response(), MHD_FUNC_, MHD_HTTP_PROCESSING, MHD_IS_HTTP_VER_SUPPORTED, MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_NO, MHD_REQUEST_TERMINATED_TIMEOUT_REACHED, MHD_response_execute_upgrade_(), MHD_STATICSTR_LEN_, MHD_thread_handle_ID_is_current_thread_, MHD_TLS_CONN_CONNECTED, MHD_TLS_CONN_INIT, MHD_TLS_CONN_NO_TLS, MHD_YES, need_100_continue(), NULL, MHD_Request::num_cr_sp_replaced, parse_connection_headers(), process_request_body(), MHD_Reply::props, MHD_Connection::read_buffer_offset, MHD_Connection::read_closed, MHD_Request::remaining_upload_size, reset_rq_header_processing_state(), MHD_Reply::response, MHD_Reply::responseCode, MHD_Connection::rp, MHD_Connection::rq, MHD_Reply::rsp_write_position, MHD_Reply_Properties::send_reply_body, MHD_Request::skipped_broken_lines, MHD_Connection::state, MHD_Connection::suspended, switch_to_rq_headers_processing(), MHD_Response::total_size, try_ready_chunked_body(), try_ready_normal_body(), MHD_Connection::write_buffer_append_offset, and MHD_Connection::write_buffer_send_offset.

Referenced by call_handlers(), and MHD_queue_response().

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

◆ MHD_connection_handle_read()

void MHD_connection_handle_read ( struct MHD_Connection * connection,
bool socket_error )

This function handles a particular connection when it has been determined that there is data to be read off a socket. All implementations (multithreaded, external polling, internal polling) call this function to handle reads.

Parameters
connectionconnection to handle
socket_errorset to true if socket error was detected

Definition at line 6412 of file connection.c.

References _, CONNECTION_CLOSE_ERROR, MHD_Connection::daemon, MHD_Connection::discard_request, mhd_assert, MHD_CONNECTION_BODY_RECEIVED, MHD_CONNECTION_BODY_RECEIVING, MHD_CONNECTION_CHUNKED_BODY_READY, MHD_CONNECTION_CHUNKED_BODY_SENT, MHD_CONNECTION_CHUNKED_BODY_UNREADY, MHD_connection_close_(), MHD_CONNECTION_CLOSED, MHD_CONNECTION_CONTINUE_SENDING, MHD_CONNECTION_FOOTERS_RECEIVED, MHD_CONNECTION_FOOTERS_RECEIVING, MHD_CONNECTION_FOOTERS_SENDING, MHD_CONNECTION_FULL_REPLY_SENT, MHD_CONNECTION_FULL_REQ_RECEIVED, MHD_CONNECTION_HEADERS_PROCESSED, MHD_CONNECTION_HEADERS_RECEIVED, MHD_CONNECTION_HEADERS_SENDING, MHD_CONNECTION_HEADERS_SENT, MHD_CONNECTION_INIT, MHD_CONNECTION_NORMAL_BODY_READY, MHD_CONNECTION_NORMAL_BODY_UNREADY, MHD_CONNECTION_REQ_HEADERS_RECEIVING, MHD_CONNECTION_REQ_LINE_RECEIVED, MHD_CONNECTION_REQ_LINE_RECEIVING, MHD_CONNECTION_START_REPLY, MHD_ERR_AGAIN_, MHD_ERR_CONNRESET_, MHD_FUNC_, MHD_pool_reallocate(), MHD_REQUEST_TERMINATED_CLIENT_ABORT, MHD_REQUEST_TERMINATED_COMPLETED_OK, MHD_REQUEST_TERMINATED_READ_ERROR, MHD_REQUEST_TERMINATED_WITH_ERROR, MHD_run_tls_handshake_(), MHD_TLS_CONN_CONNECTED, MHD_TLS_CONN_NO_TLS, MHD_update_last_activity_(), NULL, MHD_Connection::pool, MHD_Connection::read_buffer, MHD_Connection::read_buffer_offset, MHD_Connection::read_buffer_size, MHD_Connection::read_closed, MHD_Connection::recv_cls, MHD_Connection::sk_nonblck, MHD_Connection::state, and MHD_Connection::suspended.

Referenced by call_handlers().

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

◆ MHD_connection_handle_write()

void MHD_connection_handle_write ( struct MHD_Connection * connection)

This function was created to handle writes to sockets when it has been determined that the socket can be written to. All implementations (multithreaded, external select, internal select) call this function

Parameters
connectionconnection to handle

Definition at line 6585 of file connection.c.

References _, check_write_done(), MHD_Reply_Properties::chunked, CONNECTION_CLOSE_ERROR, MHD_Connection::continue_message_write_offset, MHD_Response::crc, MHD_Connection::daemon, MHD_Response::data, MHD_Response::data_iov, MHD_Response::data_size, MHD_Response::data_start, HTTP_100_CONTINUE, MHD_Connection::keepalive, mhd_assert, MHD_CONN_MUST_UPGRADE, MHD_CONNECTION_BODY_RECEIVED, MHD_CONNECTION_BODY_RECEIVING, MHD_CONNECTION_CHUNKED_BODY_READY, MHD_CONNECTION_CHUNKED_BODY_SENT, MHD_CONNECTION_CHUNKED_BODY_UNREADY, MHD_CONNECTION_CLOSED, MHD_CONNECTION_CONTINUE_SENDING, MHD_CONNECTION_FOOTERS_RECEIVED, MHD_CONNECTION_FOOTERS_RECEIVING, MHD_CONNECTION_FOOTERS_SENDING, MHD_CONNECTION_FULL_REPLY_SENT, MHD_CONNECTION_FULL_REQ_RECEIVED, MHD_CONNECTION_HEADERS_PROCESSED, MHD_CONNECTION_HEADERS_RECEIVED, MHD_CONNECTION_HEADERS_SENDING, MHD_CONNECTION_HEADERS_SENT, MHD_CONNECTION_INIT, MHD_CONNECTION_NORMAL_BODY_READY, MHD_CONNECTION_NORMAL_BODY_UNREADY, MHD_CONNECTION_REQ_HEADERS_RECEIVING, MHD_CONNECTION_REQ_LINE_RECEIVED, MHD_CONNECTION_REQ_LINE_RECEIVING, MHD_CONNECTION_START_REPLY, MHD_ERR_AGAIN_, MHD_FUNC_, MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_NO, MHD_PANIC, MHD_run_tls_handshake_(), MHD_send_data_(), MHD_send_hdr_and_body_(), MHD_send_iovec_(), MHD_STATICSTR_LEN_, MHD_TLS_CONN_CONNECTED, MHD_TLS_CONN_NO_TLS, MHD_update_last_activity_(), NULL, MHD_Reply::props, MHD_Reply::resp_iov, MHD_Reply::response, MHD_Connection::rp, MHD_Connection::rq, MHD_Reply::rsp_write_position, MHD_Reply_Properties::send_reply_body, SIZE_MAX, MHD_Connection::state, MHD_Connection::suspended, MHD_Response::total_size, try_ready_normal_body(), MHD_Request::url, MHD_Connection::write_buffer, MHD_Connection::write_buffer_append_offset, and MHD_Connection::write_buffer_send_offset.

Referenced by call_handlers().

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

◆ MHD_connection_mark_closed_()

void MHD_connection_mark_closed_ ( struct MHD_Connection * connection)

Mark connection as "closed".

Remarks
To be called from any thread.
Parameters
connectionconnection to close

Definition at line 1208 of file connection.c.

References MHD_Connection::daemon, MHD_Connection::event_loop_info, MHD_CONNECTION_CLOSED, MHD_EVENT_LOOP_INFO_CLEANUP, MHD_tls_connection_shutdown(), MHD_USE_TLS, MHD_USE_TURBO, MHD_Daemon::options, MHD_Daemon::shutdown, MHD_Connection::socket_fd, and MHD_Connection::state.

Referenced by close_connection(), and MHD_connection_close_().

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

◆ MHD_connection_set_initial_state_()

◆ MHD_set_http_callbacks_()

void MHD_set_http_callbacks_ ( struct MHD_Connection * connection)

Set callbacks for this connection to those for HTTP.

Parameters
connectionconnection to initialize

Definition at line 7617 of file connection.c.

References MHD_Connection::recv_cls, and recv_param_adapter().

Referenced by new_connection_prepare_().

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

◆ MHD_update_last_activity_()

void MHD_update_last_activity_ ( struct MHD_Connection * connection)

Update the 'last_activity' field of the connection to the current time and move the connection to the head of the 'normal_timeout' list if the timeout for the connection uses the default value.

Parameters
connectionthe connection that saw some activity

Definition at line 6367 of file connection.c.

References MHD_Connection::connection_timeout_ms, MHD_Daemon::connection_timeout_ms, MHD_Connection::daemon, MHD_Connection::last_activity, mhd_assert, MHD_D_IS_USING_THREAD_PER_CONN_, MHD_monotonic_msec_counter(), MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_Daemon::normal_timeout_head, MHD_Daemon::normal_timeout_tail, NULL, MHD_Connection::suspended, XDLL_insert, and XDLL_remove.

Referenced by MHD_connection_handle_read(), MHD_connection_handle_write(), MHD_queue_response(), and MHD_run_tls_handshake_().

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