aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r--src/microhttpd/connection.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 25788414..7f2dcd75 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -794,11 +794,33 @@ try_ready_normal_body (struct MHD_Connection *connection)
794 struct MHD_Response *response; 794 struct MHD_Response *response;
795 795
796 response = connection->response; 796 response = connection->response;
797 if (NULL == response->crc)
798 return MHD_YES;
799 if ( (0 == response->total_size) || 797 if ( (0 == response->total_size) ||
800 (connection->response_write_position == response->total_size) ) 798 (connection->response_write_position == response->total_size) )
801 return MHD_YES; /* 0-byte response is always ready */ 799 return MHD_YES; /* 0-byte response is always ready */
800 if (NULL != response->data_iov)
801 {
802 size_t copy_size;
803 if (NULL != connection->resp_iov.iov)
804 return MHD_YES;
805
806 copy_size = response->data_iovcnt * sizeof(MHD_iovec_);
807 connection->resp_iov.iov = MHD_pool_allocate (connection->pool, copy_size,
808 true);
809 if (NULL == connection->resp_iov.iov)
810 {
811 MHD_mutex_unlock_chk_ (&response->mutex);
812 /* not enough memory */
813 CONNECTION_CLOSE_ERROR (connection,
814 _ ("Closing connection (out of memory).\n"));
815 return MHD_NO;
816 }
817 memcpy (connection->resp_iov.iov, response->data_iov, copy_size);
818 connection->resp_iov.cnt = response->data_iovcnt;
819 connection->resp_iov.sent = 0;
820 return MHD_YES;
821 }
822 if (NULL == response->crc)
823 return MHD_YES;
802 if ( (response->data_start <= 824 if ( (response->data_start <=
803 connection->response_write_position) && 825 connection->response_write_position) &&
804 (response->data_size + response->data_start > 826 (response->data_size + response->data_start >
@@ -2935,6 +2957,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
2935 connection->response_write_position) ); 2957 connection->response_write_position) );
2936 2958
2937 if ( (NULL == resp->crc) && 2959 if ( (NULL == resp->crc) &&
2960 (NULL == resp->data_iov) &&
2938 (0 == connection->response_write_position) ) 2961 (0 == connection->response_write_position) )
2939 { 2962 {
2940 mhd_assert (resp->total_size >= resp->data_size); 2963 mhd_assert (resp->total_size >= resp->data_size);
@@ -3017,12 +3040,16 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
3017#if defined(_MHD_HAVE_SENDFILE) 3040#if defined(_MHD_HAVE_SENDFILE)
3018 if (MHD_resp_sender_sendfile == connection->resp_sender) 3041 if (MHD_resp_sender_sendfile == connection->resp_sender)
3019 { 3042 {
3043 mhd_assert (NULL == response->data_iov);
3020 ret = MHD_send_sendfile_ (connection); 3044 ret = MHD_send_sendfile_ (connection);
3021 } 3045 }
3046 else /* combined with the next 'if' */
3047#endif /* _MHD_HAVE_SENDFILE */
3048 if (NULL != response->data_iov)
3049 {
3050 ret = MHD_send_iovec_ (connection, &connection->resp_iov, true);
3051 }
3022 else 3052 else
3023#else /* ! _MHD_HAVE_SENDFILE */
3024 if (1)
3025#endif /* ! _MHD_HAVE_SENDFILE */
3026 { 3053 {
3027 data_write_offset = connection->response_write_position 3054 data_write_offset = connection->response_write_position
3028 - response->data_start; 3055 - response->data_start;
@@ -3674,6 +3701,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
3674 connection->write_buffer_size = 0; 3701 connection->write_buffer_size = 0;
3675 connection->write_buffer_send_offset = 0; 3702 connection->write_buffer_send_offset = 0;
3676 connection->write_buffer_append_offset = 0; 3703 connection->write_buffer_append_offset = 0;
3704 /* iov (if any) was deallocated by MHD_pool_reset */
3705 memset (&connection->resp_iov, 0, sizeof(connection->resp_iov));
3677 continue; 3706 continue;
3678 case MHD_CONNECTION_CLOSED: 3707 case MHD_CONNECTION_CLOSED:
3679 cleanup_connection (connection); 3708 cleanup_connection (connection);