Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
63547d229a07361f6684c661ba447c830749f4ce
[simgrid.git] / src / gras / Transport / transport_interface.h
1 /* $Id$ */
2
3 /* transport - low level communication (send/receive bunches of bytes)      */
4
5 /* module's public interface exported within GRAS, but not to end user.     */
6
7 /* Copyright (c) 2004 Martin Quinson. All rights reserved.                  */
8
9 /* This program is free software; you can redistribute it and/or modify it
10  * under the terms of the license (GNU LGPL) which comes with this package. */
11
12 #ifndef GRAS_TRP_INTERFACE_H
13 #define GRAS_TRP_INTERFACE_H
14
15 #include "portable.h" /* sometimes needed for fd_set */
16 #include "simix/simix.h"
17
18 /***
19  *** Options
20  ***/
21 extern int gras_opt_trp_nomoredata_on_close;
22
23 /***
24  *** Main user functions
25  ***/
26 /* stable if we know the storage will keep as is until the next trp_flush */
27 XBT_PUBLIC(void) gras_trp_send(gras_socket_t sd, char *data, long int size,
28                                int stable);
29 XBT_PUBLIC(void) gras_trp_recv(gras_socket_t sd, char *data, long int size);
30 XBT_PUBLIC(void) gras_trp_flush(gras_socket_t sd);
31
32 /* Find which socket needs to be read next */
33 XBT_PUBLIC(gras_socket_t) gras_trp_select(double timeout);
34
35 /* Set the peer process name (used by messaging layer) */
36 XBT_PUBLIC(void) gras_socket_peer_proc_set(gras_socket_t sock,char*peer_proc);
37
38 /***
39  *** Plugin mechanism 
40  ***/
41
42 /* A plugin type */
43 typedef struct gras_trp_plugin_ s_gras_trp_plugin_t, *gras_trp_plugin_t;
44
45 /* A plugin type */
46 struct gras_trp_plugin_ {
47   char          *name;
48  
49   /* dst pointers are created and initialized with default values
50      before call to socket_client/server. 
51      Retrive the info you need from there. */
52   void (*socket_client)(gras_trp_plugin_t self,
53                         gras_socket_t    dst);
54   void (*socket_server)(gras_trp_plugin_t self,
55                         gras_socket_t    dst);
56    
57   gras_socket_t (*socket_accept)(gras_socket_t  from);
58    
59    
60    /* socket_close() is responsible of telling the OS that the socket is over,
61     but should not free the socket itself (beside the specific part) */
62   void (*socket_close)(gras_socket_t sd);
63     
64   /* send/recv may be buffered */
65   void (*send)(gras_socket_t sd,
66                const char *data,
67                unsigned long int size,
68                int stable /* storage will survive until flush*/);
69   int (*recv)(gras_socket_t sd,
70               char *data,
71               unsigned long int size);
72   /* raw_send/raw_recv is never buffered (use it for measurement stuff) */
73   void (*raw_send)(gras_socket_t sd,
74                    const char *data,
75                    unsigned long int size);
76   int (*raw_recv)(gras_socket_t sd,
77                   char *data,
78                   unsigned long int size);
79
80   /* flush has to make sure that the pending communications are achieved */
81   void (*flush)(gras_socket_t sd);
82
83   void *data; /* plugin-specific data */
84  
85    /* exit is responsible for freeing data and telling to the OS that 
86       this plugin is gone */
87    /* exit=NULL, data gets brutally free()d by the generic interface. 
88       (ie exit function needed only when data contains pointers) */
89   void (*exit)(gras_trp_plugin_t);
90 };
91
92 XBT_PUBLIC(gras_trp_plugin_t) 
93 gras_trp_plugin_get_by_name(const char *name);
94
95 /* Data of this module specific to each process
96  * (used by sg_process.c to cleanup the SG channel cruft)
97  */
98 typedef struct {
99   /* set headers */
100   unsigned int ID;
101   char        *name;
102   unsigned int name_len;
103
104   int myport; /* Port on which I listen myself */
105    
106   xbt_dynar_t sockets; /* all sockets known to this process */
107   fd_set *fdset; /* idem, in another formalism */
108
109   /* SG only elements. In RL, they are part of the OS ;) */
110    
111   /* List of sockets ready to be select()ed */
112   xbt_fifo_t msg_selectable_sockets; /* regular sockets  */
113   xbt_fifo_t meas_selectable_sockets;/* measurement ones */
114
115   /* Synchronisation on msg_selectable_sockets */
116   smx_cond_t msg_select_cond;
117   smx_mutex_t msg_select_mutex;
118   /* Synchronisation on meas_selectable_sockets */
119   smx_cond_t meas_select_cond;
120   smx_mutex_t meas_select_mutex;
121    
122 } s_gras_trp_procdata_t,*gras_trp_procdata_t;
123
124 /* Display the content of our socket set (debugging purpose) */
125 XBT_PUBLIC(void) gras_trp_socketset_dump(const char *name);
126
127 #endif /* GRAS_TRP_INTERFACE_H */