Author: tjansen Date: Wed Oct 21 15:09:07 2009 New Revision: 1257 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. Modified: trunk/pisasd/sdmain.c Modified: trunk/pisasd/sdmain.c ============================================================================== --- trunk/pisasd/sdmain.c Wed Oct 21 14:22:27 2009 (r1256) +++ trunk/pisasd/sdmain.c Wed Oct 21 15:09:07 2009 (r1257) @@ -273,15 +273,18 @@ static inline void sd_do_main(void) { struct sockaddr_in from_addr; + int maxfd; memset(&from_addr, 0, sizeof(struct sockaddr_in)); + maxfd = 1 + pisa_maxof(5, sd_ctx.tunc, sd_ctx.tund, sd_ctx.tunnel, + sd_ctx.tunnel, sd_ctx.scheduler.pipe_main[0]); + sd_ctx.is_sd_running = TRUE; PISA_INFO("\nEntering main loop\n"); while (sd_ctx.is_sd_running) { - fd_set readfds; - int maxfd = 0; + fd_set readfds; pisa_sd_timeout_collect(); @@ -293,14 +296,7 @@ FD_SET(sd_ctx.fd_pisaconf, &readfds); FD_SET(sd_ctx.scheduler.pipe_main[0], &readfds); - /* Performance optimization: Does this really have to be - * recalcutated every time? Check again after PREAUTH is - * removed. -- Thomas */ - maxfd = 1 + pisa_maxof(5, sd_ctx.tunc, sd_ctx.tund, - sd_ctx.tunnel,sd_ctx.tunnel, - sd_ctx.scheduler.pipe_main[0]); - - if (select(maxfd + 1, &readfds, NULL, NULL, NULL) > 0) { + if (select(maxfd, &readfds, NULL, NULL, NULL) > 0) { if (FD_ISSET(sd_ctx.tunc, &readfds)) pisa_ctrlhandler_dispatch(&sd_ctx.ctrlhandlers, sd_ctx.tunc);