Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Partial fix of GRAS: gras-ping-sg now works again
[simgrid.git] / src / gras / Transport / transport_interface.h
1 /* transport - low level communication (send/receive bunches of bytes)      */
2
3 /* module's public interface exported within GRAS, but not to end user.     */
4
5 /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
6  * All rights reserved.                                                     */
7
8 /* This program is free software; you can redistribute it and/or modify it
9  * under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #ifndef GRAS_TRP_INTERFACE_H
12 #define GRAS_TRP_INTERFACE_H
13
14 #include "portable.h"           /* sometimes needed for fd_set */
15 #include "simix/simix.h"
16 #include "xbt/queue.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,
30                                long int size);
31 XBT_PUBLIC(void) gras_trp_flush(gras_socket_t sd);
32
33 /* Find which socket needs to be read next */
34 XBT_PUBLIC(gras_socket_t) gras_trp_select(double timeout);
35
36 /* Set the peer process name (used by messaging layer) */
37 XBT_PUBLIC(void) gras_socket_peer_proc_set(gras_socket_t sock,
38                                            char *peer_proc);
39
40 /***
41  *** Plugin mechanism 
42  ***/
43
44 /* A plugin type */
45 typedef struct gras_trp_plugin_ s_gras_trp_plugin_t, *gras_trp_plugin_t;
46
47 /* A plugin type */
48 struct gras_trp_plugin_ {
49   char *name;
50
51   /* dst pointers are created and initialized with default values
52      before call to socket_client/server. 
53      Retrive the info you need from there. */
54   void (*socket_client) (gras_trp_plugin_t self,const char *host,int port, gras_socket_t dst);
55   void (*socket_server) (gras_trp_plugin_t self, int port,gras_socket_t dst);
56
57   gras_socket_t(*socket_accept) (gras_socket_t from);
58
59   /* Getting info about who's speaking */
60   int (*my_port)(gras_socket_t sd);
61   int (*peer_port)(gras_socket_t sd);
62   const char* (*peer_name)(gras_socket_t sd);
63   const char* (*peer_proc)(gras_socket_t sd);
64   void (*peer_proc_set)(gras_socket_t sd,char*peer_proc);
65
66
67   /* socket_close() is responsible of telling the OS that the socket is over,
68      but should not free the socket itself (beside the specific part) */
69   void (*socket_close) (gras_socket_t sd);
70
71   /* send/recv may be buffered */
72   void (*send) (gras_socket_t sd,
73                 const char *data,
74                 unsigned long int size,
75                 int stable /* storage will survive until flush */ );
76   int (*recv) (gras_socket_t sd, char *data, unsigned long int size);
77   /* raw_send/raw_recv is never buffered (use it for measurement stuff) */
78   void (*raw_send) (gras_socket_t sd,
79                     const char *data, unsigned long int size);
80   int (*raw_recv) (gras_socket_t sd, char *data, unsigned long int size);
81
82   /* flush has to make sure that the pending communications are achieved */
83   void (*flush) (gras_socket_t sd);
84
85   void *data;                   /* plugin-specific data */
86
87   /* exit is responsible for freeing data and telling to the OS that 
88      this plugin is gone */
89   /* exit=NULL, data gets brutally free()d by the generic interface. 
90      (ie exit function needed only when data contains pointers) */
91   void (*exit) (gras_trp_plugin_t);
92 };
93
94 XBT_PUBLIC(gras_trp_plugin_t)
95     gras_trp_plugin_get_by_name(const char *name);
96
97 /* Data of this module specific to each process
98  * (used by sg_process.c to cleanup the SG channel cruft)
99  */
100 typedef struct {
101   /* set headers */
102   unsigned int ID;
103   char *name;
104   unsigned int name_len;
105
106   int myport;                   /* Port on which I listen myself */
107
108   xbt_dynar_t sockets;          /* all sockets known to this process */
109
110   /* SG only elements. In RL, they are part of the OS ;) */
111
112   /* List of sockets ready to be select()ed */
113   xbt_queue_t msg_selectable_sockets;   /* regular sockets  */
114   xbt_queue_t meas_selectable_sockets;  /* measurement ones */
115
116 } s_gras_trp_procdata_t, *gras_trp_procdata_t;
117
118 /* Display the content of our socket set (debugging purpose) */
119 XBT_PUBLIC(void) gras_trp_socketset_dump(const char *name);
120
121 #endif                          /* GRAS_TRP_INTERFACE_H */