# HG changeset patch # User Mikael Berthe # Date 1204061296 -3600 # Node ID fd09c95bc2b5b54c24a6b60496ceca08717a31e5 # Parent c5d937d5530b5678ac12ecb8b725aee667209bcb Wake up less often when not connected to the server When mcabber isn't connected to a server, it sleeps for very short periods, which isn't very efficient. This patch removes the safe_usleep() calls. Problem reported by Peter Somogyi. diff -r c5d937d5530b -r fd09c95bc2b5 mcabber/src/jabglue.c --- a/mcabber/src/jabglue.c Mon Feb 25 21:39:07 2008 +0100 +++ b/mcabber/src/jabglue.c Tue Feb 26 22:28:16 2008 +0100 @@ -235,27 +235,17 @@ long tmout; struct timeval tv; static time_t last_eviqs_check = 0L; - int maxfd; + int maxfd = 0; #ifdef ENABLE_FIFO int fifofd; #endif - if (!online) { - safe_usleep(10000); - check_connection(); - return; - } - - if (jc && jc->state == JCONN_STATE_CONNECTING) { - safe_usleep(75000); - jab_start(jc); - return; - } - FD_ZERO(&fds); FD_SET(0, &fds); - FD_SET(jc->fd, &fds); - maxfd = jc->fd; + if (jc && jc->fd > 0) { + FD_SET(jc->fd, &fds); + maxfd = jc->fd; + } #ifdef ENABLE_FIFO fifofd = fifo_get_fd(); @@ -268,6 +258,25 @@ tv.tv_sec = 60; tv.tv_usec = 0; + if (!online || (jc && jc->state == JCONN_STATE_CONNECTING)) { + if (online) { + // We're connecting and we need to reduce the timeout. + tv.tv_sec = 0; + tv.tv_usec = 250000; + } else { + tv.tv_sec = 30; + // Let's first update the screen, we could sleep for a long time... + scr_DoUpdate(); + } + // If we're not connected, sleep for a while... + select(maxfd + 1, &fds, NULL, NULL, &tv); + if (!online) + check_connection(); + else + jab_start(jc); + return; + } + time(&now); if (KeepaliveDelay) {