Mercurial > hg
diff mcabber/src/jabglue.c @ 939:12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
This patch from Christof Meerwald, slightly modified, reduces mcabber CPU
usage and the number of context switches per second.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Tue, 11 Jul 2006 22:50:48 +0200 |
parents | a07bd351008b |
children | fc30221b952d |
line wrap: on
line diff
--- a/mcabber/src/jabglue.c Sat Jul 08 23:32:49 2006 +0200 +++ b/mcabber/src/jabglue.c Tue Jul 11 22:50:48 2006 +0200 @@ -168,6 +168,9 @@ void jb_main() { time_t now; + fd_set fds; + long autoaway_timeout; + struct timeval tv; static time_t last_eviqs_check = 0; if (!online) { @@ -181,7 +184,30 @@ return; } - jab_poll(jc, 50); + FD_ZERO(&fds); + FD_SET(0, &fds); + FD_SET(jc->fd, &fds); + + tv.tv_sec = 60; + tv.tv_usec = 0; + + if (KeepaliveDelay) { + time(&now); + if (now > LastPingTime + (time_t)KeepaliveDelay) { + tv.tv_sec = 0; + } else { + tv.tv_sec = LastPingTime + (time_t)KeepaliveDelay - now; + } + } + + autoaway_timeout = scr_GetAutoAwayTimeout(); + if (tv.tv_sec > autoaway_timeout) + tv.tv_sec = autoaway_timeout; + + if (select(jc->fd + 1, &fds, NULL, NULL, &tv) > 0) { + if (FD_ISSET(jc->fd, &fds)) + jab_poll(jc, 0); + } if (jstate == STATE_CONNECTING) { if (jc) {