Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill gras measurement sockets for now. If you rely on them, sorry.
[simgrid.git] / src / gras / Transport / transport.c
index 1b758cf..3d159d1 100644 (file)
@@ -1,8 +1,7 @@
-/* $Id$ */
-
 /* transport - low level communication                                      */
 
-/* Copyright (c) 2004 Martin Quinson. All rights reserved.                  */
+/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 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. */
@@ -163,11 +162,8 @@ void gras_trp_socket_new(int incoming, gras_socket_t * dst)
   sock->valid = 1;
   sock->moredata = 0;
 
+  sock->refcount = 1;
   sock->sd = -1;
-  sock->port = -1;
-  sock->peer_port = -1;
-  sock->peer_name = NULL;
-  sock->peer_proc = NULL;
 
   sock->data = NULL;
   sock->bufdata = NULL;
@@ -201,14 +197,13 @@ gras_socket_server_ext(unsigned short port,
   /* defaults settings */
   gras_trp_socket_new(1, &sock);
   sock->plugin = trp;
-  sock->port = port;
   sock->buf_size = buf_size > 0 ? buf_size : 32 * 1024;
   sock->meas = measurement;
 
   /* Call plugin socket creation function */
   DEBUG1("Prepare socket with plugin (fct=%p)", trp->socket_server);
   TRY {
-    trp->socket_server(trp, sock);
+    trp->socket_server(trp, port, sock);
     DEBUG3("in=%c out=%c accept=%c",
            sock->incoming ? 'y' : 'n',
            sock->outgoing ? 'y' : 'n', sock->accepting ? 'y' : 'n');
@@ -219,10 +214,11 @@ gras_socket_server_ext(unsigned short port,
   }
 
   if (!measurement)
-    ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->myport =
-      port;
+    ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->myport
+        = port;
   xbt_dynar_push(((gras_trp_procdata_t)
-                  gras_libdata_by_id(gras_trp_libdata_id))->sockets, &sock);
+                  gras_libdata_by_id(gras_trp_libdata_id))->sockets,
+                 &sock);
 
   gras_msg_listener_awake();
   return sock;
@@ -283,18 +279,17 @@ gras_socket_client_ext(const char *host,
 
   trp = gras_trp_plugin_get_by_name(gras_if_SG()? "sg" : "tcp");
 
-  DEBUG1("Create a client socket from plugin %s", gras_if_RL()? "tcp" : "sg");
+  DEBUG1("Create a client socket from plugin %s",
+         gras_if_RL()? "tcp" : "sg");
   /* defaults settings */
   gras_trp_socket_new(0, &sock);
   sock->plugin = trp;
-  sock->peer_port = port;
-  sock->peer_name = (char *) strdup(host ? host : "localhost");
   sock->buf_size = buf_size > 0 ? buf_size : 32 * 1024;
   sock->meas = measurement;
 
   /* plugin-specific */
   TRY {
-    (*trp->socket_client) (trp, sock);
+    (*trp->socket_client) (trp,host,port,sock);
     DEBUG3("in=%c out=%c accept=%c",
            sock->incoming ? 'y' : 'n',
            sock->outgoing ? 'y' : 'n', sock->accepting ? 'y' : 'n');
@@ -303,7 +298,8 @@ gras_socket_client_ext(const char *host,
     RETHROW;
   }
   xbt_dynar_push(((gras_trp_procdata_t)
-                  gras_libdata_by_id(gras_trp_libdata_id))->sockets, &sock);
+                  gras_libdata_by_id(gras_trp_libdata_id))->sockets,
+                 &sock);
   gras_msg_listener_awake();
   return sock;
 }
@@ -333,11 +329,20 @@ gras_socket_t gras_socket_client_from_string(const char *host)
   return res;
 }
 
+void gras_socket_close_voidp(void *sock)
+{
+  gras_socket_close((gras_socket_t) sock);
+}
+
 /** \brief Close socket */
 void gras_socket_close(gras_socket_t sock)
 {
+  if (--sock->refcount)
+    return;
+
   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;
   gras_socket_t sock_iter = NULL;
   unsigned int cursor;
 
@@ -349,7 +354,7 @@ void gras_socket_close(gras_socket_t sock)
 
     if (sock->moredata)
       CRITICAL0
-        ("Closing a socket having more data in buffer. Option nomoredata_on_close disabled, so continuing.");
+          ("Closing a socket having more data in buffer. Option nomoredata_on_close disabled, so continuing.");
     _gras_lastly_selected_socket = NULL;
   }
 
@@ -368,15 +373,14 @@ void gras_socket_close(gras_socket_t sock)
           (*sock->plugin->socket_close) (sock);
 
         /* free the memory */
-        if (sock->peer_name)
-          free(sock->peer_name);
         free(sock);
         XBT_OUT;
         return;
       }
     }
-    WARN1("Ignoring request to free an unknown socket (%p). Execution stack:",
-          sock);
+    WARN1
+        ("Ignoring request to free an unknown socket (%p). Execution stack:",
+         sock);
     xbt_backtrace_display_current();
   }
   XBT_OUT;
@@ -423,27 +427,33 @@ gras_trp_plugin_t gras_trp_plugin_get_by_name(const char *name)
 
 int gras_socket_my_port(gras_socket_t sock)
 {
-  return sock->port;
+  if (!sock->plugin->my_port)
+    THROW1(unknown_error,0,"Function my_port unimplemented in plugin %s",sock->plugin->name);
+  return (*sock->plugin->my_port)(sock);
+
 }
 
 int gras_socket_peer_port(gras_socket_t sock)
 {
-  return sock->peer_port;
+  if (!sock->plugin->peer_port)
+    THROW1(unknown_error,0,"Function peer_port unimplemented in plugin %s",sock->plugin->name);
+  return (*sock->plugin->peer_port)(sock);
 }
 
-char *gras_socket_peer_name(gras_socket_t sock)
+const char *gras_socket_peer_name(gras_socket_t sock)
 {
-  return sock->peer_name;
+  xbt_assert(sock->plugin);
+  return (*sock->plugin->peer_name)(sock);
 }
 
-char *gras_socket_peer_proc(gras_socket_t sock)
+const char *gras_socket_peer_proc(gras_socket_t sock)
 {
-  return sock->peer_proc;
+  return (*sock->plugin->peer_proc)(sock);
 }
 
 void gras_socket_peer_proc_set(gras_socket_t sock, char *peer_proc)
 {
-  sock->peer_proc = peer_proc;
+  return (*sock->plugin->peer_proc_set)(sock,peer_proc);
 }
 
 /** \brief Check if the provided socket is a measurement one (or a regular one) */
@@ -480,7 +490,8 @@ void gras_socket_meas_send(gras_socket_t peer,
   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."
+      "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);
 
@@ -491,14 +502,15 @@ void gras_socket_meas_send(gras_socket_t peer,
 
   for (sent_sofar = 0; sent_sofar < msg_amount; sent_sofar++) {
     CDEBUG5(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),
+            "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, "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));
+  CDEBUG5(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));
 
   if (gras_if_RL())
     free(chunk);
@@ -526,6 +538,8 @@ void gras_socket_meas_recv(gras_socket_t peer,
   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."
+      "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);
@@ -536,14 +550,14 @@ void gras_socket_meas_recv(gras_socket_t peer,
 
   for (got_sofar = 0; got_sofar < msg_amount; got_sofar++) {
     CDEBUG5(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),
+            "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,
-          "Recvd %ld msgs of %lu (size of each: %ld) from %s:%d", got_sofar,
-          msg_amount, msg_size, gras_socket_peer_name(peer),
+          "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())
@@ -566,6 +580,8 @@ 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."
+      "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,
               "No need to accept on non-measurement sockets (it's automatic)");
@@ -614,7 +630,7 @@ static void gras_trp_procdata_free(void *data)
 void gras_trp_socketset_dump(const char *name)
 {
   gras_trp_procdata_t procdata =
-    (gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id);
+      (gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id);
 
   unsigned int it;
   gras_socket_t s;
@@ -635,8 +651,8 @@ int gras_trp_libdata_id;
 void gras_trp_register()
 {
   gras_trp_libdata_id =
-    gras_procdata_add("gras_trp", gras_trp_procdata_new,
-                      gras_trp_procdata_free);
+      gras_procdata_add("gras_trp", gras_trp_procdata_new,
+                        gras_trp_procdata_free);
 }
 
 int gras_os_myport(void)