Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
various little cleanups in the gras/sg code. Mainly reindentation and more informativ...
[simgrid.git] / src / gras / Transport / transport_interface.h
index 595deab..63547d2 100644 (file)
 #ifndef GRAS_TRP_INTERFACE_H
 #define GRAS_TRP_INTERFACE_H
 
+#include "portable.h" /* sometimes needed for fd_set */
+#include "simix/simix.h"
+
+/***
+ *** Options
+ ***/
+extern int gras_opt_trp_nomoredata_on_close;
+
 /***
  *** Main user functions
  ***/
-xbt_error_t gras_trp_chunk_send(gras_socket_t sd,
-                                char *data,
-                                long int size);
-xbt_error_t gras_trp_chunk_recv(gras_socket_t sd,
-                                char *data,
-                                long int size);
-xbt_error_t gras_trp_flush(gras_socket_t sd);
+/* stable if we know the storage will keep as is until the next trp_flush */
+XBT_PUBLIC(void) gras_trp_send(gras_socket_t sd, char *data, long int size,
+                              int stable);
+XBT_PUBLIC(void) gras_trp_recv(gras_socket_t sd, char *data, long int size);
+XBT_PUBLIC(void) gras_trp_flush(gras_socket_t sd);
 
 /* Find which socket needs to be read next */
-xbt_error_t 
-gras_trp_select(double timeout,
-               gras_socket_t *dst);
+XBT_PUBLIC(gras_socket_t) gras_trp_select(double timeout);
 
+/* Set the peer process name (used by messaging layer) */
+XBT_PUBLIC(void) gras_socket_peer_proc_set(gras_socket_t sock,char*peer_proc);
 
 /***
  *** Plugin mechanism 
  ***/
 
 /* A plugin type */
-typedef struct gras_trp_plugin_ gras_trp_plugin_t;
+typedef struct gras_trp_plugin_ s_gras_trp_plugin_t, *gras_trp_plugin_t;
 
 /* A plugin type */
 struct gras_trp_plugin_ {
@@ -43,49 +49,79 @@ struct gras_trp_plugin_ {
   /* dst pointers are created and initialized with default values
      before call to socket_client/server. 
      Retrive the info you need from there. */
-  xbt_error_t (*socket_client)(gras_trp_plugin_t *self,
-                               gras_socket_t      dst);
-  xbt_error_t (*socket_server)(gras_trp_plugin_t *self,
-                               gras_socket_t      dst);
+  void (*socket_client)(gras_trp_plugin_t self,
+                       gras_socket_t    dst);
+  void (*socket_server)(gras_trp_plugin_t self,
+                       gras_socket_t    dst);
    
-  xbt_error_t (*socket_accept)(gras_socket_t  sock,
-                               gras_socket_t *dst);
+  gras_socket_t (*socket_accept)(gras_socket_t  from);
    
    
    /* socket_close() is responsible of telling the OS that the socket is over,
     but should not free the socket itself (beside the specific part) */
-  void         (*socket_close)(gras_socket_t sd);
+  void (*socket_close)(gras_socket_t sd);
     
-  xbt_error_t (*chunk_send)(gras_socket_t sd,
-                            const char *data,
-                           unsigned long int size);
-  xbt_error_t (*chunk_recv)(gras_socket_t sd,
-                           char *data,
-                           unsigned long int size);
+  /* send/recv may be buffered */
+  void (*send)(gras_socket_t sd,
+              const char *data,
+              unsigned long int size,
+              int stable /* storage will survive until flush*/);
+  int (*recv)(gras_socket_t sd,
+             char *data,
+             unsigned long int size);
+  /* raw_send/raw_recv is never buffered (use it for measurement stuff) */
+  void (*raw_send)(gras_socket_t sd,
+                  const char *data,
+                  unsigned long int size);
+  int (*raw_recv)(gras_socket_t sd,
+                 char *data,
+                 unsigned long int size);
 
   /* flush has to make sure that the pending communications are achieved */
-  xbt_error_t (*flush)(gras_socket_t sd);
+  void (*flush)(gras_socket_t sd);
 
-  void          *data; /* plugin-specific data */
+  void *data; /* plugin-specific data */
  
-   /* exit is responsible for freeing data and telling the OS this plugin goes */
-   /* exit=NULL, data gets freed. (ie exit function needed only when data contains pointers) */
-  void         (*exit)(gras_trp_plugin_t *);
+   /* exit is responsible for freeing data and telling to the OS that 
+      this plugin is gone */
+   /* exit=NULL, data gets brutally free()d by the generic interface. 
+      (ie exit function needed only when data contains pointers) */
+  void (*exit)(gras_trp_plugin_t);
 };
 
-xbt_error_t
-gras_trp_plugin_get_by_name(const char *name,
-                           gras_trp_plugin_t **dst);
+XBT_PUBLIC(gras_trp_plugin_t) 
+gras_trp_plugin_get_by_name(const char *name);
 
 /* Data of this module specific to each process
  * (used by sg_process.c to cleanup the SG channel cruft)
  */
 typedef struct {
-   /* SG only elements. In RL, they are part of the OS ;) */
-   int chan;    /* Formated messages channel */
-   int measChan; /* Unformated echange channel for performance measurement*/
-   xbt_dynar_t sockets; /* all sockets known to this process */
+  /* set headers */
+  unsigned int ID;
+  char        *name;
+  unsigned int name_len;
+
+  int myport; /* Port on which I listen myself */
+   
+  xbt_dynar_t sockets; /* all sockets known to this process */
+  fd_set *fdset; /* idem, in another formalism */
+
+  /* SG only elements. In RL, they are part of the OS ;) */
+   
+  /* List of sockets ready to be select()ed */
+  xbt_fifo_t msg_selectable_sockets; /* regular sockets  */
+  xbt_fifo_t meas_selectable_sockets;/* measurement ones */
+
+  /* Synchronisation on msg_selectable_sockets */
+  smx_cond_t msg_select_cond;
+  smx_mutex_t msg_select_mutex;
+  /* Synchronisation on meas_selectable_sockets */
+  smx_cond_t meas_select_cond;
+  smx_mutex_t meas_select_mutex;
    
 } s_gras_trp_procdata_t,*gras_trp_procdata_t;
 
+/* Display the content of our socket set (debugging purpose) */
+XBT_PUBLIC(void) gras_trp_socketset_dump(const char *name);
+
 #endif /* GRAS_TRP_INTERFACE_H */