diff --git a/Makefile b/Makefile index dd1a2051..25bb4f99 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ PROFILEFLAGS=-pg -profile # -fdump-rtl-expand endif CFLAGS=-Wall -O2 -minline-all-stringops -I ./deps/udns-0.0.9/ -LFLAGS=-rdynamic -ldl -lm -lpthread +LFLAGS=-rdynamic -ldl -lm -lpthread -lrt CC=gcc -D_GNU_SOURCE RM=rm -f diff --git a/modules/libape-spidermonkey.c b/modules/libape-spidermonkey.c index 249375d0..bb49a705 100644 --- a/modules/libape-spidermonkey.c +++ b/modules/libape-spidermonkey.c @@ -2276,6 +2276,7 @@ static void sm_sock_ondisconnect(ape_socket *client, acetables *g_ape) free(cb->private); free(cb); + client->attach = NULL; //JS_EndRequest(cb->asc->cx); //JS_ClearContextThread(cb->asc->cx); @@ -4743,7 +4744,8 @@ static void mysac_setdb_success(struct _ape_mysql_data *myhandle, int code) /* TODO : Supress queue */ - free(myhandle->db); + free(myhandle->db); + myhandle->db = NULL; } } @@ -4772,6 +4774,7 @@ static void mysac_connect_success(struct _ape_mysql_data *myhandle, int code) myhandle->on_success = NULL; free(myhandle->db); + myhandle->db = NULL; } } @@ -4832,6 +4835,7 @@ static void mysac_query_success(struct _ape_mysql_data *myhandle, int code) JS_free(myhandle->cx, queue->query); free(queue->res); free(queue); + myhandle->data = NULL; apemysql_shift_queue(myhandle); } diff --git a/src/http.c b/src/http.c index d5432eb4..25cee178 100644 --- a/src/http.c +++ b/src/http.c @@ -389,7 +389,7 @@ void process_websocket(ape_socket *co, acetables *g_ape) } if (buffer->length > 502400) { - shutdown(co->fd, 2); + safe_shutdown(co->fd, g_ape); return; } diff --git a/src/json_parser.c b/src/json_parser.c index 788ad5ad..4a82b8fe 100755 --- a/src/json_parser.c +++ b/src/json_parser.c @@ -77,6 +77,7 @@ SOFTWARE. #include #include "json_parser.h" +#include "utils.h" #ifdef _MSC_VER # if _MSC_VER >= 1400 /* Visual Studio 2005 and up */ @@ -624,8 +625,9 @@ static int parse_parse_buffer(JSON_parser jc) break; case JSON_T_STRING: arg = &value; + urldecode(jc->parse_buffer); value.vu.str.value = jc->parse_buffer; - value.vu.str.length = jc->parse_buffer_count; + value.vu.str.length = strlen(jc->parse_buffer); break; } @@ -1037,8 +1039,9 @@ JSON_parser_char(JSON_parser jc, int next_char) if (jc->callback) { JSON_value value; + urldecode(jc->parse_buffer); value.vu.str.value = jc->parse_buffer; - value.vu.str.length = jc->parse_buffer_count; + value.vu.str.length = strlen(jc->parse_buffer); if (!(*jc->callback)(jc->ctx, JSON_T_KEY, &value)) { return false; } diff --git a/src/sock.c b/src/sock.c index 96010e64..5424a3f2 100644 --- a/src/sock.c +++ b/src/sock.c @@ -281,7 +281,7 @@ unsigned int sockroutine(acetables *g_ape) int new_fd, nfds, sin_size = sizeof(struct sockaddr_in), i, tfd = 0; - struct timeval t_start, t_end; + struct timespec t_start, t_end; long int ticks = 0, uticks = 0, lticks = 0; struct sockaddr_in their_addr; @@ -291,7 +291,13 @@ unsigned int sockroutine(acetables *g_ape) #if 0 add_periodical(5, 0, check_idle, &sl, g_ape); #endif - gettimeofday(&t_start, NULL); + if (clock_gettime(CLOCK_MONOTONIC, &t_start) < 0) + { + ape_log(APE_ERR, __FILE__, __LINE__, g_ape, + "clock_gettime(CLOCK_MONOTONIC) : %s", strerror(errno)); + return 1; + } + while (server_is_running) { /* Linux 2.6.25 provides a fd-driven timer system. It could be usefull to implement */ int timeout_to_hang = get_first_timer_ms(g_ape); @@ -502,13 +508,25 @@ unsigned int sockroutine(acetables *g_ape) } } } - - gettimeofday(&t_end, NULL); - + + if (clock_gettime(CLOCK_MONOTONIC, &t_end) < 0) + { + ape_log(APE_ERR, __FILE__, __LINE__, g_ape, + "clock_gettime(CLOCK_MONOTONIC) : %s", strerror(errno)); + return 1; + } + ticks = 0; - - uticks = 1000000L * (t_end.tv_sec - t_start.tv_sec); - uticks += (t_end.tv_usec - t_start.tv_usec); + + if (t_end.tv_sec >= t_start.tv_sec) + { + uticks = 1000000L * (t_end.tv_sec - t_start.tv_sec); + uticks += ((t_end.tv_nsec - t_start.tv_nsec) / 1000); + } else { + ape_log(APE_ERR, __FILE__, __LINE__, g_ape, + "end time less than start time (start:%ld, end:%ld)", t_start.tv_sec, t_end.tv_sec); + uticks = 1000; // a total hack, but probably better than 0 + } t_start = t_end; lticks += uticks; /* Tic tac, tic tac */