libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit b43954303929b9e3980805d51322db9f9046e7c4
parent 4231889ce35dd86cbd6a3872b3fcba053f1fd65c
Author: Andrey Uzunov <andrey.uzunov@gmail.com>
Date:   Wed, 17 Jul 2013 14:46:49 +0000

spdy: change SPDY_get_timeout to give not seconds but milliseconds as it used to be

Diffstat:
MREADME | 1-
Msrc/examples/spdy_event_loop.c | 17++++++-----------
Msrc/examples/spdy_fileserver.c | 13+++++--------
Msrc/examples/spdy_response_with_callback.c | 14+++++---------
Msrc/include/microspdy.h | 2+-
Msrc/microspdy/daemon.c | 9++++-----
Msrc/microspdy/daemon.h | 2+-
Msrc/microspdy/internal.c | 10+++++-----
Msrc/microspdy/internal.h | 4++--
Msrc/microspdy/structures.h | 8++++----
Msrc/testspdy/test_misc.c | 7++++---
Msrc/testspdy/test_new_connection.c | 8++++----
Msrc/testspdy/test_notls.c | 8++++----
Msrc/testspdy/test_request_response.c | 8++++----
Msrc/testspdy/test_request_response_with_callback.c | 8++++----
Msrc/testspdy/test_requests_with_assets.c | 10+++++-----
Msrc/testspdy/test_session_timeout.c | 54++++++++++++++++++++++++++++++++++++++++++++----------
17 files changed, 102 insertions(+), 81 deletions(-)

diff --git a/README b/README @@ -103,7 +103,6 @@ be reasonably complete: - 8 different output queues (one for each priority) have to be implemented together with a suitable algorithm for utilizing them. Otherwise, downloading a file will block all responses with same or smaller priority -- Change session timeout to use not seconds but something more precise - SPDY RST_STREAM sending on each possible error (DONE?) - SPDY_close_session - Find the best way for closing still opened stream (new call or existing) diff --git a/src/examples/spdy_event_loop.c b/src/examples/spdy_event_loop.c @@ -337,22 +337,17 @@ main (int argc, char *const *argv) FD_ZERO(&except_fd_set); ret = SPDY_get_timeout(daemon, &timeoutlong); - //printf("tout %i\n",timeoutlong); - if(SPDY_NO == ret || timeoutlong > 1) - { - //do sth else - //sleep(1); - - //try new connection + if(SPDY_NO == ret || timeoutlong > 1000) + { timeout.tv_sec = 1; - timeout.tv_usec = 0; + timeout.tv_usec = 0; } else { - timeout.tv_sec = timeoutlong; - timeout.tv_usec = 0;//(timeoutlong % 1000) * 1000; + timeout.tv_sec = timeoutlong / 1000; + timeout.tv_usec = (timeoutlong % 1000) * 1000; } - + printf("ret=%i; timeoutlong=%i; sec=%i; usec=%i\n", ret, timeoutlong, timeout.tv_sec, timeout.tv_usec); //raise(SIGINT); diff --git a/src/examples/spdy_fileserver.c b/src/examples/spdy_fileserver.c @@ -287,7 +287,6 @@ main (int argc, char *const *argv) } basedir = argv[3]; - timeout.tv_usec = 0; do { @@ -296,17 +295,15 @@ main (int argc, char *const *argv) FD_ZERO(&except_fd_set); ret = SPDY_get_timeout(daemon, &timeoutlong); - if(SPDY_NO == ret || timeoutlong > 1) - { - //do sth else - //sleep(1); - - //try new connection + if(SPDY_NO == ret || timeoutlong > 1000) + { timeout.tv_sec = 1; + timeout.tv_usec = 0; } else { - timeout.tv_sec = timeoutlong; + timeout.tv_sec = timeoutlong / 1000; + timeout.tv_usec = (timeoutlong % 1000) * 1000; } maxfd = SPDY_get_fdset (daemon, diff --git a/src/examples/spdy_response_with_callback.c b/src/examples/spdy_response_with_callback.c @@ -180,8 +180,6 @@ main (int argc, char *const *argv) return 1; } - timeout.tv_usec = 0; - do { FD_ZERO(&read_fd_set); @@ -189,17 +187,15 @@ main (int argc, char *const *argv) FD_ZERO(&except_fd_set); ret = SPDY_get_timeout(daemon, &timeoutlong); - if(SPDY_NO == ret || timeoutlong > 1) - { - //do sth else - //sleep(1); - - //try new connection + if(SPDY_NO == ret || timeoutlong > 1000) + { timeout.tv_sec = 1; + timeout.tv_usec = 0; } else { - timeout.tv_sec = timeoutlong; + timeout.tv_sec = timeoutlong / 1000; + timeout.tv_usec = (timeoutlong % 1000) * 1000; } maxfd = SPDY_get_fdset (daemon, diff --git a/src/include/microspdy.h b/src/include/microspdy.h @@ -905,7 +905,7 @@ SPDY_get_fdset (struct SPDY_Daemon * daemon, * should at most block, not the timeout value set for connections. * * @param daemon to query for timeout - * @param timeout will be set to the timeout value (in seconds) + * @param timeout will be set to the timeout value (in milliseconds) * @return SPDY_YES on success * SPDY_NO if no connections exist that * would necessiate the use of a timeout right now diff --git a/src/microspdy/daemon.c b/src/microspdy/daemon.c @@ -134,7 +134,7 @@ spdyf_parse_options_va (struct SPDY_Daemon *daemon, switch (opt) { case SPDY_DAEMON_OPTION_SESSION_TIMEOUT: - daemon->session_timeout = va_arg (valist, unsigned int); + daemon->session_timeout = va_arg (valist, unsigned int) * 1000; break; case SPDY_DAEMON_OPTION_SOCK_ADDR: daemon->address = va_arg (valist, struct sockaddr *); @@ -390,8 +390,8 @@ int SPDYF_get_timeout (struct SPDY_Daemon *daemon, unsigned long long *timeout) { - time_t earliest_deadline = 0; - time_t now; + unsigned long long earliest_deadline = 0; + unsigned long long now; struct SPDY_Session *pos; bool have_timeout; @@ -417,10 +417,9 @@ SPDYF_get_timeout (struct SPDY_Daemon *daemon, if (!have_timeout) return SPDY_NO; - if (earliest_deadline < now) + if (earliest_deadline <= now) *timeout = 0; else - //*timeout = 1000 * (1 + earliest_deadline - now); *timeout = earliest_deadline - now; return SPDY_YES; diff --git a/src/microspdy/daemon.h b/src/microspdy/daemon.h @@ -86,7 +86,7 @@ SPDYF_run (struct SPDY_Daemon *daemon); * should at most block, not the timeout value set for connections. * * @param daemon daemon to query for timeout - * @param timeout set to the timeout (in seconds) + * @param timeout set to the timeout (in milliseconds) * @return SPDY_YES on success, SPDY_NO if no connections exist that * would necessiate the use of a timeout right now */ diff --git a/src/microspdy/internal.c b/src/microspdy/internal.c @@ -26,13 +26,13 @@ #include "structures.h" -time_t +unsigned long long SPDYF_monotonic_time(void) { #ifdef HAVE_CLOCK_GETTIME - struct timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) - return ts.tv_sec; + struct timespec ts; + if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) + return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; #endif - return time(NULL); + return time(NULL) * 1000; } diff --git a/src/microspdy/internal.h b/src/microspdy/internal.h @@ -180,9 +180,9 @@ extern void *spdyf_panic_cls; /** * Returns monotonic time, to be used for session timeouts. * - * @return time in seconds + * @return time in milliseconds */ -time_t +unsigned long long SPDYF_monotonic_time(void); #endif diff --git a/src/microspdy/structures.h b/src/microspdy/structures.h @@ -739,9 +739,9 @@ struct SPDY_Session /** * Last time this connection had any activity - * (reading or writing). + * (reading or writing). In milliseconds. */ - time_t last_activity; + unsigned long long last_activity; /** * Socket for this connection. Set to -1 if @@ -918,10 +918,10 @@ struct SPDY_Daemon SPDYF_IODeinit fio_deinit; /** - * After how many seconds of inactivity should + * After how many milliseconds of inactivity should * connections time out? Zero for no timeout. */ - time_t session_timeout; + unsigned long long session_timeout; /** * Listen socket. diff --git a/src/testspdy/test_misc.c b/src/testspdy/test_misc.c @@ -210,7 +210,6 @@ parentproc() return 1; } - timeout.tv_usec = 0; create_child(); do @@ -220,13 +219,15 @@ parentproc() FD_ZERO(&except_fd_set); ret = SPDY_get_timeout(daemon, &timeoutlong); - if(SPDY_NO == ret || timeoutlong > 1) + if(SPDY_NO == ret || timeoutlong > 1000) { timeout.tv_sec = 1; + timeout.tv_usec = 0; } else { - timeout.tv_sec = timeoutlong; + timeout.tv_sec = timeoutlong / 1000; + timeout.tv_usec = (timeoutlong % 1000) * 1000; } maxfd = SPDY_get_fdset (daemon, diff --git a/src/testspdy/test_new_connection.c b/src/testspdy/test_new_connection.c @@ -897,8 +897,6 @@ parentproc(int child) printf("no daemon\n"); return 1; } - - timeout.tv_usec = 0; do { @@ -907,13 +905,15 @@ parentproc(int child) FD_ZERO(&except_fd_set); ret = SPDY_get_timeout(daemon, &timeoutlong); - if(SPDY_NO == ret || timeoutlong > 1) + if(SPDY_NO == ret || timeoutlong > 1000) { timeout.tv_sec = 1; + timeout.tv_usec = 0; } else { - timeout.tv_sec = timeoutlong; + timeout.tv_sec = timeoutlong / 1000; + timeout.tv_usec = (timeoutlong % 1000) * 1000; } maxfd = SPDY_get_fdset (daemon, diff --git a/src/testspdy/test_notls.c b/src/testspdy/test_notls.c @@ -859,8 +859,6 @@ parentproc( int port) printf("no daemon\n"); return 1; } - - timeout.tv_usec = 0; do { @@ -869,13 +867,15 @@ parentproc( int port) FD_ZERO(&except_fd_set); ret = SPDY_get_timeout(daemon, &timeoutlong); - if(SPDY_NO == ret || timeoutlong > 1) + if(SPDY_NO == ret || timeoutlong > 1000) { timeout.tv_sec = 1; + timeout.tv_usec = 0; } else { - timeout.tv_sec = timeoutlong; + timeout.tv_sec = timeoutlong / 1000; + timeout.tv_usec = (timeoutlong % 1000) * 1000; } maxfd = SPDY_get_fdset (daemon, diff --git a/src/testspdy/test_request_response.c b/src/testspdy/test_request_response.c @@ -908,8 +908,6 @@ parentproc( int port) printf("no daemon\n"); return 1; } - - timeout.tv_usec = 0; do { @@ -918,13 +916,15 @@ parentproc( int port) FD_ZERO(&except_fd_set); ret = SPDY_get_timeout(daemon, &timeoutlong); - if(SPDY_NO == ret || timeoutlong > 1) + if(SPDY_NO == ret || timeoutlong > 1000) { timeout.tv_sec = 1; + timeout.tv_usec = 0; } else { - timeout.tv_sec = timeoutlong; + timeout.tv_sec = timeoutlong / 1000; + timeout.tv_usec = (timeoutlong % 1000) * 1000; } maxfd = SPDY_get_fdset (daemon, diff --git a/src/testspdy/test_request_response_with_callback.c b/src/testspdy/test_request_response_with_callback.c @@ -176,8 +176,6 @@ parentproc() printf("no daemon\n"); return 1; } - - timeout.tv_usec = 0; do { @@ -186,13 +184,15 @@ parentproc() FD_ZERO(&except_fd_set); ret = SPDY_get_timeout(daemon, &timeoutlong); - if(SPDY_NO == ret || timeoutlong > 1) + if(SPDY_NO == ret || timeoutlong > 1000) { timeout.tv_sec = 1; + timeout.tv_usec = 0; } else { - timeout.tv_sec = timeoutlong; + timeout.tv_sec = timeoutlong / 1000; + timeout.tv_usec = (timeoutlong % 1000) * 1000; } maxfd = SPDY_get_fdset (daemon, diff --git a/src/testspdy/test_requests_with_assets.c b/src/testspdy/test_requests_with_assets.c @@ -226,8 +226,6 @@ parentproc() printf("no daemon\n"); return 1; } - - timeout.tv_usec = 0; do { @@ -239,15 +237,17 @@ parentproc() FD_ZERO(&read_fd_set); FD_ZERO(&write_fd_set); FD_ZERO(&except_fd_set); - + ret = SPDY_get_timeout(daemon, &timeoutlong); - if(SPDY_NO == ret || timeoutlong > 1) + if(SPDY_NO == ret || timeoutlong > 1000) { timeout.tv_sec = 1; + timeout.tv_usec = 0; } else { - timeout.tv_sec = timeoutlong; + timeout.tv_sec = timeoutlong / 1000; + timeout.tv_usec = (timeoutlong % 1000) * 1000; } maxfd = SPDY_get_fdset (daemon, diff --git a/src/testspdy/test_session_timeout.c b/src/testspdy/test_session_timeout.c @@ -33,6 +33,7 @@ #include <sys/stat.h> #define TIMEOUT 2 +#define SELECT_MS_TIMEOUT 20 int port; @@ -95,13 +96,16 @@ parentproc() int childstatus; unsigned long long timeoutlong=0; struct timeval timeout; + struct timespec ts; int ret; fd_set read_fd_set; fd_set write_fd_set; fd_set except_fd_set; int maxfd = -1; struct SPDY_Daemon *daemon; - + unsigned long long beginning = 0; + unsigned long long now; + SPDY_init(); daemon = SPDY_start_daemon(port, @@ -120,8 +124,6 @@ parentproc() printf("no daemon\n"); return 1; } - - timeout.tv_usec = 0; do { @@ -138,10 +140,32 @@ parentproc() { killchild("SPDY_get_timeout returned wrong SPDY_NO"); } - if(timeoutlong) + /*if(timeoutlong) { killchild("SPDY_get_timeout returned wrong timeout"); - } + }*/ + if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) + now = ts.tv_nsec / 1000000 + ts.tv_sec*1000; + else + killchild("clock_gettime returned wrong value"); + if(now - beginning > TIMEOUT*1000 + SELECT_MS_TIMEOUT) + { + printf("Started at: %ims\n",beginning); + printf("Now is: %ims\n",now); + printf("Timeout is: %i\n",TIMEOUT); + printf("Select Timeout is: %ims\n",SELECT_MS_TIMEOUT); + printf("SPDY_get_timeout gave: %ims\n",timeoutlong); + killchild("Timeout passed but session was not closed"); + } + if(timeoutlong > beginning + TIMEOUT *1000) + { + printf("Started at: %ims\n",beginning); + printf("Now is: %ims\n",now); + printf("Timeout is: %i\n",TIMEOUT); + printf("Select Timeout is: %ims\n",SELECT_MS_TIMEOUT); + printf("SPDY_get_timeout gave: %ims\n",timeoutlong); + killchild("SPDY_get_timeout returned wrong timeout"); + } } else { @@ -151,14 +175,20 @@ parentproc() } } - if(SPDY_NO == ret || timeoutlong > 1) + if(SPDY_NO == ret || timeoutlong >= 1000) { timeout.tv_sec = 1; + timeout.tv_usec = 0; } else { - timeout.tv_sec = timeoutlong; + timeout.tv_sec = timeoutlong / 1000; + timeout.tv_usec = (timeoutlong % 1000) * 1000; } + + //ignore values + timeout.tv_sec = 0; + timeout.tv_usec = SELECT_MS_TIMEOUT * 1000; maxfd = SPDY_get_fdset (daemon, &read_fd_set, @@ -179,12 +209,16 @@ parentproc() break; default: SPDY_run(daemon); - if(do_sleep) + if(0 == beginning) + if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) + beginning = ts.tv_nsec / 1000000 + ts.tv_sec*1000; + else + killchild("clock_gettime returned wrong number"); + /*if(do_sleep) { sleep(TIMEOUT); do_sleep = 0; - } - + }*/ break; } }