aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-08-01 21:17:46 +0200
committerChristian Grothoff <christian@grothoff.org>2019-08-01 21:17:46 +0200
commit8a4aec4d78fe4fb335aede980e8567b8bc51858f (patch)
tree666a9827d15f4859d6200dac795d5ae80b6d0a88
parentd21cf2c1c225c888a3fd6161a6a04357714cc628 (diff)
downloadlibmicrohttpd-8a4aec4d78fe4fb335aede980e8567b8bc51858f.tar.gz
libmicrohttpd-8a4aec4d78fe4fb335aede980e8567b8bc51858f.zip
properly handle return value from send_on_connection2
-rw-r--r--src/microhttpd/connection.c77
1 files changed, 45 insertions, 32 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index dab28878..67ff6017 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -3180,42 +3180,55 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
3180 mhd_assert (0); 3180 mhd_assert (0);
3181 return; 3181 return;
3182 case MHD_CONNECTION_HEADERS_SENDING: 3182 case MHD_CONNECTION_HEADERS_SENDING:
3183 /* if the response body is not available, we use MHD_send_on_connection_() */ 3183 {
3184 if (NULL != connection->response->crc) 3184 const size_t wb_ready =connection->write_buffer_append_offset -
3185 { 3185 connection->write_buffer_send_offset;
3186 ret = MHD_send_on_connection_ (connection,
3187 &connection->write_buffer
3188 [connection->write_buffer_send_offset],
3189 connection->write_buffer_append_offset -
3190 connection->write_buffer_send_offset,
3191 MHD_SSO_MAY_CORK);
3192 }
3193 else
3194 {
3195 ret = MHD_send_on_connection2_ (connection,
3196 &connection->write_buffer
3197 [connection->write_buffer_send_offset],
3198 connection->write_buffer_append_offset -
3199 connection->write_buffer_send_offset,
3200 connection->response->data,
3201 connection->response->data_buffer_size);
3202 }
3203 3186
3204 if (ret < 0) 3187 /* if the response body is not available, we use MHD_send_on_connection_() */
3205 { 3188 if (NULL != connection->response->crc)
3206 if (MHD_ERR_AGAIN_ == ret) 3189 {
3190 ret = MHD_send_on_connection_ (connection,
3191 &connection->write_buffer
3192 [connection->write_buffer_send_offset],
3193 wb_ready,
3194 MHD_SSO_MAY_CORK);
3195 }
3196 else
3197 {
3198 ret = MHD_send_on_connection2_ (connection,
3199 &connection->write_buffer
3200 [connection->write_buffer_send_offset],
3201 wb_ready,
3202 connection->response->data,
3203 connection->response->data_buffer_size);
3204 }
3205
3206 if (ret < 0)
3207 {
3208 if (MHD_ERR_AGAIN_ == ret)
3209 return;
3210 CONNECTION_CLOSE_ERROR (connection,
3211 _("Connection was closed while sending response headers.\n"));
3207 return; 3212 return;
3208 CONNECTION_CLOSE_ERROR (connection, 3213 }
3209 _("Connection was closed while sending response headers.\n")); 3214 if (ret > wb_ready)
3215 {
3216 mhd_assert (NULL == connection->repsonse->crc);
3217 /* We sent not just header data but also some response data,
3218 update both offsets! */
3219 connection->write_buffer_send_offset += wb_ready;
3220 ret -= wb_ready;
3221 connection->response_write_position += ret;
3222 }
3223 else
3224 connection->write_buffer_send_offset += ret;
3225 MHD_update_last_activity_ (connection);
3226 if (MHD_CONNECTION_HEADERS_SENDING != connection->state)
3210 return; 3227 return;
3211 } 3228 check_write_done (connection,
3212 connection->write_buffer_send_offset += ret; 3229 MHD_CONNECTION_HEADERS_SENT);
3213 MHD_update_last_activity_ (connection);
3214 if (MHD_CONNECTION_HEADERS_SENDING != connection->state)
3215 return; 3230 return;
3216 check_write_done (connection, 3231 }
3217 MHD_CONNECTION_HEADERS_SENT);
3218 return;
3219 case MHD_CONNECTION_HEADERS_SENT: 3232 case MHD_CONNECTION_HEADERS_SENT:
3220 return; 3233 return;
3221 case MHD_CONNECTION_NORMAL_BODY_READY: 3234 case MHD_CONNECTION_NORMAL_BODY_READY: