Mercurial > hg
changeset 112:edb5591e2e64
[/trunk] Changeset 126 by mikael
* Fix keepalive.
author | mikael |
---|---|
date | Sun, 24 Apr 2005 17:38:48 +0000 |
parents | d896962c16fa |
children | 8ac67e951eab |
files | mcabber/connwrap/connwrap.c mcabber/src/TODO mcabber/src/jabglue.c mcabber/src/jabglue.h mcabber/src/main.c |
diffstat | 5 files changed, 44 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/mcabber/connwrap/connwrap.c Sat Apr 23 21:12:36 2005 +0000 +++ b/mcabber/connwrap/connwrap.c Sun Apr 24 17:38:48 2005 +0000 @@ -7,6 +7,7 @@ #include <arpa/inet.h> #include <fcntl.h> #include <sys/time.h> +#include <unistd.h> #define PROXY_TIMEOUT 10 // HTTP proxy timeout in seconds (for the CONNECT method)
--- a/mcabber/src/TODO Sat Apr 23 21:12:36 2005 +0000 +++ b/mcabber/src/TODO Sun Apr 24 17:38:48 2005 +0000 @@ -3,6 +3,7 @@ * Should not stay on buddy buffer when one moves to a group * Pending message not displayed if buddy outside Contact window +* Check keepalive TODO:
--- a/mcabber/src/jabglue.c Sat Apr 23 21:12:36 2005 +0000 +++ b/mcabber/src/jabglue.c Sun Apr 24 17:38:48 2005 +0000 @@ -31,8 +31,11 @@ #define JABBERSSLPORT 5223 jconn jc; +time_t LastPingTime; +unsigned int KeepaliveDelay; static int s_id = 1; // FIXME which use?? static int regmode, regdone; +unsigned char online; char imstatus2char[imstatus_size] = { '_', 'o', 'i', 'f', 'd', 'c', 'n', 'a' @@ -116,7 +119,7 @@ jab_state_handler(jc, &statehandler); if (jc->user) { - //fonline = TRUE; + online = TRUE; jstate = STATE_CONNECTING; statehandler(0, -1); jab_start(jc); @@ -130,12 +133,24 @@ statehandler(jc, JCONN_STATE_OFF); } +inline void jb_reset_keepalive() +{ + time(&LastPingTime); +} + void jb_keepalive() { if (jc) { // XXX Only if connected... - jab_send_raw(jc, " "); + jab_send_raw(jc, " \t "); + scr_LogPrint("Sent keepalive"); } + jb_reset_keepalive(); +} + +void jb_set_keepalive_delay(unsigned int delay) +{ + KeepaliveDelay = delay; } void jb_main() @@ -143,6 +158,8 @@ xmlnode x, z; char *cid; + if (!online) + return; if (jc && jc->state == JCONN_STATE_CONNECTING) { jab_start(jc); return; @@ -167,7 +184,7 @@ if (!jc || jc->state == JCONN_STATE_OFF) { scr_LogPrint("Unable to connect to the server"); - // fonline = FALSE; + online = FALSE; } } @@ -176,6 +193,14 @@ } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) { statehandler(jc, JCONN_STATE_OFF); } + + // Keepalive + if (KeepaliveDelay) { + time_t now; + time(&now); + if (now > LastPingTime + KeepaliveDelay) + jb_keepalive(); + } } void setjabberstatus(enum imstatus st, char *msg) @@ -362,7 +387,7 @@ switch(state) { case JCONN_STATE_OFF: - /* jhook.flogged = jhook.fonline = FALSE; */ + online = FALSE; if (previous_state != JCONN_STATE_OFF) { scr_LogPrint("+ JCONN_STATE_OFF"); @@ -383,7 +408,7 @@ case JCONN_STATE_ON: scr_LogPrint("+ JCONN_STATE_ON"); - // if (regmode) jhook.fonline = TRUE; + online = TRUE; break; case JCONN_STATE_CONNECTING: @@ -407,6 +432,7 @@ enum imstatus ust; // int npos; + jb_reset_keepalive(); // reset keepalive delay jpacket_reset(packet); p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p;
--- a/mcabber/src/jabglue.h Sat Apr 23 21:12:36 2005 +0000 +++ b/mcabber/src/jabglue.h Sun Apr 24 17:38:48 2005 +0000 @@ -29,8 +29,10 @@ jconn jb_connect(const char *jid, unsigned int port, int ssl, const char *pass); void jb_disconnect(void); -void jb_keepalive(); void jb_main(); void jb_send_msg(const char *, const char *); +void jb_keepalive(); +inline void jb_reset_keepalive(); +void jb_set_keepalive_delay(unsigned int delay); #endif /* __JABGLUE_H__ */
--- a/mcabber/src/main.c Sat Apr 23 21:12:36 2005 +0000 +++ b/mcabber/src/main.c Sun Apr 24 17:38:48 2005 +0000 @@ -18,21 +18,14 @@ void sig_handler(int signum) { - switch (signum) { - case SIGALRM: - jb_keepalive(); - break; - - case SIGTERM: + if (signum == SIGTERM) { // bud_TerminateBuddies(); scr_TerminateCurses(); jb_disconnect(); printf("Killed by SIGTERM\nBye!\n"); exit(EXIT_SUCCESS); - break; - } - signal(SIGALRM, sig_handler); + ut_WriteLog("Caught signal: %d\n", signum); } ssize_t my_getpass (char **passstr, size_t *n) @@ -177,15 +170,12 @@ return -2; } - ping = 20; + ping = 40; if (cfg_read("pinginterval")) ping = (unsigned int) atoi(cfg_read("pinginterval")); - + jb_set_keepalive_delay(ping); ut_WriteLog("Ping interval stablished: %d secs\n", ping); - ut_WriteLog("Entering into main loop...\n\n"); - ut_WriteLog("Ready to send/receive messages...\n"); - optstring = cfg_read("hide_offline_buddies"); if (optstring && (atoi(optstring) > 0)) buddylist_hide_offline_buddies(TRUE); @@ -193,9 +183,12 @@ /* Initialize commands system */ cmd_init(); + ut_WriteLog("Entering into main loop...\n\n"); + ut_WriteLog("Ready to send/receive messages...\n"); + + jb_reset_keepalive(); keypad(scr_GetInputWindow(), TRUE); while (ret != 255) { - alarm(ping); key = scr_Getch(); if (key != ERR) ret = process_key(key);