From e9eee1fe3cb2cd0068f549a7cd46843d4c95c6f3 Mon Sep 17 00:00:00 2001 From: short <> Date: Sat, 5 Jun 2004 19:52:42 +0000 Subject: [PATCH] Try probing the server indefinitely from commandline. Try probing the server max 10 seconds from GnomeUI. Increase the probing timeout exponentially to prevent on-demand dialups hogging. --- src/network.c | 41 +++++++++++++++++++++++++++++++++-------- src/network.h | 1 + src/ui-gnome.c | 2 ++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/network.c b/src/network.c index 3dd363b..4d2ba2f 100644 --- a/src/network.c +++ b/src/network.c @@ -50,9 +50,10 @@ #define SERVER_INADDR 0x511F02EA /* paulina.vellum.cz = 81.31.2.234; host order */ #define SERVER_PORT 9201 /* host order */ #define PROBE_INADDR SERVER_INADDR /* host order */ -#define PROBE_PORT 8201 /* host order */ +#define PROBE_PORT 8202 /* host order */ #define CLIENT_TIMEOUT_SEC (5*60) -#define PROBE_TIMEOUT_SEC (5) +#define PROBE_TIMEOUT_SEC_BASE 5 +#define PROBE_TIMEOUT_SEC_MAX 3500 void (*network_notify_hostip)(guint32 hostip_guint32); @@ -70,6 +71,9 @@ static GList *sock_client_list; /* of 'struct client *', incl. 'master' and 'pro static struct client *master; /* no 'timeout' permitted */ static struct client *probe; /* 'timeout' permitted */ static guint32 probe_unique; +static guint probe_timeout_sec_now; +guint probe_timeout_sec_max=G_MAXUINT; +static gint port_local; /* for 'probe' resends */ static gboolean write_daemon_running(pid_t pid); @@ -142,14 +146,15 @@ gboolean errgboolean; static gboolean client_touch_timeout(struct client *client); -static void client_touch(struct client *client) +static void client_touch(struct client *client,guint timeout_sec) { g_return_if_fail(client!=NULL); g_return_if_fail(client!=master); + g_return_if_fail(timeout_sec>0); client_timeout_remove(client); client->timeout_id=g_timeout_add( - (client==probe ? PROBE_TIMEOUT_SEC*1000 : CLIENT_TIMEOUT_SEC*1000), /* interval; msec */ + timeout_sec*1000, /* interval; msec */ (GSourceFunc)client_touch_timeout, /* function */ client); /* data */ if (optarg_verbose) @@ -158,6 +163,7 @@ static void client_touch(struct client *client) } static void client_destroy(struct client *client); +static gboolean probe_send(struct client *probe,gint port_local); static gboolean client_touch_timeout(struct client *client) { @@ -174,6 +180,17 @@ static gboolean client_touch_timeout(struct client *client) client->timeout_id=0; if (client==probe) { + if (probe_timeout_sec_nownext) { @@ -276,7 +296,7 @@ GList *clientl; client=client_new(); client->sockaddr_in_from=sockaddr_in_from; } - client_touch(client); + client_touch(client,CLIENT_TIMEOUT_SEC); UDPGATE_MEMZERO(&sockaddr_in_server); sockaddr_in_server.sin_family=AF_INET; sockaddr_in_server.sin_port=htons(SERVER_PORT); @@ -340,7 +360,7 @@ socklen_t sockaddr_in_from_length; break; if (sockaddr_in_from_length!=sizeof(sockaddr_in_from)) /* FIXME: errors reporting */ continue; - client_touch(client); + client_touch(client,CLIENT_TIMEOUT_SEC); /* FIXME: errors checking */ sendto( master->gpollfd.fd, /* s */ @@ -579,8 +599,13 @@ static gboolean probe_start(gint port) /* Setup 'probe': */ if (!(probe=client_new())) return FALSE; - probe_send(probe,port); - client_touch(probe); /* timeout */ + port_local=port; + if (!probe_send(probe,port)) { + client_destroy(probe); + return FALSE; + } + probe_timeout_sec_now=PROBE_TIMEOUT_SEC_BASE; + client_touch(probe,probe_timeout_sec_now); /* timeout */ return TRUE; } diff --git a/src/network.h b/src/network.h index c341ae7..85101f8 100644 --- a/src/network.h +++ b/src/network.h @@ -34,6 +34,7 @@ gboolean optarg_port_set_string(const gchar *string); gboolean network_stop(void); extern void (*network_notify_hostip)(guint32 hostip_guint32); gboolean network_detach(void); +extern guint probe_timeout_sec_max; G_END_DECLS diff --git a/src/ui-gnome.c b/src/ui-gnome.c index 4c0c8ef..88ecfe1 100644 --- a/src/ui-gnome.c +++ b/src/ui-gnome.c @@ -49,6 +49,7 @@ #define EXTERNAL_STARTUP_CHECK_INTERVAL_MS 1000 #define PORT_RANGE_BEGIN 2048 #define PORT_RANGE_END 10240 +#define UI_GNOME_PROBE_TIMEOUT_SEC 10 static GnomeApp *App; @@ -217,6 +218,7 @@ GtkWidget *dialog; static void ui_gnome_interactive(void) { + probe_timeout_sec_max=UI_GNOME_PROBE_TIMEOUT_SEC; gtk_main(); network_notify_hostip=NULL; g_log_remove_handler( -- 1.8.3.1