Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Indent include and src using this command:
[simgrid.git] / src / gras / Transport / rl_transport.c
index 395137f..7b8ff2e 100644 (file)
@@ -1,8 +1,7 @@
-/* $Id$ */
-
 /* rl_transport - RL specific functions for transport                       */
 
-/* Copyright (c) 2004 Martin Quinson. All rights reserved.                  */
+/* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -28,7 +27,8 @@ gras_socket_t _gras_lastly_selected_socket = NULL;
 gras_socket_t gras_trp_select(double timeout)
 {
   xbt_dynar_t sockets =
-    ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->sockets;
+      ((gras_trp_procdata_t)
+       gras_libdata_by_id(gras_trp_libdata_id))->sockets;
   int done = -1;
   double wakeup = gras_os_time() + timeout;
   double now = 0;
@@ -48,9 +48,10 @@ gras_socket_t gras_trp_select(double timeout)
 
   /* Check whether there is more data to read from the socket we selected last time.
      This can happen with tcp buffered sockets since we try to get as much data as we can for them */
-  if (_gras_lastly_selected_socket && _gras_lastly_selected_socket->moredata) {
+  if (_gras_lastly_selected_socket
+      && _gras_lastly_selected_socket->moredata) {
     VERB0
-      ("Returning _gras_lastly_selected_socket since there is more data on it");
+        ("Returning _gras_lastly_selected_socket since there is more data on it");
     return _gras_lastly_selected_socket;
   }
 
@@ -63,7 +64,7 @@ gras_socket_t gras_trp_select(double timeout)
     fd_setsize = getdtablesize();
 #  else
     fd_setsize = FD_SETSIZE;
-#  endif /* !USE_SYSCONF */
+#  endif                        /* !USE_SYSCONF */
 #endif
   }
 
@@ -126,11 +127,12 @@ gras_socket_t gras_trp_select(double timeout)
     max_fds = fd_setsize;
 #endif
 
+    tout.tv_sec = tout.tv_usec = 0;
     if (timeout > 0) {
       /* set the timeout */
       tout.tv_sec = (unsigned long) (wakeup - now);
       tout.tv_usec =
-        ((wakeup - now) - ((unsigned long) (wakeup - now))) * 1000000;
+          ((wakeup - now) - ((unsigned long) (wakeup - now))) * 1000000;
       p_tout = &tout;
     } else if (timeout == 0) {
       /* polling only */
@@ -144,7 +146,8 @@ gras_socket_t gras_trp_select(double timeout)
       p_tout = NULL;
     }
 
-    DEBUG2("Selecting over %d socket(s); timeout=%f", max_fds - 1, timeout);
+    DEBUG2("Selecting over %d socket(s); timeout=%f", max_fds - 1,
+           timeout);
     ready = select(max_fds, &FDS, NULL, NULL, p_tout);
     DEBUG1("select returned %d", ready);
     if (ready == -1) {