libmicrohttpd

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

commit 18b1972b408b9620e497307d7ce33e86bfbb605e
parent b2a041e934bd33a033668d2d94053a4e6085c570
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 19 Dec 2014 23:42:32 +0000

-fix linker issue

Diffstat:
Msrc/testspdy/test_session_timeout.c | 87+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 54 insertions(+), 33 deletions(-)

diff --git a/src/testspdy/test_session_timeout.c b/src/testspdy/test_session_timeout.c @@ -47,7 +47,23 @@ int new_session; int closed_session; int do_sleep; -void + + +static unsigned long long +monotonic_time (void) +{ +#ifdef HAVE_CLOCK_GETTIME +#ifdef CLOCK_MONOTONIC + struct timespec ts; + if (0 == clock_gettime (CLOCK_MONOTONIC, &ts)) + return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; +#endif +#endif + return time (NULL) * 1000; +} + + +static void killchild(char *msg) { printf("%s\n",msg); @@ -55,7 +71,8 @@ killchild(char *msg) exit(1); } -void + +static void killparent(char *msg) { printf("%s\n",msg); @@ -63,28 +80,30 @@ killparent(char *msg) _exit(1); } -void + +static void new_session_cb (void *cls, - struct SPDY_Session * session) + struct SPDY_Session * session) { (void)cls; (void)session; - + if(!new_session)do_sleep = 1; new_session = 1; printf("new session\n"); } -void + +static void closed_session_cb (void *cls, - struct SPDY_Session * session, - int by_client) + struct SPDY_Session * session, + int by_client) { (void)cls; (void)session; - + printf("closed_session_cb called\n"); - + if(SPDY_YES == by_client) { killchild("closed by the client"); @@ -93,13 +112,14 @@ closed_session_cb (void *cls, { killchild("closed_session_cb called twice"); } - + closed_session = 1; } -int + +static int parentproc() -{ +{ int childstatus; unsigned long long timeoutlong=0; struct timeval timeout; @@ -111,9 +131,9 @@ parentproc() struct SPDY_Daemon *daemon; unsigned long long beginning = 0; unsigned long long now; - + SPDY_init(); - + daemon = SPDY_start_daemon(port, DATA_DIR "cert-and-key.pem", DATA_DIR "cert-and-key.pem", @@ -125,7 +145,7 @@ parentproc() SPDY_DAEMON_OPTION_SESSION_TIMEOUT, TIMEOUT, SPDY_DAEMON_OPTION_END); - + if(NULL==daemon){ printf("no daemon\n"); return 1; @@ -139,7 +159,7 @@ parentproc() FD_ZERO(&except_fd_set); ret = SPDY_get_timeout(daemon, &timeoutlong); - + if(new_session && !closed_session) { if(SPDY_NO == ret) @@ -150,7 +170,7 @@ parentproc() { killchild("SPDY_get_timeout returned wrong timeout"); }*/ - now = SPDYF_monotonic_time (); + now = monotonic_time (); if(now - beginning > TIMEOUT*1000 + SELECT_MS_TIMEOUT) { printf("Started at: %llums\n",beginning); @@ -177,7 +197,7 @@ parentproc() killchild("SPDY_get_timeout returned wrong SPDY_YES"); } } - + if(SPDY_NO == ret || timeoutlong >= 1000) { timeout.tv_sec = 1; @@ -188,18 +208,18 @@ parentproc() 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, - &write_fd_set, + &write_fd_set, &except_fd_set); - + ret = select(maxfd+1, &read_fd_set, &write_fd_set, &except_fd_set, &timeout); - + switch(ret) { case -1: printf("select error: %i\n", errno); @@ -214,7 +234,7 @@ parentproc() SPDY_run(daemon); if(0 == beginning) { - beginning = SPDYF_monotonic_time (); + beginning = monotonic_time (); } /*if(do_sleep) { @@ -225,27 +245,28 @@ parentproc() } } while(waitpid(child,&childstatus,WNOHANG) != child); - + if(!new_session || !closed_session) { killchild("child is dead, callback wasn't called"); } ret = SPDY_get_timeout(daemon, &timeoutlong); - + if(SPDY_YES == ret) { killchild("SPDY_get_timeout returned wrong SPDY_YES after child died"); } - + SPDY_stop_daemon(daemon); - + SPDY_deinit(); - + return 0; } -int + +static int childproc() { pid_t devnull; @@ -292,7 +313,7 @@ main() child = fork(); if (-1 == child) - { + { fprintf(stderr, "can't fork, error %d\n", errno); exit(EXIT_FAILURE); } @@ -303,7 +324,7 @@ main() _exit(ret); } else - { + { int ret = parentproc(); exit(ret); }