libmicrohttpd

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

commit 9c2700afc5c81f9a9199f6989633d94167f6e68a
parent 9d0f953af2400c13f8a15f68e625d3d60351dd95
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon, 23 Sep 2013 18:34:19 +0000

check CLOCK_MONOTONIC is defined

Diffstat:
MChangeLog | 4++++
Msrc/microhttpd/internal.c | 15++++++++++-----
Msrc/microspdy/EXPORT.sym | 1+
Msrc/microspdy/internal.c | 8+++++---
Msrc/spdy2http/proxy.c | 40+++++++++++++++++++++++++++++++---------
Msrc/testspdy/test_session_timeout.c | 12+++---------
6 files changed, 54 insertions(+), 26 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,7 @@ +Mon Sep 23 20:24:48 CEST 2013 + Fixing build issues on OS X with CLOCK_MONOTONIC not being + implemented on OS X. -CG + Mon Sep 23 14:15:00 CEST 2013 Make libmicrohttpd play nicely with upcoming libgcrypt 1.6.0. -CG diff --git a/src/microhttpd/internal.c b/src/microhttpd/internal.c @@ -158,14 +158,19 @@ MHD_http_unescape (void *cls, return wpos - val; /* = strlen(val) */ } -time_t MHD_monotonic_time(void) + +time_t +MHD_monotonic_time (void) { #ifdef HAVE_CLOCK_GETTIME - struct timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) - return ts.tv_sec; +#ifdef CLOCK_MONOTONIC + struct timespec ts; + + if (0 == clock_gettime (CLOCK_MONOTONIC, &ts)) + return ts.tv_sec; +#endif #endif - return time(NULL); + return time (NULL); } /* end of internal.c */ diff --git a/src/microspdy/EXPORT.sym b/src/microspdy/EXPORT.sym @@ -1,2 +1,3 @@ SPDY_start_daemon SPDY_stop_daemon +SPDYF_monotonic_time diff --git a/src/microspdy/internal.c b/src/microspdy/internal.c @@ -27,12 +27,14 @@ unsigned long long -SPDYF_monotonic_time(void) +SPDYF_monotonic_time (void) { #ifdef HAVE_CLOCK_GETTIME +#ifdef CLOCK_MONOTONIC struct timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) + if (0 == clock_gettime (CLOCK_MONOTONIC, &ts)) return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; #endif - return time(NULL) * 1000; +#endif + return time (NULL) * 1000; } diff --git a/src/spdy2http/proxy.c b/src/spdy2http/proxy.c @@ -244,12 +244,29 @@ parse_uri(regex_t * preg, const char * full_uri, struct URI ** uri) (*uri)->full_uri = strdup(full_uri); - asprintf(&((*uri)->scheme), "%.*s",pmatch[2].rm_eo - pmatch[2].rm_so, &full_uri[pmatch[2].rm_so]); - asprintf(&((*uri)->host_and_port), "%.*s",pmatch[4].rm_eo - pmatch[4].rm_so, &full_uri[pmatch[4].rm_so]); - asprintf(&((*uri)->path), "%.*s",pmatch[5].rm_eo - pmatch[5].rm_so, &full_uri[pmatch[5].rm_so]); - asprintf(&((*uri)->path_and_more), "%.*s",pmatch[9].rm_eo - pmatch[5].rm_so, &full_uri[pmatch[5].rm_so]); - asprintf(&((*uri)->query), "%.*s",pmatch[7].rm_eo - pmatch[7].rm_so, &full_uri[pmatch[7].rm_so]); - asprintf(&((*uri)->fragment), "%.*s",pmatch[9].rm_eo - pmatch[9].rm_so, &full_uri[pmatch[9].rm_so]); + asprintf(&((*uri)->scheme), + "%.*s", + (int) (pmatch[2].rm_eo - pmatch[2].rm_so), + &full_uri[pmatch[2].rm_so]); + asprintf(&((*uri)->host_and_port), "%.*s", + (int) (pmatch[4].rm_eo - pmatch[4].rm_so), + &full_uri[pmatch[4].rm_so]); + asprintf(&((*uri)->path), + "%.*s", + (int) (pmatch[5].rm_eo - pmatch[5].rm_so), + &full_uri[pmatch[5].rm_so]); + asprintf(&((*uri)->path_and_more), + "%.*s", + (int) (pmatch[9].rm_eo - pmatch[5].rm_so), + &full_uri[pmatch[5].rm_so]); + asprintf(&((*uri)->query), + "%.*s", + (int) (pmatch[7].rm_eo - pmatch[7].rm_so), + &full_uri[pmatch[7].rm_so]); + asprintf(&((*uri)->fragment), + "%.*s", + (int) (pmatch[9].rm_eo - pmatch[9].rm_so), + &full_uri[pmatch[9].rm_so]); colon = strrchr((*uri)->host_and_port, ':'); if(NULL == colon) @@ -1173,12 +1190,17 @@ run () if(glob_opt.verbose) { - struct timespec ts; +#ifdef HAVE_CLOCK_GETTIME #ifdef CLOCK_MONOTONIC - if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) - PRINT_VERBOSE2("time now %lld %lld", (unsigned long long)ts.tv_sec, (unsigned long long)ts.tv_nsec); + struct timespec ts; + + if (0 == clock_gettime(CLOCK_MONOTONIC, &ts)) + PRINT_VERBOSE2 ("time now %lld %lld", + (unsigned long long) ts.tv_sec, + (unsigned long long) ts.tv_nsec); } #endif +#endif } while(loop); diff --git a/src/testspdy/test_session_timeout.c b/src/testspdy/test_session_timeout.c @@ -31,6 +31,7 @@ #include "common.h" #include <sys/time.h> #include <sys/stat.h> +#include "../microspdy/internal.h" #define TIMEOUT 2 #define SELECT_MS_TIMEOUT 20 @@ -102,7 +103,6 @@ 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; @@ -150,10 +150,7 @@ parentproc() { 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"); + now = SPDYF_monotonic_time (); if(now - beginning > TIMEOUT*1000 + SELECT_MS_TIMEOUT) { printf("Started at: %llums\n",beginning); @@ -217,10 +214,7 @@ parentproc() SPDY_run(daemon); 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"); + beginning = SPDYF_monotonic_time (); } /*if(do_sleep) {