Author: tjansen Date: Wed Oct 21 17:48:19 2009 New Revision: 1266 Log: Performance optimization in pisasd main loop. maxfd is the highest file descriptor (+1) for the select call. Since the list of file descriptors is known before the while loop and does not change within, it is not necessary to recompute the maximum before each select call. This is a port of commit 1257 to pisacd. Modified: trunk/pisacd/cdmain.c Modified: trunk/pisacd/cdmain.c ============================================================================== --- trunk/pisacd/cdmain.c Wed Oct 21 17:41:07 2009 (r1265) +++ trunk/pisacd/cdmain.c Wed Oct 21 17:48:19 2009 (r1266) @@ -242,7 +242,7 @@ */ static inline void cd_do_main(void) { - int maxfd = 0; + int maxfd; int ret = 0; int pending = 0; fd_set readfds; @@ -253,6 +253,9 @@ PISA_INFO("\nEntering main loop\n"); + /* TODO Inline this if we can get rid of the ifdef. -- Thomas */ + maxfd = cd_get_maxfd() + 1; + while (cd_ctx.is_cd_running || pending) { /* sockets.tunnel needs to be always included in the reading fd list */ FD_ZERO(&readfds); @@ -262,11 +265,7 @@ FD_SET(cd_ctx.fd_pisaconf, &readfds); FD_SET(cd_ctx.scheduler.pipe_main[0], &readfds); - /* TODO this is just a maxof, no need for a separate function. - * Inline once PREAUTH is gone. -- Thomas */ - maxfd = cd_get_maxfd(); - - if ((ret = select(maxfd + 1, &readfds, NULL, NULL, NULL)) > 0) { + if ((ret = select(maxfd, &readfds, NULL, NULL, NULL)) > 0) { if (cd_ctx.is_cd_running) { if (FD_ISSET(cd_ctx.tunnel, &readfds)) pisa_cd_copy_from_tun_to_sock();