From b3be641eeddce360692d3a3e872d769f86f1b293 Mon Sep 17 00:00:00 2001 From: Joshua Judson Rosen Date: Mon, 16 Feb 2015 23:33:02 -0500 Subject: Nix mysleep(). Just use sleep() where only whole-second resolution is used to delay between reconnect-attempts; and nanosleep where sub-second resolution is used. sleep() should actually be OK, because we don't intermix those calls with alarm() or any other signals or itimer functions. nanosleep() should be OK because POSIX.1-2001 requires that it not have the crazy signal interactions that its predecessors are known for. --- src/afclient.c | 8 +++++--- src/http_proxy_functions.c | 15 --------------- src/http_proxy_functions.h | 1 - src/server_signals.c | 9 ++++++++- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/afclient.c b/src/afclient.c index a22ece3..e99598d 100644 --- a/src/afclient.c +++ b/src/afclient.c @@ -22,6 +22,8 @@ #include "afclient.h" +#include + static struct option long_options[] = { {"help", 0, 0, 'h'}, {"udpmode", 0, 0, 'u'}, @@ -825,7 +827,7 @@ main(int argc, char **argv) if ((i != 0) && (temp == 1)) { aflog(LOG_T_INIT, LOG_I_INFO, "Trying to reconnect..."); - mysleep(ArOptions_get_arDelay(ClientRealm_get_arOptions(pointer))); + sleep(ArOptions_get_arDelay(ClientRealm_get_arOptions(pointer))); ClientRealm_set_realmType(pointer, realmType); } if (temp == 0) { @@ -1140,7 +1142,7 @@ main(int argc, char **argv) ClientRealm_closeUsersConnections(pointer); close(SslFd_get_fd(ClientRealm_get_masterSslFd(pointer))); SslFd_set_ssl(ClientRealm_get_masterSslFd(pointer), NULL); - mysleep(ArOptions_get_arDelay(ClientRealm_get_arOptions(pointer))); + sleep(ArOptions_get_arDelay(ClientRealm_get_arOptions(pointer))); aflog(LOG_T_CLIENT, LOG_I_INFO, "Trying to reconnect..."); @@ -1428,7 +1430,7 @@ main(int argc, char **argv) ClientRealm_closeUsersConnections(pointer); close(SslFd_get_fd(ClientRealm_get_masterSslFd(pointer))); SslFd_set_ssl(ClientRealm_get_masterSslFd(pointer), NULL); - mysleep(ArOptions_get_arDelay(ClientRealm_get_arOptions(pointer))); + sleep(ArOptions_get_arDelay(ClientRealm_get_arOptions(pointer))); aflog(LOG_T_CLIENT, LOG_I_INFO, "Trying to reconnect..."); diff --git a/src/http_proxy_functions.c b/src/http_proxy_functions.c index e7bef6f..3e53365 100644 --- a/src/http_proxy_functions.c +++ b/src/http_proxy_functions.c @@ -51,21 +51,6 @@ myrand(int down, int up) } /* - * Function name: mysleep - * Description: Sleeps for the given amount of milliseconds. - * Arguments: time - the amount of milliseconds to sleep for - */ - -void -mysleep(double time) -{ - struct timeval tv; - tv.tv_sec = (int) time; - tv.tv_usec = (int)(time * 1000000)%1000000; - select(0, NULL, NULL, NULL, &tv); -} - -/* * Function name: delete_user * Description: Deletes the user's connection from the http proxy connections. * Arguments: cnts - the connection to remove diff --git a/src/http_proxy_functions.h b/src/http_proxy_functions.h index 3d29699..1b10f9a 100644 --- a/src/http_proxy_functions.h +++ b/src/http_proxy_functions.h @@ -72,7 +72,6 @@ typedef struct { } connection; int myrand(int, int); -void mysleep(double); int parse_header(SslFd*, char*, header*, char); int read_message(int, int, connection*, char*, int); void delete_user(connection*, int, fd_set*); diff --git a/src/server_signals.c b/src/server_signals.c index 00f69bd..84cf5ec 100644 --- a/src/server_signals.c +++ b/src/server_signals.c @@ -28,6 +28,8 @@ #include "logging.h" #include "server_configuration_struct.h" +#include + extern ServerConfiguration* config; /* @@ -77,7 +79,12 @@ server_sig_int(int signo) } /* FIXME: give a time to close all connections */ - mysleep(0.1); + { + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 100000000; + nanosleep(&ts, NULL); + } aflog(LOG_T_MAIN, LOG_I_NOTICE, "SERVER CLOSED cg: %ld bytes", getcg()); -- cgit v1.1