Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use CATCH_ANONYMOUS whenever possible, and remove unused variables.
[simgrid.git] / src / gras / Transport / transport.c
index 3d159d1..7c3c4e9 100644 (file)
@@ -32,7 +32,7 @@ static void gras_trp_plugin_new(const char *name, gras_trp_setup_t setup)
 
   gras_trp_plugin_t plug = xbt_new0(s_gras_trp_plugin_t, 1);
 
-  DEBUG1("Create plugin %s", name);
+  XBT_DEBUG("Create plugin %s", name);
 
   plug->name = xbt_strdup(name);
 
@@ -67,8 +67,9 @@ void gras_trp_init(void)
       WSADATA wsaData;
 
       wVersionRequested = MAKEWORD(2, 0);
-      xbt_assert0(WSAStartup(wVersionRequested, &wsaData) == 0,
-                  "Cannot find a usable WinSock DLL");
+      int res;
+      res = WSAStartup(wVersionRequested, &wsaData);
+      xbt_assert(res == 0, "Cannot find a usable WinSock DLL");
 
       /* Confirm that the WinSock DLL supports 2.0. */
       /* Note that if the DLL supports versions greater    */
@@ -76,17 +77,18 @@ void gras_trp_init(void)
       /* 2.0 in wVersion since that is the version we      */
       /* requested.                                        */
 
-      xbt_assert0(LOBYTE(wsaData.wVersion) == 2 &&
+      xbt_assert(LOBYTE(wsaData.wVersion) == 2 &&
                   HIBYTE(wsaData.wVersion) == 0,
                   "Cannot find a usable WinSock DLL");
-      INFO0("Found and initialized winsock2");
+      XBT_INFO("Found and initialized winsock2");
     }                           /* The WinSock DLL is acceptable. Proceed. */
 #elif HAVE_WINSOCK_H
     {
       WSADATA wsaData;
-      xbt_assert0(WSAStartup(0x0101, &wsaData) == 0,
-                  "Cannot find a usable WinSock DLL");
-      INFO0("Found and initialized winsock");
+      int res;
+      res = WSAStartup(0x0101, &wsaData);
+      xbt_assert(res == 0, "Cannot find a usable WinSock DLL");
+      XBT_INFO("Found and initialized winsock");
     }
 #endif
 
@@ -101,7 +103,7 @@ void gras_trp_init(void)
 
 void gras_trp_exit(void)
 {
-  DEBUG1("gras_trp value %d", _gras_trp_started);
+  XBT_DEBUG("gras_trp value %d", _gras_trp_started);
   if (_gras_trp_started == 0) {
     return;
   }
@@ -130,7 +132,7 @@ void gras_trp_plugin_free(void *p)
     if (plug->exit) {
       plug->exit(plug);
     } else if (plug->data) {
-      DEBUG1("Plugin %s lacks exit(). Free data anyway.", plug->name);
+      XBT_DEBUG("Plugin %s lacks exit(). Free data anyway.", plug->name);
       free(plug->data);
     }
 
@@ -150,7 +152,7 @@ void gras_trp_socket_new(int incoming, gras_socket_t * dst)
 
   gras_socket_t sock = xbt_new0(s_gras_socket_t, 1);
 
-  VERB1("Create a new socket (%p)", (void *) sock);
+  XBT_VERB("Create a new socket (%p)", (void *) sock);
 
   sock->plugin = NULL;
 
@@ -170,7 +172,7 @@ void gras_trp_socket_new(int incoming, gras_socket_t * dst)
 
   *dst = sock;
 
-  XBT_OUT;
+  XBT_OUT();
 }
 
 /**
@@ -185,12 +187,10 @@ gras_socket_t
 gras_socket_server_ext(unsigned short port,
                        unsigned long int buf_size, int measurement)
 {
-
-  xbt_ex_t e;
   gras_trp_plugin_t trp;
   gras_socket_t sock;
 
-  DEBUG2("Create a server socket from plugin %s on port %d",
+  XBT_DEBUG("Create a server socket from plugin %s on port %d",
          gras_if_RL()? "tcp" : "sg", port);
   trp = gras_trp_plugin_get_by_name(gras_if_SG()? "sg" : "tcp");
 
@@ -201,14 +201,14 @@ gras_socket_server_ext(unsigned short port,
   sock->meas = measurement;
 
   /* Call plugin socket creation function */
-  DEBUG1("Prepare socket with plugin (fct=%p)", trp->socket_server);
+  XBT_DEBUG("Prepare socket with plugin (fct=%p)", trp->socket_server);
   TRY {
     trp->socket_server(trp, port, sock);
-    DEBUG3("in=%c out=%c accept=%c",
+    XBT_DEBUG("in=%c out=%c accept=%c",
            sock->incoming ? 'y' : 'n',
            sock->outgoing ? 'y' : 'n', sock->accepting ? 'y' : 'n');
-  } CATCH(e) {
-
+  }
+  CATCH_ANONYMOUS {
     free(sock);
     RETHROW;
   }
@@ -272,14 +272,12 @@ gras_socket_client_ext(const char *host,
                        unsigned short port,
                        unsigned long int buf_size, int measurement)
 {
-
-  xbt_ex_t e;
   gras_trp_plugin_t trp;
   gras_socket_t sock;
 
   trp = gras_trp_plugin_get_by_name(gras_if_SG()? "sg" : "tcp");
 
-  DEBUG1("Create a client socket from plugin %s",
+  XBT_DEBUG("Create a client socket from plugin %s",
          gras_if_RL()? "tcp" : "sg");
   /* defaults settings */
   gras_trp_socket_new(0, &sock);
@@ -290,10 +288,11 @@ gras_socket_client_ext(const char *host,
   /* plugin-specific */
   TRY {
     (*trp->socket_client) (trp,host,port,sock);
-    DEBUG3("in=%c out=%c accept=%c",
+    XBT_DEBUG("in=%c out=%c accept=%c",
            sock->incoming ? 'y' : 'n',
            sock->outgoing ? 'y' : 'n', sock->accepting ? 'y' : 'n');
-  } CATCH(e) {
+  }
+  CATCH_ANONYMOUS {
     free(sock);
     RETHROW;
   }
@@ -346,27 +345,27 @@ void gras_socket_close(gras_socket_t sock)
   gras_socket_t sock_iter = NULL;
   unsigned int cursor;
 
-  XBT_IN;
-  VERB1("Close %p", sock);
+  XBT_IN("");
+  XBT_VERB("Close %p", sock);
   if (sock == _gras_lastly_selected_socket) {
-    xbt_assert0(!gras_opt_trp_nomoredata_on_close || !sock->moredata,
+    xbt_assert(!gras_opt_trp_nomoredata_on_close || !sock->moredata,
                 "Closing a socket having more data in buffer while the nomoredata_on_close option is activated");
 
     if (sock->moredata)
-      CRITICAL0
+      XBT_CRITICAL
           ("Closing a socket having more data in buffer. Option nomoredata_on_close disabled, so continuing.");
     _gras_lastly_selected_socket = NULL;
   }
 
   /* FIXME: Issue an event when the socket is closed */
-  DEBUG1("sockets pointer before %p", sockets);
+  XBT_DEBUG("sockets pointer before %p", sockets);
   if (sock) {
     /* FIXME: Cannot get the dynar mutex, because it can be already locked */
 //              _xbt_dynar_foreach(sockets,cursor,sock_iter) {
     for (cursor = 0; cursor < xbt_dynar_length(sockets); cursor++) {
       _xbt_dynar_cursor_get(sockets, cursor, &sock_iter);
       if (sock == sock_iter) {
-        DEBUG2("remove sock cursor %d dize %lu\n", cursor,
+        XBT_DEBUG("remove sock cursor %d dize %lu\n", cursor,
                xbt_dynar_length(sockets));
         xbt_dynar_cursor_rm(sockets, &cursor);
         if (sock->plugin->socket_close)
@@ -374,16 +373,16 @@ void gras_socket_close(gras_socket_t sock)
 
         /* free the memory */
         free(sock);
-        XBT_OUT;
+        XBT_OUT();
         return;
       }
     }
-    WARN1
+    XBT_WARN
         ("Ignoring request to free an unknown socket (%p). Execution stack:",
          sock);
     xbt_backtrace_display_current();
   }
-  XBT_OUT;
+  XBT_OUT();
 }
 
 /**
@@ -394,7 +393,7 @@ void gras_socket_close(gras_socket_t sock)
  */
 void gras_trp_send(gras_socket_t sd, char *data, long int size, int stable)
 {
-  xbt_assert0(sd->outgoing, "Socket not suited for data send");
+  xbt_assert(sd->outgoing, "Socket not suited for data send");
   (*sd->plugin->send) (sd, data, size, stable);
 }
 
@@ -405,7 +404,7 @@ void gras_trp_send(gras_socket_t sd, char *data, long int size, int stable)
  */
 void gras_trp_recv(gras_socket_t sd, char *data, long int size)
 {
-  xbt_assert0(sd->incoming, "Socket not suited for data receive");
+  xbt_assert(sd->incoming, "Socket not suited for data receive");
   (sd->plugin->recv) (sd, data, size);
 }
 
@@ -428,7 +427,7 @@ gras_trp_plugin_t gras_trp_plugin_get_by_name(const char *name)
 int gras_socket_my_port(gras_socket_t sock)
 {
   if (!sock->plugin->my_port)
-    THROW1(unknown_error,0,"Function my_port unimplemented in plugin %s",sock->plugin->name);
+    THROWF(unknown_error,0,"Function my_port unimplemented in plugin %s",sock->plugin->name);
   return (*sock->plugin->my_port)(sock);
 
 }
@@ -436,7 +435,7 @@ int gras_socket_my_port(gras_socket_t sock)
 int gras_socket_peer_port(gras_socket_t sock)
 {
   if (!sock->plugin->peer_port)
-    THROW1(unknown_error,0,"Function peer_port unimplemented in plugin %s",sock->plugin->name);
+    THROWF(unknown_error,0,"Function peer_port unimplemented in plugin %s",sock->plugin->name);
   return (*sock->plugin->peer_port)(sock);
 }
 
@@ -489,25 +488,25 @@ void gras_socket_meas_send(gras_socket_t peer,
   char *chunk = NULL;
   unsigned long int sent_sofar;
 
-  XBT_IN;
-  THROW0(unknown_error,0,"measurement sockets were broken in this release of SimGrid and should be ported back in the future."
+  XBT_IN("");
+  THROWF(unknown_error,0,"measurement sockets were broken in this release of SimGrid and should be ported back in the future."
       "If you depend on it, sorry, you have to use an older version, or wait for the future version using it...");
   if (gras_if_RL())
     chunk = xbt_malloc0(msg_size);
 
-  xbt_assert0(peer->meas,
+  xbt_assert(peer->meas,
               "Asked to send measurement data on a regular socket");
-  xbt_assert0(peer->outgoing,
+  xbt_assert(peer->outgoing,
               "Socket not suited for data send (was created with gras_socket_server(), not gras_socket_client())");
 
   for (sent_sofar = 0; sent_sofar < msg_amount; sent_sofar++) {
-    CDEBUG5(gras_trp_meas,
+    XBT_CDEBUG(gras_trp_meas,
             "Sent %lu msgs of %lu (size of each: %ld) to %s:%d",
             sent_sofar, msg_amount, msg_size, gras_socket_peer_name(peer),
             gras_socket_peer_port(peer));
     (*peer->plugin->raw_send) (peer, chunk, msg_size);
   }
-  CDEBUG5(gras_trp_meas,
+  XBT_CDEBUG(gras_trp_meas,
           "Sent %lu msgs of %lu (size of each: %ld) to %s:%d", sent_sofar,
           msg_amount, msg_size, gras_socket_peer_name(peer),
           gras_socket_peer_port(peer));
@@ -515,7 +514,7 @@ void gras_socket_meas_send(gras_socket_t peer,
   if (gras_if_RL())
     free(chunk);
 
-  XBT_OUT;
+  XBT_OUT();
 }
 
 /** \brief Receive a chunk of data over a measurement socket
@@ -537,32 +536,32 @@ void gras_socket_meas_recv(gras_socket_t peer,
   char *chunk = NULL;
   unsigned long int got_sofar;
 
-  XBT_IN;
-  THROW0(unknown_error,0,"measurement sockets were broken in this release of SimGrid and should be ported back in the future."
+  XBT_IN("");
+  THROWF(unknown_error,0,"measurement sockets were broken in this release of SimGrid and should be ported back in the future."
       "If you depend on it, sorry, you have to use an older version, or wait for the future version using it...");
 
   if (gras_if_RL())
     chunk = xbt_malloc(msg_size);
 
-  xbt_assert0(peer->meas,
+  xbt_assert(peer->meas,
               "Asked to receive measurement data on a regular socket");
-  xbt_assert0(peer->incoming, "Socket not suited for data receive");
+  xbt_assert(peer->incoming, "Socket not suited for data receive");
 
   for (got_sofar = 0; got_sofar < msg_amount; got_sofar++) {
-    CDEBUG5(gras_trp_meas,
+    XBT_CDEBUG(gras_trp_meas,
             "Recvd %ld msgs of %lu (size of each: %ld) from %s:%d",
             got_sofar, msg_amount, msg_size, gras_socket_peer_name(peer),
             gras_socket_peer_port(peer));
     (peer->plugin->raw_recv) (peer, chunk, msg_size);
   }
-  CDEBUG5(gras_trp_meas,
+  XBT_CDEBUG(gras_trp_meas,
           "Recvd %ld msgs of %lu (size of each: %ld) from %s:%d",
           got_sofar, msg_amount, msg_size, gras_socket_peer_name(peer),
           gras_socket_peer_port(peer));
 
   if (gras_if_RL())
     free(chunk);
-  XBT_OUT;
+  XBT_OUT();
 }
 
 /**
@@ -580,10 +579,10 @@ void gras_socket_meas_recv(gras_socket_t peer,
 gras_socket_t gras_socket_meas_accept(gras_socket_t peer)
 {
   gras_socket_t res;
-  THROW0(unknown_error,0,"measurement sockets were broken in this release of SimGrid and should be ported back in the future."
+  THROWF(unknown_error,0,"measurement sockets were broken in this release of SimGrid and should be ported back in the future."
       "If you depend on it, sorry, you have to use an older version, or wait for the future version using it...");
 
-  xbt_assert0(peer->meas,
+  xbt_assert(peer->meas,
               "No need to accept on non-measurement sockets (it's automatic)");
 
   if (!peer->accepting) {
@@ -594,7 +593,7 @@ gras_socket_t gras_socket_meas_accept(gras_socket_t peer)
 
   res = (peer->plugin->socket_accept) (peer);
   res->meas = peer->meas;
-  CDEBUG1(gras_trp_meas, "meas_accepted onto %d", res->sd);
+  XBT_CDEBUG(gras_trp_meas, "meas_accepted onto %d", res->sd);
 
   return res;
 }
@@ -635,13 +634,13 @@ void gras_trp_socketset_dump(const char *name)
   unsigned int it;
   gras_socket_t s;
 
-  INFO1("** Dump the socket set %s", name);
+  XBT_INFO("** Dump the socket set %s", name);
   xbt_dynar_foreach(procdata->sockets, it, s) {
-    INFO4("  %p -> %s:%d %s",
+    XBT_INFO("  %p -> %s:%d %s",
           s, gras_socket_peer_name(s), gras_socket_peer_port(s),
           s->valid ? "(valid)" : "(peer dead)");
   }
-  INFO1("** End of socket set %s", name);
+  XBT_INFO("** End of socket set %s", name);
 }
 
 /*