Refactoring: moved socket-specific connection data to special structure

This commit is contained in:
Evgeny Grin (Karlson2k)
2024-11-21 22:44:19 +03:00
parent 80d55d8274
commit f996b18c04
16 changed files with 343 additions and 256 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ libmicrohttpd2_la_SOURCES = \
mhd_lib_init.c mhd_lib_init_impl.h mhd_lib_init.h \
mhd_lib_init_auto.h \
mhd_dlinked_list.h \
mhd_connection.h \
mhd_conn_socket.h mhd_connection.h \
mhd_locks.h \
mhd_itc.c mhd_itc.h mhd_itc_types.h \
mhd_threads.c mhd_threads.h sys_thread_entry_type.h \
+8 -7
View File
@@ -57,7 +57,7 @@ mhd_conn_process_recv_send_data (struct MHD_Connection *restrict c)
((mhd_D_IS_USING_EDGE_TRIG (c->daemon)) ||
(0 != (MHD_EVENT_LOOP_INFO_SEND & c->event_loop_info)));
const bool has_sock_err =
(0 != (mhd_SOCKET_NET_STATE_ERROR_READY & c->sk_ready));
(0 != (mhd_SOCKET_NET_STATE_ERROR_READY & c->sk.ready));
bool data_processed;
data_processed = false;
@@ -65,9 +65,9 @@ mhd_conn_process_recv_send_data (struct MHD_Connection *restrict c)
if (0 != (MHD_EVENT_LOOP_INFO_RECV & c->event_loop_info))
{
bool use_recv;
use_recv = (0 != (mhd_SOCKET_NET_STATE_RECV_READY & c->sk_ready));
use_recv = (0 != (mhd_SOCKET_NET_STATE_RECV_READY & c->sk.ready));
use_recv = use_recv ||
(has_sock_err && c->sk_nonblck);
(has_sock_err && c->sk.props.is_nonblck);
if (use_recv)
{
@@ -89,11 +89,12 @@ mhd_conn_process_recv_send_data (struct MHD_Connection *restrict c)
/* Assuming that after finishing receiving phase, connection send system
buffers should have some space as sending was performed before receiving
or has not been performed yet. */
use_send = (0 != (mhd_SOCKET_NET_STATE_SEND_READY & c->sk_ready));
use_send = (0 != (mhd_SOCKET_NET_STATE_SEND_READY & c->sk.ready));
use_send = use_send ||
(data_processed && (! send_ready_state_known) && c->sk_nonblck);
(data_processed && (! send_ready_state_known)
&& c->sk.props.is_nonblck);
use_send = use_send ||
(has_sock_err && c->sk_nonblck);
(has_sock_err && c->sk.props.is_nonblck);
if (use_send)
{
@@ -142,7 +143,7 @@ mhd_conn_process_recv_send_data (struct MHD_Connection *restrict c)
only for non-blocking sockets. */
/* No need to check 'ret' as connection is always in
* MHD_CONNECTION_CLOSED state if 'ret' is equal 'MHD_NO'. */
else if (on_fasttrack && c->sk_nonblck)
else if (on_fasttrack && c->sk.props.is_nonblck)
{
if (MHD_CONNECTION_HEADERS_SENDING == c->state)
{
+9 -9
View File
@@ -53,8 +53,8 @@ mhd_conn_data_recv (struct MHD_Connection *restrict c,
mhd_assert (NULL != c->read_buffer);
mhd_assert (c->read_buffer_size > c->read_buffer_offset);
mhd_assert (! has_err || \
(0 != (c->sk_ready & mhd_SOCKET_NET_STATE_ERROR_READY)));
mhd_assert ((0 == (c->sk_ready & mhd_SOCKET_NET_STATE_ERROR_READY)) || \
(0 != (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY)));
mhd_assert ((0 == (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY)) || \
has_err);
// TODO: TLS support: handshake/transport layer
@@ -69,10 +69,10 @@ mhd_conn_data_recv (struct MHD_Connection *restrict c,
/* Handle errors */
if ((mhd_SOCKET_ERR_NO_ERROR == res) && (0 == received))
{
c->sk_rmt_shut_wr = true;
c->sk.state.rmt_shut_wr = true;
res = mhd_SOCKET_ERR_REMT_DISCONN;
}
if (has_err && ! mhd_SOCKET_ERR_IS_HARD (res) && c->sk_nonblck)
if (has_err && ! mhd_SOCKET_ERR_IS_HARD (res) && c->sk.props.is_nonblck)
{
/* Re-try last time to detect the error */
uint_fast64_t dummy_buf;
@@ -80,16 +80,16 @@ mhd_conn_data_recv (struct MHD_Connection *restrict c,
}
if (mhd_SOCKET_ERR_IS_HARD (res))
{
c->sk_discnt_err = res;
c->sk_ready =
(enum mhd_SocketNetState) (((unsigned int) c->sk_ready)
c->sk.state.discnt_err = res;
c->sk.ready =
(enum mhd_SocketNetState) (((unsigned int) c->sk.ready)
| mhd_SOCKET_NET_STATE_ERROR_READY);
}
return;
}
if (0 == received)
c->sk_rmt_shut_wr = true;
c->sk.state.rmt_shut_wr = true;
c->read_buffer_offset += received;
mhd_stream_update_activity_mark (c); // TODO: centralise activity update
@@ -132,7 +132,7 @@ if ((bytes_read < 0) || socket_error)
#if 0 // TODO: handle remote shut WR
if (0 == bytes_read)
{ /* Remote side closed c. */ // FIXME: Actually NOT!
c->sk_rmt_shut_wr = true;
c->sk.state.rmt_shut_wr = true;
if ( (MHD_CONNECTION_INIT < c->state) &&
(MHD_CONNECTION_FULL_REQ_RECEIVED > c->state) )
{
+3 -3
View File
@@ -343,9 +343,9 @@ mhd_conn_data_send (struct MHD_Connection *restrict c)
}
else if (mhd_SOCKET_ERR_IS_HARD (res))
{
c->sk_discnt_err = res;
c->sk_ready =
(enum mhd_SocketNetState) (((unsigned int) c->sk_ready)
c->sk.state.discnt_err = res;
c->sk.ready =
(enum mhd_SocketNetState) (((unsigned int) c->sk.ready)
| mhd_SOCKET_NET_STATE_ERROR_READY);
}
}
+27 -27
View File
@@ -168,18 +168,18 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon,
if (! external_add)
{
connection->sk_corked = mhd_T_NO;
connection->sk_nodelay = mhd_T_NO;
connection->sk.state.corked = mhd_T_NO;
connection->sk.state.nodelay = mhd_T_NO;
}
else
{
connection->sk_corked = mhd_T_MAYBE;
connection->sk_nodelay = mhd_T_MAYBE;
connection->sk.state.corked = mhd_T_MAYBE;
connection->sk.state.nodelay = mhd_T_MAYBE;
}
if (0 < addrlen)
{
if (NULL == (connection->addr = malloc (addrlen)))
if (NULL == (connection->sk.addr.data = malloc (addrlen)))
{
mhd_LOG_MSG (daemon, MHD_SC_CONNECTION_MALLOC_FAILURE,
"Failed to allocate memory for the new connection");
@@ -187,17 +187,17 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon,
free (connection);
return MHD_SC_CONNECTION_MALLOC_FAILURE;
}
memcpy (connection->addr,
memcpy (connection->sk.addr.data,
addr,
addrlen);
}
else
connection->addr = NULL;
connection->addr_len = addrlen;
connection->socket_fd = client_socket;
connection->sk_nonblck = non_blck;
connection->is_nonip = sk_is_nonip;
connection->sk_spipe_suppress = sk_spipe_supprs;
connection->sk.addr.data = NULL;
connection->sk.addr.size = addrlen;
connection->sk.fd = client_socket;
connection->sk.props.is_nonblck = non_blck;
connection->sk.props.is_nonip = sk_is_nonip;
connection->sk.props.has_spipe_supp = sk_spipe_supprs;
#ifdef MHD_USE_THREADS
mhd_thread_handle_ID_set_invalid (&connection->tid);
#endif /* MHD_USE_THREADS */
@@ -317,7 +317,7 @@ new_connection_process_ (struct MHD_Daemon *restrict daemon,
event.data.ptr = connection;
if (0 != epoll_ctl (daemon->events.data.epoll.e_fd,
EPOLL_CTL_ADD,
connection->socket_fd,
connection->sk.fd,
&event))
{
mhd_LOG_MSG (daemon, MHD_SC_EPOLL_CTL_ADD_FAILED,
@@ -328,7 +328,7 @@ new_connection_process_ (struct MHD_Daemon *restrict daemon,
{
if (0) // TODO: implement turbo
{
connection->sk_ready = mhd_SOCKET_NET_STATE_RECV_READY
connection->sk.ready = mhd_SOCKET_NET_STATE_RECV_READY
| mhd_SOCKET_NET_STATE_SEND_READY;
mhd_conn_mark_ready (connection, daemon);
}
@@ -360,9 +360,9 @@ new_connection_process_ (struct MHD_Daemon *restrict daemon,
// TODO: per IP limit
if (NULL != connection->addr)
free (connection->addr);
(void) mhd_socket_close (connection->socket_fd);
if (NULL != connection->sk.addr.data)
free (connection->sk.addr.data);
(void) mhd_socket_close (connection->sk.fd);
free (connection);
mhd_assert (MHD_SC_OK != res);
return res; /* *** Function failure exit point *** */
@@ -543,8 +543,8 @@ MHD_daemon_add_connection (struct MHD_Daemon *daemon,
return MHD_SC_CONFIGURATION_WRONG_SA_SIZE;
}
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
if ((0 != addr->sa_len) &&
(sizeof(struct sockaddr_in) > (size_t) addr->sa_len) )
if ((0 != sk.addr.data->sa_len) &&
(sizeof(struct sockaddr_in) > (size_t) sk.addr.data->sa_len) )
{
mhd_LOG_MSG (daemon, MHD_SC_CONFIGURATION_WRONG_SA_SIZE, \
"MHD_add_connection() has been called with " \
@@ -567,8 +567,8 @@ MHD_daemon_add_connection (struct MHD_Daemon *daemon,
return MHD_SC_CONFIGURATION_WRONG_SA_SIZE;
}
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
if ((0 != addr->sa_len) &&
(sizeof(struct sockaddr_in6) > (size_t) addr->sa_len) )
if ((0 != sk.addr.data->sa_len) &&
(sizeof(struct sockaddr_in6) > (size_t) sk.addr.data->sa_len) )
{
mhd_LOG_MSG (daemon, MHD_SC_CONFIGURATION_WRONG_SA_SIZE, \
"MHD_add_connection() has been called with " \
@@ -580,9 +580,9 @@ MHD_daemon_add_connection (struct MHD_Daemon *daemon,
#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
}
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
if ((0 != addr->sa_len) &&
(addrlen > (size_t) addr->sa_len))
addrlen = (size_t) addr->sa_len; /* Use safest value */
if ((0 != sk.addr.data->sa_len) &&
(addrlen > (size_t) sk.addr.data->sa_len))
addrlen = (size_t) sk.addr.data->sa_len; /* Use safest value */
#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
#endif /* HAVE_INET6 */
}
@@ -975,9 +975,9 @@ mhd_conn_close_final (struct MHD_Connection *restrict c)
mhd_assert (c != mhd_DLINKEDL_GET_FIRST (&(c->daemon->conns), all_conn));
mhd_assert (c != mhd_DLINKEDL_GET_LAST (&(c->daemon->conns), all_conn));
if (NULL != c->addr)
free (c->addr);
mhd_socket_close (c->socket_fd);
if (NULL != c->sk.addr.data)
free (c->sk.addr.data);
mhd_socket_close (c->sk.fd);
free (c);
}
+8 -8
View File
@@ -101,10 +101,10 @@ update_conn_net_status (struct MHD_Daemon *restrict d,
if (err_state)
sk_state = (enum mhd_SocketNetState)
(sk_state | (unsigned int) mhd_SOCKET_NET_STATE_ERROR_READY);
c->sk_ready = sk_state;
c->sk.ready = sk_state;
if ((0 !=
(((unsigned int) c->sk_ready) & ((unsigned int) c->event_loop_info)
(((unsigned int) c->sk.ready) & ((unsigned int) c->event_loop_info)
& (MHD_EVENT_LOOP_INFO_RECV | MHD_EVENT_LOOP_INFO_SEND)))
|| err_state)
mhd_conn_mark_ready (c, d);
@@ -470,16 +470,16 @@ select_update_fdsets (struct MHD_Daemon *restrict d,
continue;
if (0 != (c->event_loop_info & MHD_EVENT_LOOP_INFO_RECV))
fd_set_wrap (c->socket_fd,
fd_set_wrap (c->sk.fd,
rfds,
&ret,
d);
if (0 != (c->event_loop_info & MHD_EVENT_LOOP_INFO_SEND))
fd_set_wrap (c->socket_fd,
fd_set_wrap (c->sk.fd,
wfds,
&ret,
d);
fd_set_wrap (c->socket_fd,
fd_set_wrap (c->sk.fd,
efds,
&ret,
d);
@@ -575,7 +575,7 @@ select_update_statuses_from_fdsets (struct MHD_Daemon *d,
if (is_conn_excluded_from_http_comm (c))
continue;
sk = c->socket_fd;
sk = c->sk.fd;
recv_ready = FD_ISSET (sk, rfds);
send_ready = FD_ISSET (sk, wfds);
err_state = FD_ISSET (sk, efds);
@@ -737,7 +737,7 @@ poll_update_fds (struct MHD_Daemon *restrict d,
mhd_assert (i_c < d->dbg.num_events_elements);
mhd_assert (MHD_CONNECTION_CLOSED != c->state);
d->events.data.poll.fds[i_c].fd = c->socket_fd;
d->events.data.poll.fds[i_c].fd = c->sk.fd;
d->events.data.poll.rel[i_c].connection = c;
events = 0;
if (0 != (c->event_loop_info & MHD_EVENT_LOOP_INFO_RECV))
@@ -846,7 +846,7 @@ poll_update_statuses_from_fds (struct MHD_Daemon *restrict d,
c = d->events.data.poll.rel[i_c].connection;
mhd_assert (! is_conn_excluded_from_http_comm (c));
mhd_assert (c->socket_fd == d->events.data.poll.fds[i_c].fd);
mhd_assert (c->sk.fd == d->events.data.poll.fds[i_c].fd);
revents = d->events.data.poll.fds[i_c].revents;
recv_ready = (0 != (revents & (MHD_POLL_IN | POLLIN)));
send_ready = (0 != (revents & (MHD_POLL_OUT | POLLOUT)));
+169
View File
@@ -0,0 +1,169 @@
/*
This file is part of GNU libmicrohttpd
Copyright (C) 2024 Evgeny Grin (Karlson2k)
GNU libmicrohttpd is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
GNU libmicrohttpd is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file src/mhd2/mhd_conn_socket.h
* @brief The definition of the connection-specific socket data
* @author Karlson2k (Evgeny Grin)
*/
#ifndef MHD_CONN_SOCKET_H
#define MHD_CONN_SOCKET_H 1
#include "mhd_sys_options.h"
#include "sys_bool_type.h"
#include "mhd_socket_type.h"
#include "mhd_tristate.h"
#include "mhd_socket_error.h"
struct sockaddr_storage; /* Forward declaration */
/**
* The network states for connected sockets
* An internal version of #MHD_FdState. Keep in sync!
*/
enum MHD_FIXED_FLAGS_ENUM_ mhd_SocketNetState
{
/**
* No active states of the socket
*/
mhd_SOCKET_NET_STATE_NOTHING = 0
,
/**
* The socket is ready for receiving
*/
mhd_SOCKET_NET_STATE_RECV_READY = 1 << 0
,
/**
* The socket is ready for sending
*/
mhd_SOCKET_NET_STATE_SEND_READY = 1 << 1
,
/**
* The socket has some unrecoverable error
*/
mhd_SOCKET_NET_STATE_ERROR_READY = 1 << 2
};
/**
* Connection-specific socket state data
*/
struct mhd_ConnSocketState
{
/**
* The current state of TCP_NODELAY socket setting
*/
enum mhd_Tristate nodelay;
// #ifndef MHD_SOCKETS_KIND_WINSOCK // TODO: conditionally use in the code
/**
* The current state of TCP_CORK / TCP_NOPUSH socket setting
*/
enum mhd_Tristate corked;
// #endif
/**
* Set to 'true' when the remote side shut down write/send and
* __the last byte from the remote has been read__.
*/
bool rmt_shut_wr;
/**
* The type of the error when the socket disconnected early
*/
enum mhd_SocketError discnt_err;
};
/**
* Connection-specific socket properties
*/
struct mhd_ConnSocketProperties
{
/**
* The type of the socket: TCP/IP or non TCP/IP (a UNIX domain socket, a pipe)
*/
enum mhd_Tristate is_nonip;
/**
* true if the socket is non-blocking, false otherwise.
*/
bool is_nonblck;
/**
* true if the socket has set SIGPIPE suppression
*/
bool has_spipe_supp;
};
/**
* The connection socket remote address information
*/
struct mhd_ConnSocketAddr
{
/**
* The remote address.
* Allocated by malloc() (not in the connection memory pool!).
* Could be NULL if the address is not known.
*/
struct sockaddr_storage *data;
/**
* The size of the address pointed by @a data.
* Zero is @a data is NULL.
*/
size_t size;
};
/**
* Connection-specific socket data
*/
struct mhd_ConnSocket
{
/**
* The network socket.
*/
MHD_Socket fd;
/**
* Connection-specific socket state data
*/
struct mhd_ConnSocketState state;
/**
* The receive / send / error readiness the socket
*/
enum mhd_SocketNetState ready;
/**
* Connection-specific socket properties
*/
struct mhd_ConnSocketProperties props;
/**
* The connection socket remote address information
*/
struct mhd_ConnSocketAddr addr;
};
#endif /* ! MHD_CONN_SOCKET_H */
+14 -97
View File
@@ -37,7 +37,8 @@
#include "sys_bool_type.h"
#include "sys_base_types.h"
#include "mhd_socket_type.h"
#include "mhd_conn_socket.h"
#include "mhd_threads.h"
@@ -114,81 +115,53 @@ enum MHD_FIXED_FLAGS_ENUM_ MHD_ConnectionEventLoopInfo
/**
* The network states for connected sockets
* An internal version of #MHD_FdState. Keep in sync!
* The reason for the connection closure
*/
enum MHD_FIXED_FLAGS_ENUM_ mhd_SocketNetState
{
/**
* No active states of the socket
*/
mhd_SOCKET_NET_STATE_NOTHING = 0
,
/**
* The socket is ready for receiving
*/
mhd_SOCKET_NET_STATE_RECV_READY = 1 << 0
,
/**
* The socket is ready for sending
*/
mhd_SOCKET_NET_STATE_SEND_READY = 1 << 1
,
/**
* The socket has some unrecoverable error
*/
mhd_SOCKET_NET_STATE_ERROR_READY = 1 << 2
};
/**
* The reason for the socket closure
*/
enum mhd_SocketClosureReason
enum mhd_ConnClosureReason
{
/**
* The socket is not closed / closing.
*/
mhd_SCOKET_CLOSURE_REASON_NO_CLOSURE = 0
mhd_CONN_CLOSURE_REASON_NO_CLOSURE = 0
,
/**
* Socket has to be closed because HTTP protocol successfully finished data
* exchange.
*/
mhd_SCOKET_CLOSURE_REASON_PROTOCOL_SUCCESS
mhd_CONN_CLOSURE_REASON_PROTOCOL_SUCCESS
,
/**
* Socket has to be closed because remote side violated some HTTP
* specification requirements or request processed with an error.
* The HTTP error response should be sent.
*/
mhd_SCOKET_CLOSURE_REASON_PROTOCOL_FAILURE_SOFT
mhd_CONN_CLOSURE_REASON_PROTOCOL_FAILURE_SOFT
,
/**
* Timeout expired
*/
mhd_SCOKET_CLOSURE_REASON_TIMEOUT
mhd_CONN_CLOSURE_REASON_TIMEOUT
,
/**
* Socket has to be closed because received data cannot be interpreted as
* valid HTTP data.
*/
mhd_SCOKET_CLOSURE_REASON_PROTOCOL_FAILURE_HARD
mhd_CONN_CLOSURE_REASON_PROTOCOL_FAILURE_HARD
,
/**
* Unrecoverable TLS error
*/
mhd_SCOKET_CLOSURE_REASON_TLS_ERROR
mhd_CONN_CLOSURE_REASON_TLS_ERROR
,
/**
* The remote side closed connection in abortive way
*/
mhd_SCOKET_CLOSURE_REASON_REMOTE_HARD_DISCONN
mhd_CONN_CLOSURE_REASON_REMOTE_HARD_DISCONN
,
/**
* The connection has been broken for some reason
*/
mhd_SCOKET_CLOSURE_REASON_CONN_BROKEN
mhd_CONN_CLOSURE_REASON_CONN_BROKEN
};
/**
@@ -423,20 +396,9 @@ struct MHD_Connection
mhd_DLNKDL_LINKS (MHD_Connection,all_conn);
/**
* The state of the connected socket
* The connection socket data
*/
enum mhd_SocketNetState sk_ready;
/**
* The type of the error when disconnected early
*/
enum mhd_SocketError sk_discnt_err;
/**
* Set to 'true' when the client shut down write/send and
* __the last byte from the remote has been read__.
*/
bool sk_rmt_shut_wr;
struct mhd_ConnSocket sk;
/**
* 'true' if connection is in 'process ready' list,
@@ -530,12 +492,6 @@ struct MHD_Connection
*/
char *write_buffer;
/**
* Foreign address (of length @e addr_len). MALLOCED (not
* in pool!).
*/
struct sockaddr_storage *addr;
#if defined(MHD_USE_THREADS)
/**
* Thread handle for this connection (if we are using
@@ -579,11 +535,6 @@ struct MHD_Connection
*/
size_t continue_message_write_offset;
/**
* Length of the foreign address.
*/
size_t addr_len;
/**
* Last time this connection had any activity
* (reading or writing).
@@ -597,40 +548,6 @@ struct MHD_Connection
*/
uint_fast64_t connection_timeout_ms;
/**
* Socket for this connection. Set to #MHD_INVALID_SOCKET if
* this connection has died (daemon should clean
* up in that case).
*/
MHD_Socket socket_fd;
/**
* The type of the socket: TCP/IP or non TCP/IP (a UNIX domain socket, a pipe)
*/
enum mhd_Tristate is_nonip;
/**
* true if @a socket_fd is non-blocking, false otherwise.
*/
bool sk_nonblck;
/**
* true if connection socket has set SIGPIPE suppression
*/
bool sk_spipe_suppress;
// #ifndef MHD_SOCKETS_KIND_WINSOCK // TODO: conditionally use in the code
/**
* Tracks TCP_CORK / TCP_NOPUSH of the connection socket.
*/
enum mhd_Tristate sk_corked;
// #endif
/**
* Tracks TCP_NODELAY state of the connection socket.
*/
enum mhd_Tristate sk_nodelay;
/**
* Some error happens during processing the connection therefore this
* connection must be closed.
+6 -6
View File
@@ -52,13 +52,13 @@ mhd_plain_recv (struct MHD_Connection *restrict c,
if (MHD_SCKT_SEND_MAX_SIZE_ < buf_size)
buf_size = MHD_SCKT_SEND_MAX_SIZE_;
res = mhd_sys_recv (c->socket_fd, buf, buf_size);
res = mhd_sys_recv (c->sk.fd, buf, buf_size);
if (0 <= res)
{
*received = (size_t) res;
if (buf_size > (size_t) res)
c->sk_ready = (enum mhd_SocketNetState) /* Clear 'recv-ready' */
(((unsigned int) c->sk_ready)
c->sk.ready = (enum mhd_SocketNetState) /* Clear 'recv-ready' */
(((unsigned int) c->sk.ready)
& (~(enum mhd_SocketNetState)
mhd_SOCKET_NET_STATE_RECV_READY));
return mhd_SOCKET_ERR_NO_ERROR; /* Success exit point */
@@ -67,8 +67,8 @@ mhd_plain_recv (struct MHD_Connection *restrict c,
err = mhd_socket_error_get_from_sys_err (mhd_SCKT_GET_LERR ());
if (mhd_SOCKET_ERR_AGAIN == err)
c->sk_ready = (enum mhd_SocketNetState) /* Clear 'recv-ready' */
(((unsigned int) c->sk_ready)
c->sk.ready = (enum mhd_SocketNetState) /* Clear 'recv-ready' */
(((unsigned int) c->sk.ready)
& (~(enum mhd_SocketNetState)
mhd_SOCKET_NET_STATE_RECV_READY));
@@ -83,7 +83,7 @@ mhd_recv (struct MHD_Connection *restrict c,
char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)],
size_t *restrict received)
{
mhd_assert (MHD_INVALID_SOCKET != c->socket_fd);
mhd_assert (MHD_INVALID_SOCKET != c->sk.fd);
mhd_assert (MHD_CONNECTION_CLOSED != c->state);
// TODO: implement TLS support
+1 -1
View File
@@ -36,7 +36,7 @@ struct MHD_Connection; /* forward declaration */
/**
* Receive the data from the network socket.
* Clear #mhd_SOCKET_NET_STATE_RECV_READY in sk_ready if necessary.
* Clear #mhd_SOCKET_NET_STATE_RECV_READY in sk.ready if necessary.
*
* @param c the connection to use
* @param buf_size the size of the @a buf buffer
+67 -67
View File
@@ -198,26 +198,26 @@ mhd_connection_set_nodelay_state (struct MHD_Connection *connection,
static const mhd_SCKT_OPT_BOOL on_val = 1;
int err_code;
if (mhd_T_IS_YES (connection->is_nonip))
if (mhd_T_IS_YES (connection->sk.props.is_nonip))
return false;
if (0 == setsockopt (connection->socket_fd,
if (0 == setsockopt (connection->sk.fd,
IPPROTO_TCP,
TCP_NODELAY,
(const void *) (nodelay_state ? &on_val : &off_val),
sizeof (off_val)))
{
connection->sk_nodelay = nodelay_state ? mhd_T_YES : mhd_T_NO;
connection->sk.state.nodelay = nodelay_state ? mhd_T_YES : mhd_T_NO;
return true;
}
err_code = mhd_SCKT_GET_LERR ();
if ((mhd_T_IS_NOT_YES (connection->is_nonip)) &&
if ((mhd_T_IS_NOT_YES (connection->sk.props.is_nonip)) &&
(mhd_SCKT_ERR_IS_EINVAL (err_code) ||
mhd_SCKT_ERR_IS_NOPROTOOPT (err_code) ||
mhd_SCKT_ERR_IS_NOTSOCK (err_code)))
{
connection->is_nonip = mhd_T_YES;
connection->sk.props.is_nonip = mhd_T_YES;
}
else
{
@@ -226,7 +226,7 @@ mhd_connection_set_nodelay_state (struct MHD_Connection *connection,
}
#else /* ! TCP_NODELAY */
(void) nodelay_state; /* Mute compiler warnings */
connection->sk_nodelay = mhd_T_NO;
connection->sk.state.nodelay = mhd_T_NO;
#endif /* ! TCP_NODELAY */
return false;
}
@@ -241,26 +241,26 @@ mhd_connection_set_cork_state (struct MHD_Connection *connection,
static const mhd_SCKT_OPT_BOOL on_val = 1;
int err_code;
if (mhd_T_IS_YES (connection->is_nonip))
if (mhd_T_IS_YES (connection->sk.props.is_nonip))
return false;
if (0 == setsockopt (connection->socket_fd,
if (0 == setsockopt (connection->sk.fd,
IPPROTO_TCP,
mhd_TCP_CORK_NOPUSH,
(const void *) (cork_state ? &on_val : &off_val),
sizeof (off_val)))
{
connection->sk_corked = cork_state ? mhd_T_YES : mhd_T_NO;
connection->sk.state.corked = cork_state ? mhd_T_YES : mhd_T_NO;
return true;
}
err_code = mhd_SCKT_GET_LERR ();
if ((mhd_T_IS_NOT_YES (connection->is_nonip)) &&
if ((mhd_T_IS_NOT_YES (connection->sk.props.is_nonip)) &&
(mhd_SCKT_ERR_IS_EINVAL (err_code) ||
mhd_SCKT_ERR_IS_NOPROTOOPT (err_code) ||
mhd_SCKT_ERR_IS_NOTSOCK (err_code)))
{
connection->is_nonip = mhd_T_YES;
connection->sk.props.is_nonip = mhd_T_YES;
}
else
{
@@ -275,7 +275,7 @@ mhd_connection_set_cork_state (struct MHD_Connection *connection,
#else /* ! mhd_TCP_CORK_NOPUSH */
(void) cork_state; /* Mute compiler warnings. */
connection->sk_corked = mhd_T_NO;
connection->sk.state.corked = mhd_T_NO;
#endif /* ! mhd_TCP_CORK_NOPUSH */
return false;
}
@@ -300,7 +300,7 @@ pre_send_setopt (struct MHD_Connection *connection,
* Final piece is indicated by push_data == true. */
const bool buffer_data = (! push_data);
if (mhd_T_IS_YES (connection->is_nonip))
if (mhd_T_IS_YES (connection->sk.props.is_nonip))
return;
// TODO: support inheriting of TCP_NODELAY and TCP_NOPUSH
@@ -322,7 +322,7 @@ pre_send_setopt (struct MHD_Connection *connection,
#endif /* ! mhd_USE_MSG_MORE */
#ifdef mhd_TCP_CORK_NOPUSH
if (mhd_T_IS_YES (connection->sk_corked))
if (mhd_T_IS_YES (connection->sk.state.corked))
return; /* The connection was already corked. */
/* Prefer 'cork' over 'no delay' as the 'cork' buffers better, regardless
@@ -333,7 +333,7 @@ pre_send_setopt (struct MHD_Connection *connection,
/* Failed to cork the connection.
* Really unlikely to happen on TCP connections. */
#endif /* mhd_TCP_CORK_NOPUSH */
if (mhd_T_IS_NO (connection->sk_nodelay))
if (mhd_T_IS_NO (connection->sk.state.nodelay))
return; /* TCP_NODELAY was not set for the socket.
* Nagle's algorithm will buffer some data. */
@@ -397,17 +397,17 @@ pre_send_setopt (struct MHD_Connection *connection,
/* This is typical modern FreeBSD and OpenBSD behaviour. */
# endif /* ! mhd_NODELAY_SET_PUSH_DATA */
if (mhd_T_IS_YES (connection->sk_corked))
if (mhd_T_IS_YES (connection->sk.state.corked))
return; /* Socket is corked. Data can be pushed by resetting of
* TCP_CORK / TCP_NOPUSH after send() */
else if (mhd_T_IS_NO (connection->sk_corked))
else if (mhd_T_IS_NO (connection->sk.state.corked))
{
/* The socket is not corked. */
if (mhd_T_IS_YES (connection->sk_nodelay))
if (mhd_T_IS_YES (connection->sk.state.nodelay))
return; /* TCP_NODELAY was already set,
* data will be pushed automatically by the next send() */
# ifdef mhd_NODELAY_SET_PUSH_DATA
else if (mhd_T_IS_MAYBE (connection->sk_nodelay))
else if (mhd_T_IS_MAYBE (connection->sk.state.nodelay))
{
/* Setting TCP_NODELAY may push data NOW.
* Cork socket here and uncork after send(). */
@@ -470,7 +470,7 @@ pre_send_setopt (struct MHD_Connection *connection,
* TCP_CORK / TCP_NOPUSH after send() */
/* The socket cannot be corked.
* Really unlikely to happen on TCP connections */
if (mhd_T_IS_YES (connection->sk_nodelay))
if (mhd_T_IS_YES (connection->sk.state.nodelay))
return; /* TCP_NODELAY was already set,
* data will be pushed by the next send() */
@@ -499,11 +499,11 @@ pre_send_setopt (struct MHD_Connection *connection,
/* This is old FreeBSD and Darwin behaviour. */
/* Uncork socket if socket wasn't uncorked. */
if (mhd_T_IS_NOT_NO (connection->sk_corked))
if (mhd_T_IS_NOT_NO (connection->sk.state.corked))
mhd_connection_set_cork_state (connection, false);
/* Set TCP_NODELAY if it wasn't set. */
if (mhd_T_IS_NOT_YES (connection->sk_nodelay))
if (mhd_T_IS_NOT_YES (connection->sk.state.nodelay))
mhd_connection_set_nodelay_state (connection, true);
return;
@@ -525,7 +525,7 @@ pre_send_setopt (struct MHD_Connection *connection,
/* Buffering of data is controlled only by
* Nagel's algorithm. */
/* Set TCP_NODELAY if it wasn't set. */
if (mhd_T_IS_NOT_YES (connection->sk_nodelay))
if (mhd_T_IS_NOT_YES (connection->sk.state.nodelay))
mhd_connection_set_nodelay_state (connection, true);
#endif /* ! mhd_TCP_CORK_NOPUSH */
}
@@ -548,11 +548,11 @@ zero_send (struct MHD_Connection *connection)
{
static const int dummy = 0;
if (mhd_T_IS_YES (connection->is_nonip))
if (mhd_T_IS_YES (connection->sk.props.is_nonip))
return false;
mhd_assert (mhd_T_IS_NO (connection->sk_corked));
mhd_assert (mhd_T_IS_YES (connection->sk_nodelay));
if (0 == mhd_sys_send (connection->socket_fd, &dummy, 0))
mhd_assert (mhd_T_IS_NO (connection->sk.state.corked));
mhd_assert (mhd_T_IS_YES (connection->sk.state.nodelay));
if (0 == mhd_sys_send (connection->sk.fd, &dummy, 0))
return true;
mhd_LOG_MSG (connection->daemon, MHD_SC_SOCKET_ZERO_SEND_FAILED, \
"Failed to push the data by zero-sized send.");
@@ -581,7 +581,7 @@ post_send_setopt (struct MHD_Connection *connection,
* Final piece is indicated by push_data == true. */
const bool buffer_data = (! push_data);
if (mhd_T_IS_YES (connection->is_nonip))
if (mhd_T_IS_YES (connection->sk.props.is_nonip))
return;
if (buffer_data)
return; /* Nothing to do after the send(). */
@@ -592,8 +592,8 @@ post_send_setopt (struct MHD_Connection *connection,
/* Need to push data. */
#ifdef mhd_TCP_CORK_NOPUSH
if (mhd_T_IS_YES (connection->sk_nodelay) && \
mhd_T_IS_NO (connection->sk_corked))
if (mhd_T_IS_YES (connection->sk.state.nodelay) && \
mhd_T_IS_NO (connection->sk.state.corked))
return; /* Data has been already pushed by last send(). */
# ifdef mhd_CORK_RESET_PUSH_DATA_ALWAYS
@@ -620,7 +620,7 @@ post_send_setopt (struct MHD_Connection *connection,
* resetting of TCP_CORK so next final send without MSG_MORE will push
* data to the network (without additional sys-call to push data). */
if (mhd_T_IS_NOT_YES (connection->sk_nodelay) ||
if (mhd_T_IS_NOT_YES (connection->sk.state.nodelay) ||
(! plain_send_next))
{
if (mhd_connection_set_nodelay_state (connection, true))
@@ -672,9 +672,9 @@ post_send_setopt (struct MHD_Connection *connection,
# else /* ! mhd_CORK_RESET_PUSH_DATA_ALWAYS */
/* This is old FreeBSD or Darwin kernel. */
if (mhd_T_IS_NO (connection->sk_corked))
if (mhd_T_IS_NO (connection->sk.state.corked))
{
mhd_assert (mhd_T_IS_NOT_YES (connection->sk_nodelay));
mhd_assert (mhd_T_IS_NOT_YES (connection->sk.state.nodelay));
/* Unlikely to reach this code.
* TCP_NODELAY should be turned on before send(). */
@@ -692,7 +692,7 @@ post_send_setopt (struct MHD_Connection *connection,
else
{
#ifdef mhd_CORK_RESET_PUSH_DATA
enum mhd_Tristate old_cork_state = connection->sk_corked;
enum mhd_Tristate old_cork_state = connection->sk.state.corked;
#endif /* mhd_CORK_RESET_PUSH_DATA */
/* The socket is corked or cork state is unknown. */
@@ -707,7 +707,7 @@ post_send_setopt (struct MHD_Connection *connection,
/* Unlikely to reach this code.
* The data should be pushed by uncorking (FreeBSD) or
* the socket should be uncorked before send(). */
if (mhd_T_IS_YES (connection->sk_nodelay) ||
if (mhd_T_IS_YES (connection->sk.state.nodelay) ||
(mhd_connection_set_nodelay_state (connection, true)))
{
/* TCP_NODELAY is turned ON on uncorked socket.
@@ -722,8 +722,8 @@ post_send_setopt (struct MHD_Connection *connection,
#else /* ! mhd_TCP_CORK_NOPUSH */
/* Corking is not supported. Buffering is controlled
* by TCP_NODELAY only. */
mhd_assert (mhd_T_IS_NOT_YES (connection->sk_corked));
if (mhd_T_IS_YES (connection->sk_nodelay))
mhd_assert (mhd_T_IS_NOT_YES (connection->sk.state.corked));
if (mhd_T_IS_YES (connection->sk.state.nodelay))
return; /* Data was already pushed by send(). */
/* Unlikely to reach this code.
@@ -768,12 +768,12 @@ mhd_plain_send (struct MHD_Connection *restrict c,
pre_send_setopt (c, true, push_data);
#ifdef mhd_USE_MSG_MORE
res = mhd_sys_send4 (c->socket_fd,
res = mhd_sys_send4 (c->sk.fd,
buf,
buf_size,
push_data ? 0 : MSG_MORE);
#else
res = mhd_sys_send4 (c->socket_fd,
res = mhd_sys_send4 (c->sk.fd,
buf,
buf_size,
0);
@@ -786,8 +786,8 @@ mhd_plain_send (struct MHD_Connection *restrict c,
err = mhd_socket_error_get_from_sys_err (mhd_SCKT_GET_LERR ());
if (mhd_SOCKET_ERR_AGAIN == err)
c->sk_ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) c->sk_ready)
c->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) c->sk.ready)
& (~(enum mhd_SocketNetState)
mhd_SOCKET_NET_STATE_SEND_READY));
@@ -798,8 +798,8 @@ mhd_plain_send (struct MHD_Connection *restrict c,
full_buf_sent = (buf_size == (size_t) res);
if (! full_buf_sent)
c->sk_ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) c->sk_ready)
c->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) c->sk.ready)
& (~(enum mhd_SocketNetState)
mhd_SOCKET_NET_STATE_SEND_READY));
@@ -826,7 +826,7 @@ mhd_send_data (struct MHD_Connection *restrict connection,
{
const bool tls_conn = false; // TODO: TLS support
mhd_assert (MHD_INVALID_SOCKET != connection->socket_fd);
mhd_assert (MHD_INVALID_SOCKET != connection->sk.fd);
mhd_assert (MHD_CONNECTION_CLOSED != connection->state);
if (tls_conn)
@@ -869,7 +869,7 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection,
bool send_error;
bool push_hdr;
bool push_body;
MHD_Socket s = connection->socket_fd;
MHD_Socket s = connection->sk.fd;
#ifdef mhd_USE_VECT_SEND
#if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV)
struct iovec vector[2];
@@ -891,7 +891,7 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection,
defined(mhd_SEND_SPIPE_SUPPRESS_POSSIBLE) && \
defined(mhd_SEND_SPIPE_SUPPRESS_NEEDED)
no_vec = no_vec || (! connection->daemon->sigpipe_blocked &&
! connection->sk_spipe_suppress);
! connection->sk.props.has_spipe_supp);
#endif /* (!HAVE_SENDMSG || ! MSG_NOSIGNAL) &&
mhd_SEND_SPIPE_SUPPRESS_POSSIBLE &&
mhd_SEND_SPIPE_SUPPRESS_NEEDED */
@@ -951,7 +951,7 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection,
(header_size == *sent) &&
(0 != body_size) &&
(header_size < header_size + body_size) &&
(connection->sk_nonblck))
(connection->sk.props.is_nonblck))
{
size_t sent_b;
/* The header has been sent completely.
@@ -1053,16 +1053,16 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection,
err = mhd_socket_error_get_from_sys_err (mhd_SCKT_GET_LERR ());
if (mhd_SOCKET_ERR_AGAIN == err)
connection->sk_ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) connection->sk_ready)
connection->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) connection->sk.ready)
& (~(enum mhd_SocketNetState)
mhd_SOCKET_NET_STATE_SEND_READY));
return err;
}
if ((header_size + body_size) > *sent)
connection->sk_ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) connection->sk_ready)
connection->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) connection->sk.ready)
& (~(enum mhd_SocketNetState)
mhd_SOCKET_NET_STATE_SEND_READY));
@@ -1178,12 +1178,12 @@ mhd_send_sendfile (struct MHD_Connection *restrict c,
{
ssize_t res;
#ifndef HAVE_SENDFILE64
ret = sendfile (c->socket_fd,
ret = sendfile (c->sk.fd,
file_fd,
&offset,
send_size);
#else /* HAVE_SENDFILE64 */
res = sendfile64 (c->socket_fd,
res = sendfile64 (c->sk.fd,
file_fd,
&offset,
send_size);
@@ -1219,7 +1219,7 @@ mhd_send_sendfile (struct MHD_Connection *restrict c,
freebsd_sendfile_flags_thd_p_c_ : freebsd_sendfile_flags_;
#endif /* SF_FLAGS */
if (0 != sendfile (file_fd,
c->socket_fd,
c->sk.fd,
offset,
send_size,
NULL,
@@ -1263,7 +1263,7 @@ mhd_send_sendfile (struct MHD_Connection *restrict c,
len = (off_t) send_size; /* chunk always fit */
if (0 != sendfile (file_fd,
c->socket_fd,
c->sk.fd,
offset,
&len,
NULL,
@@ -1312,8 +1312,8 @@ mhd_send_sendfile (struct MHD_Connection *restrict c,
if ((mhd_SOCKET_ERR_AGAIN == ret) ||
((mhd_SOCKET_ERR_NO_ERROR == ret) && (send_size > sent_bytes)))
c->sk_ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) c->sk_ready)
c->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) c->sk.ready)
& (~(enum mhd_SocketNetState)
mhd_SOCKET_NET_STATE_SEND_READY));
@@ -1374,7 +1374,7 @@ send_iov_nontls (struct MHD_Connection *restrict connection,
// TODO: assert for non-TLS
mhd_assert (MHD_INVALID_SOCKET != connection->socket_fd);
mhd_assert (MHD_INVALID_SOCKET != connection->sk.fd);
mhd_assert (MHD_CONNECTION_CLOSED != connection->state);
send_error = false;
@@ -1400,7 +1400,7 @@ send_iov_nontls (struct MHD_Connection *restrict connection,
msg.msg_flags = 0;
pre_send_setopt (connection, true, push_data);
res = sendmsg (connection->socket_fd, &msg,
res = sendmsg (connection->sk.fd, &msg,
mhd_MSG_NOSIGNAL | (push_data ? 0 : mhd_MSG_MORE));
if (0 < res)
*sent = (size_t) res;
@@ -1408,7 +1408,7 @@ send_iov_nontls (struct MHD_Connection *restrict connection,
send_error = true;
#elif defined(HAVE_WRITEV)
pre_send_setopt (connection, false, push_data);
res = writev (connection->socket_fd, r_iov->iov + r_iov->sent,
res = writev (connection->sk.fd, r_iov->iov + r_iov->sent,
items_to_send);
if (0 < res)
*sent = (size_t) res;
@@ -1427,7 +1427,7 @@ send_iov_nontls (struct MHD_Connection *restrict connection,
cnt_w = (DWORD) items_to_send;
#endif /* ! _WIN64 */
pre_send_setopt (connection, true, push_data);
if (0 == WSASend (connection->socket_fd,
if (0 == WSASend (connection->sk.fd,
(LPWSABUF) (r_iov->iov + r_iov->sent),
cnt_w,
&bytes_sent, 0, NULL, NULL))
@@ -1445,8 +1445,8 @@ send_iov_nontls (struct MHD_Connection *restrict connection,
err = mhd_socket_error_get_from_sys_err (mhd_SCKT_GET_LERR ());
if (mhd_SOCKET_ERR_AGAIN == err)
connection->sk_ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) connection->sk_ready)
connection->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) connection->sk.ready)
& (~(enum mhd_SocketNetState)
mhd_SOCKET_NET_STATE_SEND_READY));
@@ -1470,8 +1470,8 @@ send_iov_nontls (struct MHD_Connection *restrict connection,
post_send_setopt (connection, true, push_data);
else
{
connection->sk_ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) connection->sk_ready)
connection->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */
(((unsigned int) connection->sk.ready)
& (~(enum mhd_SocketNetState)
mhd_SOCKET_NET_STATE_SEND_READY));
if (0 != track_sent)
@@ -1518,7 +1518,7 @@ send_iov_emu (struct MHD_Connection *restrict connection,
bool push_data,
size_t *restrict sent)
{
const bool non_blk = connection->sk_nonblck;
const bool non_blk = connection->sk.props.is_nonblck;
size_t total_sent;
size_t max_elelements_to_sent;
@@ -1603,7 +1603,7 @@ mhd_send_iovec (struct MHD_Connection *restrict connection,
#endif /* HTTPS_SUPPORT */
#ifdef mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED
use_iov_send = use_iov_send && (connection->daemon->sigpipe_blocked ||
connection->sk_spipe_suppress);
connection->sk.props.has_spipe_supp);
#endif /* mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED */
if (use_iov_send)
#endif /* HTTPS_SUPPORT || mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED */
+2 -2
View File
@@ -144,7 +144,7 @@ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (4);
/**
* Set required TCP_NODELAY state for connection socket
*
* The function automatically updates sk_nodelay state.
* The function automatically updates sk.nodelay state.
* @param connection the connection to manipulate
* @param nodelay_state the requested new state of socket
* @return true if succeed, false if failed or not supported
@@ -159,7 +159,7 @@ MHD_FN_PAR_NONNULL_ALL_;
/**
* Set required cork state for connection socket
*
* The function automatically updates sk_corked state.
* The function automatically updates sk.corked state.
*
* @param connection the connection to manipulate
* @param cork_state the requested new state of socket
+4 -4
View File
@@ -726,7 +726,7 @@ mhd_conn_start_closing (struct MHD_Connection *restrict c,
break;
case mhd_CONN_CLOSE_SOCKET_ERR:
close_hard = true;
switch (c->sk_discnt_err)
switch (c->sk.state.discnt_err)
{
case mhd_SOCKET_ERR_NOMEM:
end_code = MHD_REQUEST_ENDED_NO_RESOURCES;
@@ -816,13 +816,13 @@ mhd_conn_start_closing (struct MHD_Connection *restrict c,
if (close_hard)
{
/* Use abortive closing, send RST to remote to indicate a problem */
(void) mhd_socket_set_hard_close (c->socket_fd);
(void) mhd_socket_set_hard_close (c->sk.fd);
c->state = MHD_CONNECTION_PRE_CLOSING;
c->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP;
}
else
{
if (mhd_socket_shut_wr (c->socket_fd) && (! c->sk_rmt_shut_wr))
if (mhd_socket_shut_wr (c->sk.fd) && (! c->sk.state.rmt_shut_wr))
{
(void) 0; // TODO: start local lingering phase
c->state = MHD_CONNECTION_PRE_CLOSING; // TODO: start local lingering phase
@@ -893,7 +893,7 @@ mhd_conn_pre_clean_part1 (struct MHD_Connection *restrict c)
event.data.ptr = NULL;
if (0 != epoll_ctl (c->daemon->events.data.epoll.e_fd,
EPOLL_CTL_DEL,
c->socket_fd,
c->sk.fd,
&event))
{
mhd_LOG_MSG (c->daemon, MHD_SC_EPOLL_CTL_REMOVE_FAILED,
+1 -1
View File
@@ -136,7 +136,7 @@ get_conn_reuse (struct MHD_Connection *c)
return mhd_CONN_MUST_CLOSE;
mhd_assert ( (! c->stop_with_error) || (c->discard_request));
if ((c->sk_rmt_shut_wr) || (c->discard_request))
if ((c->sk.state.rmt_shut_wr) || (c->discard_request))
return mhd_CONN_MUST_CLOSE;
if (rp->cfg.close_forced)
+13 -13
View File
@@ -66,7 +66,7 @@ update_active_state (struct MHD_Connection *restrict c)
/* Do not update states of suspended connection */
mhd_assert (! c->suspended);
if (0 != (c->sk_ready & mhd_SOCKET_NET_STATE_ERROR_READY))
if (0 != (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY))
{
mhd_assert (0 && "Should be handled earlier");
mhd_conn_start_closing_skt_err (c);
@@ -208,10 +208,10 @@ update_active_state (struct MHD_Connection *restrict c)
mhd_assert (MHD_EVENT_LOOP_INFO_PROCESS != c->event_loop_info);
/* Sockets errors must be already handled */
mhd_assert (0 == (c->sk_ready & mhd_SOCKET_NET_STATE_ERROR_READY));
mhd_assert (0 == (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY));
if (0 !=
(((unsigned int) c->sk_ready) & ((unsigned int) c->event_loop_info)
(((unsigned int) c->sk.ready) & ((unsigned int) c->event_loop_info)
& (MHD_EVENT_LOOP_INFO_RECV | MHD_EVENT_LOOP_INFO_SEND)))
mhd_conn_mark_ready (c, c->daemon);
else
@@ -230,7 +230,7 @@ mhd_conn_process_data (struct MHD_Connection *restrict c)
/* 'daemon' is not used if epoll is not available and asserts are disabled */
(void) d; /* Mute compiler warning */
if ((c->sk_rmt_shut_wr) && (MHD_CONNECTION_START_REPLY > c->state))
if ((c->sk.state.rmt_shut_wr) && (MHD_CONNECTION_START_REPLY > c->state))
{
if (0 == c->read_buffer_offset)
{ /* Read buffer is empty, connection state is actual */
@@ -251,14 +251,14 @@ mhd_conn_process_data (struct MHD_Connection *restrict c)
(void) 0;
}
if ((mhd_SOCKET_ERR_NO_ERROR != c->sk_discnt_err) ||
(0 != (c->sk_ready & mhd_SOCKET_NET_STATE_ERROR_READY)))
if ((mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err) ||
(0 != (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY)))
{
mhd_assert ((mhd_SOCKET_ERR_NO_ERROR == c->sk_discnt_err) || \
mhd_SOCKET_ERR_IS_HARD (c->sk_discnt_err));
if ((mhd_SOCKET_ERR_NO_ERROR == c->sk_discnt_err) ||
(mhd_SOCKET_ERR_NOT_CHECKED == c->sk_discnt_err))
c->sk_discnt_err = mhd_socket_error_get_from_socket (c->socket_fd);
mhd_assert ((mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err) || \
mhd_SOCKET_ERR_IS_HARD (c->sk.state.discnt_err));
if ((mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err) ||
(mhd_SOCKET_ERR_NOT_CHECKED == c->sk.state.discnt_err))
c->sk.state.discnt_err = mhd_socket_error_get_from_socket (c->sk.fd);
mhd_conn_start_closing_skt_err (c);
return false;
}
@@ -459,7 +459,7 @@ mhd_conn_process_data (struct MHD_Connection *restrict c)
c,
mhd_CONN_KEEPALIVE_POSSIBLE == c->conn_reuse
&& ! c->discard_request
&& ! c->sk_rmt_shut_wr);
&& ! c->sk.state.rmt_shut_wr);
continue;
#ifdef MHD_UPGRADE_SUPPORT
case MHD_CONNECTION_UPGRADING:
@@ -506,7 +506,7 @@ mhd_conn_process_data (struct MHD_Connection *restrict c)
return true;
}
if ((c->sk_rmt_shut_wr) && (MHD_CONNECTION_START_REPLY > c->state))
if ((c->sk.state.rmt_shut_wr) && (MHD_CONNECTION_START_REPLY > c->state))
{
mhd_conn_start_closing (c,
(MHD_CONNECTION_INIT == c->state) ?
+10 -10
View File
@@ -110,7 +110,7 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh,
{
struct MHD_Connection *restrict c = urh->c;
#if defined(MHD_USE_POLL) || defined(MHD_USE_SELECT)
const MHD_Socket socket_fd = c->socket_fd;
const MHD_Socket socket_fd = c->sk.fd;
#endif /* MHD_USE_POLL || MHD_USE_SELECT */
char *restrict buf_char = (char *) recv_buf;
size_t last_block_size;
@@ -167,7 +167,7 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh,
if (mhd_SOCKET_ERR_NO_ERROR == res)
{
if (0 == last_block_size)
c->sk_rmt_shut_wr = true;
c->sk.state.rmt_shut_wr = true;
*received_size += last_block_size;
return MHD_SC_OK;
}
@@ -220,7 +220,7 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh,
# if defined(MHD_USE_SELECT)
bool use_select;
# ifdef MHD_SOCKETS_KIND_POSIX
use_select = (socket_fd < FD_SETSIZE);
use_select = (sk.fd < FD_SETSIZE);
# else /* MHD_SOCKETS_KIND_WINSOCK */
use_select = true;
# endif /* MHD_SOCKETS_KIND_WINSOCK */
@@ -245,9 +245,9 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh,
else
tmvl.tv_usec = (int) (max_wait_millisec % 1000);
FD_ZERO (&rfds);
FD_SET (socket_fd, &rfds);
FD_SET (sk.fd, &rfds);
sel_res = select (c->socket_fd + 1,
sel_res = select (c->sk.fd + 1,
&rfds,
NULL,
NULL,
@@ -295,7 +295,7 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh,
if (mhd_SOCKET_ERR_NO_ERROR == res)
{
if (0 == last_block_size)
c->sk_rmt_shut_wr = true;
c->sk.state.rmt_shut_wr = true;
*received_size += last_block_size;
return MHD_SC_OK;
}
@@ -327,7 +327,7 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh,
{
struct MHD_Connection *restrict c = urh->c;
#if defined(MHD_USE_POLL) || defined(MHD_USE_SELECT)
const MHD_Socket socket_fd = c->socket_fd;
const MHD_Socket socket_fd = c->sk.fd;
#endif /* MHD_USE_POLL || MHD_USE_SELECT */
const char *restrict buf_char = (const char *) send_buf;
const bool push_data = (MHD_NO == more_data_to_come);
@@ -452,7 +452,7 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh,
#else /* ! MHD_USE_POLL */
# if defined(MHD_USE_SELECT)
# ifdef MHD_SOCKETS_KIND_POSIX
use_select = (socket_fd < FD_SETSIZE);
use_select = (sk.fd < FD_SETSIZE);
# else /* MHD_SOCKETS_KIND_WINSOCK */
use_select = true;
# endif /* MHD_SOCKETS_KIND_WINSOCK */
@@ -488,9 +488,9 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh,
tmvl.tv_usec = (int) (max_wait_millisec % 1000);
}
FD_ZERO (&wfds);
FD_SET (socket_fd, &wfds);
FD_SET (sk.fd, &wfds);
sel_res = select (c->socket_fd + 1,
sel_res = select (c->sk.fd + 1,
NULL,
&wfds,
NULL,