Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
If it is a win plateform we have to use wenvironment against environment.
[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, 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,
37                                            char *peer_proc);
38
39 /***
40  *** Plugin mechanism 
41  ***/
42
43 /* A plugin type */
44      typedef struct gras_trp_plugin_ s_gras_trp_plugin_t, *gras_trp_plugin_t;
45
46 /* A plugin type */
47      struct gras_trp_plugin_ {
48        char *name;
49
50        /* dst pointers are created and initialized with default values
51           before call to socket_client/server. 
52           Retrive the info you need from there. */
53        void (*socket_client) (gras_trp_plugin_t self, gras_socket_t dst);
54        void (*socket_server) (gras_trp_plugin_t self, gras_socket_t dst);
55
56        gras_socket_t(*socket_accept) (gras_socket_t from);
57
58
59        /* socket_close() is responsible of telling the OS that the socket is over,
60           but should not free the socket itself (beside the specific part) */
61        void (*socket_close) (gras_socket_t sd);
62
63        /* send/recv may be buffered */
64        void (*send) (gras_socket_t sd,
65                      const char *data,
66                      unsigned long int size,
67                      int stable /* storage will survive until flush */ );
68        int (*recv) (gras_socket_t sd, char *data, unsigned long int size);
69        /* raw_send/raw_recv is never buffered (use it for measurement stuff) */
70        void (*raw_send) (gras_socket_t sd,
71                          const char *data, unsigned long int size);
72        int (*raw_recv) (gras_socket_t sd, char *data, unsigned long int size);
73
74        /* flush has to make sure that the pending communications are achieved */
75        void (*flush) (gras_socket_t sd);
76
77        void *data;              /* plugin-specific data */
78
79        /* exit is responsible for freeing data and telling to the OS that 
80           this plugin is gone */
81        /* exit=NULL, data gets brutally free()d by the generic interface. 
82           (ie exit function needed only when data contains pointers) */
83        void (*exit) (gras_trp_plugin_t);
84      };
85
86 XBT_PUBLIC(gras_trp_plugin_t)
87   gras_trp_plugin_get_by_name(const char *name);
88
89 /* Data of this module specific to each process
90  * (used by sg_process.c to cleanup the SG channel cruft)
91  */
92      typedef struct {
93        /* set headers */
94        unsigned int ID;
95        char *name;
96        unsigned int name_len;
97
98        int myport;              /* Port on which I listen myself */
99
100        xbt_dynar_t sockets;     /* all sockets known to this process */
101
102        /* SG only elements. In RL, they are part of the OS ;) */
103
104        /* List of sockets ready to be select()ed */
105        xbt_queue_t msg_selectable_sockets;      /* regular sockets  */
106        xbt_queue_t meas_selectable_sockets;     /* measurement ones */
107
108      } s_gras_trp_procdata_t, *gras_trp_procdata_t;
109
110 /* Display the content of our socket set (debugging purpose) */
111 XBT_PUBLIC(void) gras_trp_socketset_dump(const char *name);
112
113 #endif /* GRAS_TRP_INTERFACE_H */