From c9e0d7be942004aea8fb2b3ae2e18bc9d0ea4b98 Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Tue, 1 Apr 2025 07:53:44 +0300 Subject: [PATCH] Clear send/recv-ready flags when using blocking sockets --- src/mhd2/mhd_recv.c | 8 +++++++- src/mhd2/mhd_send.c | 20 +++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/mhd2/mhd_recv.c b/src/mhd2/mhd_recv.c index a23da765..d6205e36 100644 --- a/src/mhd2/mhd_recv.c +++ b/src/mhd2/mhd_recv.c @@ -61,7 +61,8 @@ mhd_recv_plain (struct MHD_Connection *restrict c, if (0 <= res) { *received = (size_t) res; - if (buf_size > (size_t) res) + if ((buf_size > (size_t) res) + || ! c->sk.props.is_nonblck) c->sk.ready = (enum mhd_SocketNetState) /* Clear 'recv-ready' */ (((unsigned int) c->sk.ready) & (~(enum mhd_SocketNetState) @@ -109,6 +110,11 @@ mhd_recv_tls (struct MHD_Connection *restrict c, mhd_SOCKET_NET_STATE_RECV_READY)); else if (mhd_SOCKET_ERR_NO_ERROR == res) { + if (! c->sk.props.is_nonblck) + c->sk.ready = (enum mhd_SocketNetState) /* Clear 'recv-ready' */ + (((unsigned int) c->sk.ready) + & (~(enum mhd_SocketNetState) + mhd_SOCKET_NET_STATE_RECV_READY)); if (res == buf_size) { if (mhd_tls_conn_has_data_in (c->tls)) diff --git a/src/mhd2/mhd_send.c b/src/mhd2/mhd_send.c index 67b289a6..d7ec2ef5 100644 --- a/src/mhd2/mhd_send.c +++ b/src/mhd2/mhd_send.c @@ -805,7 +805,7 @@ mhd_send_plain (struct MHD_Connection *restrict c, full_buf_sent = (buf_size == (size_t) res); - if (! full_buf_sent) + if (! full_buf_sent || ! c->sk.props.is_nonblck) c->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ (((unsigned int) c->sk.ready) & (~(enum mhd_SocketNetState) @@ -858,6 +858,12 @@ mhd_send_tls (struct MHD_Connection *restrict c, return res; } + if (! c->sk.props.is_nonblck) + c->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ + (((unsigned int) c->sk.ready) + & (~(enum mhd_SocketNetState) + mhd_SOCKET_NET_STATE_SEND_READY)); + /* If there is a need to push the data from network buffers * call post_send_setopt(). */ if (push_data && (buf_size == *sent)) @@ -1104,7 +1110,8 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, return err; } - if ((header_size + body_size) > *sent) + if (((header_size + body_size) > *sent) + || ! connection->sk.props.is_nonblck) connection->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ (((unsigned int) connection->sk.ready) & (~(enum mhd_SocketNetState) @@ -1354,7 +1361,7 @@ mhd_send_sendfile (struct MHD_Connection *restrict c, return mhd_SOCKET_ERR_INTR; } - if ((mhd_SOCKET_ERR_AGAIN == ret) || + if ((mhd_SOCKET_ERR_AGAIN == ret) || ! c->sk.props.is_nonblck || ((mhd_SOCKET_ERR_NO_ERROR == ret) && (send_size > sent_bytes))) c->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ (((unsigned int) c->sk.ready) @@ -1502,6 +1509,13 @@ send_iov_nontls (struct MHD_Connection *restrict connection, if (1) { size_t track_sent = (size_t) *sent; + + if (! connection->sk.props.is_nonblck) + connection->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ + (((unsigned int) connection->sk.ready) + & (~(enum mhd_SocketNetState) + mhd_SOCKET_NET_STATE_SEND_READY)); + /* Adjust the internal tracking information for the iovec to * take this last send into account. */ while ((0 != track_sent) && (r_iov->iov[r_iov->sent].iov_len <= track_sent))