From f409a5e841d91237fe4034818955dd88167a679b Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Mon, 15 Jul 2013 19:06:35 +0000 Subject: add a global tcp-keepalive-option. thanks to Fefe --- vchat-client.c | 2 ++ vchat-config.h | 1 + vchat-protocol.c | 7 ++++++- vchat.h | 3 ++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/vchat-client.c b/vchat-client.c index 71a596c..f5cd516 100755 --- a/vchat-client.c +++ b/vchat-client.c @@ -43,6 +43,8 @@ int status = 1; int ownquit = 0; /* we set this, we DONT want to quit */ int wantreconnect = 0; +unsigned int want_tcp_keepalive = 0; + static int reconnect_delay = 6; static time_t reconnect_time = 0; diff --git a/vchat-config.h b/vchat-config.h index 96fed27..8392d18 100755 --- a/vchat-config.h +++ b/vchat-config.h @@ -55,6 +55,7 @@ static volatile configoption configoptions[] = { {CF_BELLPRIV, CO_INT, "bellonpm", (char *) 0, (char *)-1, { NULL } }, {CF_CASEFIRST, CO_INT, "casefirst", (char *) 0, (char *)-1, { .pint = &ul_case_first } }, {CF_AUTORECONN, CO_INT, "autoreconn", (char *) 0, (char *)-1, { NULL } }, + {CF_KEEPALIVE, CO_INT, "keepalive", (char *) 0, (char *)-1, { .pint = &want_tcp_keepalive } }, {CF_NIL, CO_NIL, NULL, NULL, NULL, { NULL } }, }; diff --git a/vchat-protocol.c b/vchat-protocol.c index b9a5e15..b50f511 100755 --- a/vchat-protocol.c +++ b/vchat-protocol.c @@ -92,6 +92,11 @@ static int connect_socket( char *server, char *port ) { break; /* okay we got one */ } freeaddrinfo(res0); + + if (want_tcp_keepalive) { /* global from vchat-client.c */ + int one=1; + setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,&one,sizeof(one)); + } return s; } @@ -373,7 +378,7 @@ justloggedin (char *message) /* we're not logged in, change status and request nicks */ if (!loggedin) { - loadcfg(getstroption(CF_LOGINSCRIPT),handleline); + loadcfg(getstroption(CF_LOGINSCRIPT),0,handleline); handleline(".S"); loggedin = 1; } diff --git a/vchat.h b/vchat.h index 7b6e0d3..1a24973 100755 --- a/vchat.h +++ b/vchat.h @@ -33,7 +33,7 @@ typedef enum { CF_NIL, CF_NICK, CF_FROM, CF_SERVERHOST, CF_SERVERPORT, CF_CIPHERSUITE, CF_CONFIGFILE, CF_CERTFILE, CF_KEYFILE, CF_FORMFILE, CF_LOGINSCRIPT, CF_USESSL, CF_IGNSSL, CF_USECERT, CF_PRIVHEIGHT, CF_PRIVCOLLAPS, CF_HSCROLL, CF_CHANNEL, CF_USETIME, CF_USETOPIC, CF_SCROLLBPRIV, CF_SCROLLBACK, CF_SCROLLBPRIVT, CF_SCROLLBACKT, -CF_ENCODING, CF_BELLPRIV, CF_CASEFIRST, CF_AUTORECONN } confopt; +CF_ENCODING, CF_BELLPRIV, CF_CASEFIRST, CF_AUTORECONN, CF_KEEPALIVE } confopt; /* format strings */ typedef enum { FS_PLAIN, FS_CHAN, FS_PRIV, FS_SERV, FS_GLOB, FS_DBG, FS_ERR, @@ -75,6 +75,7 @@ typedef struct formatstring formatstring; static char tmpstr[TMPSTRSIZE]; extern unsigned int loggedin; +extern unsigned int want_tcp_keepalive; /* vchat-client.c */ #define ERRSTRSIZE 1024 -- cgit v1.2.3