[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] [PATCH] imprecision calculations of timeouts
From: |
Evgeny Grin |
Subject: |
Re: [libmicrohttpd] [PATCH] imprecision calculations of timeouts |
Date: |
Thu, 16 Mar 2017 23:16:47 +0300 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 |
You are right, connection must be idle *at least* "timeout" number of
seconds. Nor *not more* than "timeout" number of seconds.
Fixed as suggested.
--
Best Wishes,
Evgeny Grin
On 16.03.2017 22:27, Vitaliy T wrote:
> Because of timeouts have time_t type, it is possible that deltas will
> be rounded to a greater value (augment by 1, specifically).
>
> An example:
> 1. connection timeout is set to 1.
> 2. real delta between MHD_monotonic_sec_counter() -
> connection->last_activity is 0.7.
> 3. delta before patch is 1 and comparison via '<=' leads to disconnect.
>
> This is actual for very small timeouts values, where even microseconds
> are important.
>
>
> diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
> index c3c7be8b..833a0d87 100644
> --- a/src/microhttpd/connection.c
> +++ b/src/microhttpd/connection.c
> @@ -3215,7 +3215,7 @@ MHD_connection_handle_idle (struct
> MHD_Connection *connection)
> unsigned int timeout;
> timeout = connection->connection_timeout;
> if ( (0 != timeout) &&
> - (timeout <= (MHD_monotonic_sec_counter() -
> connection->last_activity)) )
> + (timeout < (MHD_monotonic_sec_counter() -
> connection->last_activity)) )
> {
> MHD_connection_close_ (connection,
> MHD_REQUEST_TERMINATED_TIMEOUT_REACHED);
> diff --git a/src/microhttpd/connection_https.c
> b/src/microhttpd/connection_https.c
> index 5a05bf3b..f023c2f1 100644
> --- a/src/microhttpd/connection_https.c
> +++ b/src/microhttpd/connection_https.c
> @@ -144,7 +144,7 @@ MHD_tls_connection_handle_idle (struct
> MHD_Connection *connection)
> return MHD_connection_handle_idle (connection);
> timeout = connection->connection_timeout;
> if ( (timeout != 0) &&
> - (timeout <= (MHD_monotonic_sec_counter() -
> connection->last_activity)))
> + (timeout < (MHD_monotonic_sec_counter() - connection->last_activity)))
> MHD_connection_close_ (connection,
> MHD_REQUEST_TERMINATED_TIMEOUT_REACHED);
> switch (connection->state)
>
>