aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/connection.c
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-06-04 23:37:41 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-06-05 00:32:27 +0300
commit3777686c912cc6102694e55862302aec9a16812b (patch)
treeafbc620b0c2e6907398d47ea50db1e1ecec33be1 /src/microhttpd/connection.c
parent0c2fd79ba3d02659c8e223c4a8e6b9e6d9716018 (diff)
downloadlibmicrohttpd-3777686c912cc6102694e55862302aec9a16812b.tar.gz
libmicrohttpd-3777686c912cc6102694e55862302aec9a16812b.zip
Do not use errno to return errors from recv_param_adapter()/recv_tls_adapter()
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r--src/microhttpd/connection.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index baa5eb56..45cc6566 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -118,7 +118,8 @@
118 * @param connection the MHD connection structure 118 * @param connection the MHD connection structure
119 * @param other where to write received data to 119 * @param other where to write received data to
120 * @param i maximum size of other (in bytes) 120 * @param i maximum size of other (in bytes)
121 * @return number of bytes actually received 121 * @return positive value for number of bytes actually received or
122 * negative value for error number MHD_ERR_xxx_
122 */ 123 */
123static ssize_t 124static ssize_t
124recv_param_adapter (struct MHD_Connection *connection, 125recv_param_adapter (struct MHD_Connection *connection,
@@ -130,8 +131,7 @@ recv_param_adapter (struct MHD_Connection *connection,
130 if ( (MHD_INVALID_SOCKET == connection->socket_fd) || 131 if ( (MHD_INVALID_SOCKET == connection->socket_fd) ||
131 (MHD_CONNECTION_CLOSED == connection->state) ) 132 (MHD_CONNECTION_CLOSED == connection->state) )
132 { 133 {
133 MHD_socket_set_error_ (MHD_SCKT_ENOTCONN_); 134 return MHD_ERR_NOTCONN_;
134 return -1;
135 } 135 }
136 if (i > MHD_SCKT_SEND_MAX_SIZE_) 136 if (i > MHD_SCKT_SEND_MAX_SIZE_)
137 i = MHD_SCKT_SEND_MAX_SIZE_; /* return value limit */ 137 i = MHD_SCKT_SEND_MAX_SIZE_; /* return value limit */
@@ -139,16 +139,26 @@ recv_param_adapter (struct MHD_Connection *connection,
139 ret = MHD_recv_ (connection->socket_fd, 139 ret = MHD_recv_ (connection->socket_fd,
140 other, 140 other,
141 i); 141 i);
142#ifdef EPOLL_SUPPORT
143 if (0 > ret) 142 if (0 > ret)
144 { 143 {
145 /* Got EAGAIN --- no longer read-ready */ 144 const int err = MHD_socket_get_error_ ();
146 if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())) 145 if (MHD_SCKT_ERR_IS_EAGAIN_ (err))
147 connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY; 146 {
147#ifdef EPOLL_SUPPORT
148 /* Got EAGAIN --- no longer read-ready */
149 connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
150#endif /* EPOLL_SUPPORT */
151 return MHD_ERR_AGAIN_;
152 }
153 if (MHD_SCKT_ERR_IS_EINTR_ (err))
154 return MHD_ERR_AGAIN_;
155 /* Treat any other error as hard error. */
156 return MHD_ERR_CONNRESET_;
148 } 157 }
158#ifdef EPOLL_SUPPORT
149 else if (i > (size_t)ret) 159 else if (i > (size_t)ret)
150 connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY; 160 connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
151#endif 161#endif /* EPOLL_SUPPORT */
152 return ret; 162 return ret;
153} 163}
154 164
@@ -2660,11 +2670,9 @@ MHD_connection_handle_read (struct MHD_Connection *connection)
2660 connection->read_buffer_offset); 2670 connection->read_buffer_offset);
2661 if (bytes_read < 0) 2671 if (bytes_read < 0)
2662 { 2672 {
2663 const int err = MHD_socket_get_error_ (); 2673 if (MHD_ERR_AGAIN_ == bytes_read)
2664 if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
2665 MHD_SCKT_ERR_IS_EAGAIN_ (err))
2666 return MHD_YES; /* No new data to process. */ 2674 return MHD_YES; /* No new data to process. */
2667 if (MHD_SCKT_ERR_IS_REMOTE_DISCNN_ (err)) 2675 if (MHD_ERR_CONNRESET_ == bytes_read)
2668 { 2676 {
2669 CONNECTION_CLOSE_ERROR (connection, 2677 CONNECTION_CLOSE_ERROR (connection,
2670 (MHD_CONNECTION_INIT == connection->state) ? 2678 (MHD_CONNECTION_INIT == connection->state) ?