GNU libmicrohttpd  0.9.72
mhd_send.c File Reference

Implementation of send() wrappers and helper functions. More...

#include "mhd_send.h"
#include "mhd_assert.h"
#include "mhd_limits.h"
Include dependency graph for mhd_send.c:

Go to the source code of this file.

Macros

#define MHD_SENFILE_CHUNK_   (0x20000)
 
#define MHD_SENFILE_CHUNK_THR_P_C_   (0x200000)
 
#define _MHD_SEND_VEC_MAX   MHD_SCKT_SEND_MAX_SIZE_
 

Functions

static bool connection_set_nodelay_state_ (struct MHD_Connection *connection, bool nodelay_state)
 
static void pre_send_setopt (struct MHD_Connection *connection, bool plain_send, bool push_data)
 
static bool zero_send_ (struct MHD_Connection *connection)
 
static void post_send_setopt (struct MHD_Connection *connection, bool plain_send_next, bool push_data)
 
ssize_t MHD_send_data_ (struct MHD_Connection *connection, const char *buffer, size_t buffer_size, bool push_data)
 
ssize_t MHD_send_hdr_and_body_ (struct MHD_Connection *connection, const char *header, size_t header_size, bool never_push_hdr, const char *body, size_t body_size, bool complete_response)
 

Detailed Description

Implementation of send() wrappers and helper functions.

Author
Karlson2k (Evgeny Grin)
ng0 (N. Gillmann)
Christian Grothoff

Definition in file mhd_send.c.

Macro Definition Documentation

◆ _MHD_SEND_VEC_MAX

#define _MHD_SEND_VEC_MAX   MHD_SCKT_SEND_MAX_SIZE_

◆ MHD_SENFILE_CHUNK_

#define MHD_SENFILE_CHUNK_   (0x20000)

sendfile() chuck size

Definition at line 57 of file mhd_send.c.

◆ MHD_SENFILE_CHUNK_THR_P_C_

#define MHD_SENFILE_CHUNK_THR_P_C_   (0x200000)

sendfile() chuck size for thread-per-connection

Definition at line 62 of file mhd_send.c.

Function Documentation

◆ connection_set_nodelay_state_()

static bool connection_set_nodelay_state_ ( struct MHD_Connection connection,
bool  nodelay_state 
)
static

Set required TCP_NODELAY state for connection socket

The function automatically updates sk_nodelay state.

Parameters
connectionthe connection to manipulate
nodelay_statethe requested new state of socket
Returns
true if succeed, false if failed

Definition at line 117 of file mhd_send.c.

References _, MHD_Connection::daemon, MHD_socket_get_error_, MHD_socket_strerr_, MHD_Connection::sk_nodelay, and MHD_Connection::socket_fd.

Referenced by post_send_setopt(), and pre_send_setopt().

Here is the caller graph for this function:

◆ MHD_send_data_()

ssize_t MHD_send_data_ ( struct MHD_Connection connection,
const char *  buffer,
size_t  buffer_size,
bool  push_data 
)

Send buffer to the client, push data from network buffer if requested and full buffer is sent.

Parameters
connectionthe MHD_Connection structure
buffercontent of the buffer to send
buffer_sizethe size of the buffer (in bytes)
push_dataset to true to force push the data to the network from system buffers (usually set for the last piece of data), set to false to prefer holding incomplete network packets (more data will be send for the same reply).
Returns
sum of the number of bytes sent from both buffers or error code (negative)

Definition at line 662 of file mhd_send.c.

References MHD_Connection::daemon, MHD_CONNECTION_CLOSED, MHD_EPOLL_STATE_WRITE_READY, MHD_ERR_AGAIN_, MHD_ERR_CONNRESET_, MHD_ERR_NOMEM_, MHD_ERR_NOTCONN_, MHD_INVALID_SOCKET, MHD_SCKT_ECONNRESET_, MHD_SCKT_ERR_IS_, MHD_SCKT_ERR_IS_EAGAIN_, MHD_SCKT_ERR_IS_EINTR_, MHD_SCKT_ERR_IS_LOW_RESOURCES_, MHD_SCKT_SEND_MAX_SIZE_, MHD_send4_, MHD_socket_get_error_, MHD_USE_TLS, MHD_Daemon::options, post_send_setopt(), pre_send_setopt(), MHD_Connection::socket_fd, SSIZE_MAX, and MHD_Connection::state.

Referenced by MHD_connection_handle_write(), and MHD_send_hdr_and_body_().

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

◆ MHD_send_hdr_and_body_()

ssize_t MHD_send_hdr_and_body_ ( struct MHD_Connection connection,
const char *  header,
size_t  header_size,
bool  never_push_hdr,
const char *  body,
size_t  body_size,
bool  complete_response 
)

Send reply header with optional reply body.

Parameters
connectionthe MHD_Connection structure
headercontent of header to send
header_sizethe size of the header (in bytes)
never_push_hdrset to true to disable internal algorithm that can push automatically header data alone to the network
bodycontent of the body to send (optional, may be NULL)
body_sizethe size of the body (in bytes)
complete_responseset to true if complete response is provided by header and body, set to false if additional body data will be sent later
Returns
sum of the number of bytes sent from both buffers or error code (negative)

Definition at line 789 of file mhd_send.c.

References _MHD_SEND_VEC_MAX, MHD_Connection::daemon, mhd_assert, MHD_CONNECTION_CLOSED, MHD_EPOLL_STATE_WRITE_READY, MHD_ERR_AGAIN_, MHD_ERR_CONNRESET_, MHD_ERR_NOMEM_, MHD_ERR_NOTCONN_, MHD_INVALID_SOCKET, MHD_SCKT_ECONNRESET_, MHD_SCKT_ERR_IS_, MHD_SCKT_ERR_IS_EAGAIN_, MHD_SCKT_ERR_IS_EINTR_, MHD_SCKT_ERR_IS_LOW_RESOURCES_, MHD_send_data_(), MHD_socket_get_error_, MHD_USE_TLS, MSG_NOSIGNAL_OR_ZERO, NULL, MHD_Daemon::options, post_send_setopt(), pre_send_setopt(), MHD_Daemon::sigpipe_blocked, MHD_Connection::sk_nonblck, MHD_Connection::sk_spipe_suppress, MHD_Connection::socket_fd, SSIZE_MAX, MHD_Connection::state, and UINT_MAX.

Referenced by MHD_connection_handle_write().

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

◆ post_send_setopt()

static void post_send_setopt ( struct MHD_Connection connection,
bool  plain_send_next,
bool  push_data 
)
static

Handle post-send setsockopt calls.

Parameters
connectionthe MHD_Connection structure
plain_send_nextset to true if plain send() or sendmsg() will be called next, set to false if TLS socket send(), sendfile() or writev() will be called next.
push_datawhether to push data to the network from buffers

Definition at line 493 of file mhd_send.c.

References _, _MHD_OFF, _MHD_ON, connection_set_nodelay_state_(), MHD_Connection::daemon, mhd_assert, MHD_Connection::sk_corked, MHD_Connection::sk_nodelay, and zero_send_().

Referenced by MHD_send_data_(), and MHD_send_hdr_and_body_().

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

◆ pre_send_setopt()

static void pre_send_setopt ( struct MHD_Connection connection,
bool  plain_send,
bool  push_data 
)
static

Handle pre-send setsockopt calls.

Parameters
connectionthe MHD_Connection structure
plain_sendset to true if plain send() or sendmsg() will be called, set to false if TLS socket send(), sendfile() or writev() will be called.
push_datawhether to push data to the network from buffers after the next call of send function.

Definition at line 234 of file mhd_send.c.

References _MHD_OFF, _MHD_ON, _MHD_UNKNOWN, connection_set_nodelay_state_(), MHD_Connection::sk_corked, and MHD_Connection::sk_nodelay.

Referenced by MHD_send_data_(), and MHD_send_hdr_and_body_().

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

◆ zero_send_()

static bool zero_send_ ( struct MHD_Connection connection)
static

Send zero-sized data

This function use send of zero-sized data to kick data from the socket buffers to the network. The socket must not be corked and must have TCP_NODELAY switched on. Used only as last resort option, when other options are failed due to some errors. Should not be called on typical data processing.

Returns
true if succeed, false if failed

Definition at line 460 of file mhd_send.c.

References _, _MHD_OFF, _MHD_ON, MHD_Connection::daemon, mhd_assert, MHD_send_, MHD_socket_last_strerr_, MHD_Connection::sk_corked, MHD_Connection::sk_nodelay, and MHD_Connection::socket_fd.

Referenced by post_send_setopt().

Here is the caller graph for this function: