From 1ab3563b9f429a75fbbdc95c6d3405fc4368d876 Mon Sep 17 00:00:00 2001 From: mquinson Date: Tue, 21 Nov 2006 16:52:08 +0000 Subject: [PATCH] Compute fd_setsize only once, and not on each select git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2937 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/gras/Transport/rl_transport.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/gras/Transport/rl_transport.c b/src/gras/Transport/rl_transport.c index 8b7c9d7151..098a2355f9 100644 --- a/src/gras/Transport/rl_transport.c +++ b/src/gras/Transport/rl_transport.c @@ -40,7 +40,7 @@ gras_socket_t gras_trp_select(double timeout) { with this tiny optimisation on BillWare */ fd_set FDS; int ready; /* return of select: number of socket ready to be serviced */ - int fd_setsize; /* FD_SETSIZE not always defined. Get this portably */ + static int fd_setsize=-1; /* FD_SETSIZE not always defined. Get this portably */ gras_socket_t sock_iter; /* iterating over all sockets */ int cursor; /* iterating over all sockets */ @@ -52,16 +52,18 @@ gras_socket_t gras_trp_select(double timeout) { return _gras_lastly_selected_socket; } - /* Compute FD_SETSIZE */ + /* Compute FD_SETSIZE on need */ + if (fd_setsize < 0) { #ifdef HAVE_SYSCONF - fd_setsize = sysconf( _SC_OPEN_MAX ); + fd_setsize = sysconf( _SC_OPEN_MAX ); #else # ifdef HAVE_GETDTABLESIZE - fd_setsize = getdtablesize(); + fd_setsize = getdtablesize(); # else - fd_setsize = FD_SETSIZE; + fd_setsize = FD_SETSIZE; # endif /* !USE_SYSCONF */ #endif + } while (done == -1) { if (timeout > 0) { /* did we timeout already? */ -- 2.20.1