diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-10-20 19:22:14 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-10-22 09:48:07 +0300 |
commit | f1c69db3000e65a992e33190f3d272a5b9ca7462 (patch) | |
tree | a38326d0403b6f9821a86419560a55f8ef654c65 | |
parent | bf9e99729c52c2462390ce1d29eeda7f0f337b26 (diff) | |
download | libmicrohttpd-f1c69db3000e65a992e33190f3d272a5b9ca7462.tar.gz libmicrohttpd-f1c69db3000e65a992e33190f3d272a5b9ca7462.zip |
Reworked partial processing of the upload
Now if some data has been processed by Access Handler Callback, zero
timeout is used for the next turn and at the same time more data is
read (if available) from the network.
If Access Handler Callback has not processed any data, MHD will wait
for additional data to come.
-rw-r--r-- | src/microhttpd/connection.c | 30 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 12 |
2 files changed, 33 insertions, 9 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 0f94422b..cc6192ad 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -2592,6 +2592,8 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection) | |||
2592 | if ( (connection->read_buffer_offset < connection->read_buffer_size) && | 2592 | if ( (connection->read_buffer_offset < connection->read_buffer_size) && |
2593 | (! connection->discard_request) ) | 2593 | (! connection->discard_request) ) |
2594 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | 2594 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; |
2595 | else if (connection->rq.some_payload_processed) | ||
2596 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_PROCESS_READ; | ||
2595 | else | 2597 | else |
2596 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_PROCESS; | 2598 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_PROCESS; |
2597 | break; | 2599 | break; |
@@ -3448,6 +3450,8 @@ process_request_body (struct MHD_Connection *connection) | |||
3448 | bool instant_retry; | 3450 | bool instant_retry; |
3449 | char *buffer_head; | 3451 | char *buffer_head; |
3450 | 3452 | ||
3453 | connection->rq.some_payload_processed = false; | ||
3454 | |||
3451 | if (NULL != connection->rp.response) | 3455 | if (NULL != connection->rp.response) |
3452 | { | 3456 | { |
3453 | /* TODO: discard all read buffer as early response | 3457 | /* TODO: discard all read buffer as early response |
@@ -3673,19 +3677,27 @@ process_request_body (struct MHD_Connection *connection) | |||
3673 | } | 3677 | } |
3674 | if (left_unprocessed > to_be_processed) | 3678 | if (left_unprocessed > to_be_processed) |
3675 | MHD_PANIC (_ ("libmicrohttpd API violation.\n")); | 3679 | MHD_PANIC (_ ("libmicrohttpd API violation.\n")); |
3680 | |||
3681 | if (left_unprocessed != to_be_processed) | ||
3682 | /* Something was processed by the application. */ | ||
3683 | connection->rq.some_payload_processed = true; | ||
3676 | if (0 != left_unprocessed) | 3684 | if (0 != left_unprocessed) |
3677 | { | 3685 | { |
3678 | instant_retry = false; /* client did not process everything */ | 3686 | instant_retry = false; /* client did not process everything */ |
3679 | #ifdef HAVE_MESSAGES | 3687 | #ifdef HAVE_MESSAGES |
3680 | /* client did not process all upload data, complain if | 3688 | if ((left_unprocessed == to_be_processed) && |
3681 | the setup was incorrect, which may prevent us from | 3689 | (! connection->suspended)) |
3682 | handling the rest of the request */ | 3690 | { |
3683 | if ( (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) && | 3691 | /* client did not process any upload data, complain if |
3684 | (! connection->suspended) ) | 3692 | the setup was incorrect, which may prevent us from |
3685 | MHD_DLOG (daemon, | 3693 | handling the rest of the request */ |
3686 | _ ("WARNING: incomplete upload processing and connection " \ | 3694 | if (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) |
3687 | "not suspended may result in hung connection.\n")); | 3695 | MHD_DLOG (daemon, |
3688 | #endif | 3696 | _ ("WARNING: Access Handler Callback has not processed " \ |
3697 | "any upload data and connection is not suspended. " \ | ||
3698 | "This may result in hung connection.\n")); | ||
3699 | } | ||
3700 | #endif /* HAVE_MESSAGES */ | ||
3689 | } | 3701 | } |
3690 | processed_size = to_be_processed - left_unprocessed; | 3702 | processed_size = to_be_processed - left_unprocessed; |
3691 | if (connection->rq.have_chunked_upload) | 3703 | if (connection->rq.have_chunked_upload) |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 990552b7..78481b21 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -1022,6 +1022,18 @@ struct MHD_Request | |||
1022 | uint64_t current_chunk_offset; | 1022 | uint64_t current_chunk_offset; |
1023 | 1023 | ||
1024 | /** | 1024 | /** |
1025 | * Indicate that some of the upload payload data have been processed | ||
1026 | * by the last call of the connection handler. | ||
1027 | * If any data have been processed, but some data left in the buffer | ||
1028 | * for further processing, then MHD will use zero timeout before the | ||
1029 | * next data processing round. | ||
1030 | * If no data have been processed, than MHD will wait for more data | ||
1031 | * to come (as it makes no sense to call the connection handler with | ||
1032 | * the same conditions). | ||
1033 | */ | ||
1034 | bool some_payload_processed; | ||
1035 | |||
1036 | /** | ||
1025 | * We allow the main application to associate some pointer with the | 1037 | * We allow the main application to associate some pointer with the |
1026 | * HTTP request, which is passed to each #MHD_AccessHandlerCallback | 1038 | * HTTP request, which is passed to each #MHD_AccessHandlerCallback |
1027 | * and some other API calls. Here is where we store it. (MHD does | 1039 | * and some other API calls. Here is where we store it. (MHD does |