comparison mcabber/src/jabglue.c @ 1439:fd09c95bc2b5

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.
author Mikael Berthe <mikael@lilotux.net>
date Tue, 26 Feb 2008 22:28:16 +0100
parents 9bf7f3ddff10
children 49c8be874344
comparison
equal deleted inserted replaced
1438:c5d937d5530b 1439:fd09c95bc2b5
233 time_t now; 233 time_t now;
234 fd_set fds; 234 fd_set fds;
235 long tmout; 235 long tmout;
236 struct timeval tv; 236 struct timeval tv;
237 static time_t last_eviqs_check = 0L; 237 static time_t last_eviqs_check = 0L;
238 int maxfd; 238 int maxfd = 0;
239 #ifdef ENABLE_FIFO 239 #ifdef ENABLE_FIFO
240 int fifofd; 240 int fifofd;
241 #endif 241 #endif
242 242
243 if (!online) {
244 safe_usleep(10000);
245 check_connection();
246 return;
247 }
248
249 if (jc && jc->state == JCONN_STATE_CONNECTING) {
250 safe_usleep(75000);
251 jab_start(jc);
252 return;
253 }
254
255 FD_ZERO(&fds); 243 FD_ZERO(&fds);
256 FD_SET(0, &fds); 244 FD_SET(0, &fds);
257 FD_SET(jc->fd, &fds); 245 if (jc && jc->fd > 0) {
258 maxfd = jc->fd; 246 FD_SET(jc->fd, &fds);
247 maxfd = jc->fd;
248 }
259 249
260 #ifdef ENABLE_FIFO 250 #ifdef ENABLE_FIFO
261 fifofd = fifo_get_fd(); 251 fifofd = fifo_get_fd();
262 if (fifofd > 0) { 252 if (fifofd > 0) {
263 FD_SET(fifofd, &fds); 253 FD_SET(fifofd, &fds);
265 } 255 }
266 #endif 256 #endif
267 257
268 tv.tv_sec = 60; 258 tv.tv_sec = 60;
269 tv.tv_usec = 0; 259 tv.tv_usec = 0;
260
261 if (!online || (jc && jc->state == JCONN_STATE_CONNECTING)) {
262 if (online) {
263 // We're connecting and we need to reduce the timeout.
264 tv.tv_sec = 0;
265 tv.tv_usec = 250000;
266 } else {
267 tv.tv_sec = 30;
268 // Let's first update the screen, we could sleep for a long time...
269 scr_DoUpdate();
270 }
271 // If we're not connected, sleep for a while...
272 select(maxfd + 1, &fds, NULL, NULL, &tv);
273 if (!online)
274 check_connection();
275 else
276 jab_start(jc);
277 return;
278 }
270 279
271 time(&now); 280 time(&now);
272 281
273 if (KeepaliveDelay) { 282 if (KeepaliveDelay) {
274 if (now >= LastPingTime + (time_t)KeepaliveDelay) 283 if (now >= LastPingTime + (time_t)KeepaliveDelay)