Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill old $Id$ command dating from CVS
[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 Martin Quinson. All rights reserved.                  */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #ifndef GRAS_TRP_INTERFACE_H
11 #define GRAS_TRP_INTERFACE_H
12
13 #include "portable.h"           /* sometimes needed for fd_set */
14 #include "simix/simix.h"
15 #include "xbt/queue.h"
16
17 /***
18  *** Options
19  ***/
20 extern int gras_opt_trp_nomoredata_on_close;
21
22 /***
23  *** Main user functions
24  ***/
25 /* stable if we know the storage will keep as is until the next trp_flush */
26 XBT_PUBLIC(void) gras_trp_send(gras_socket_t sd, char *data, long int size,
27                                int stable);
28 XBT_PUBLIC(void) gras_trp_recv(gras_socket_t sd, char *data, long int size);
29 XBT_PUBLIC(void) gras_trp_flush(gras_socket_t sd);
30
31 /* Find which socket needs to be read next */
32 XBT_PUBLIC(gras_socket_t) gras_trp_select(double timeout);
33
34 /* Set the peer process name (used by messaging layer) */
35 XBT_PUBLIC(void) gras_socket_peer_proc_set(gras_socket_t sock,
36                                            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, gras_socket_t dst);
53        void (*socket_server) (gras_trp_plugin_t self, gras_socket_t dst);
54
55        gras_socket_t(*socket_accept) (gras_socket_t from);
56
57
58        /* socket_close() is responsible of telling the OS that the socket is over,
59           but should not free the socket itself (beside the specific part) */
60        void (*socket_close) (gras_socket_t sd);
61
62        /* send/recv may be buffered */
63        void (*send) (gras_socket_t sd,
64                      const char *data,
65                      unsigned long int size,
66                      int stable /* storage will survive until flush */ );
67        int (*recv) (gras_socket_t sd, char *data, unsigned long int size);
68        /* raw_send/raw_recv is never buffered (use it for measurement stuff) */
69        void (*raw_send) (gras_socket_t sd,
70                          const char *data, unsigned long int size);
71        int (*raw_recv) (gras_socket_t sd, char *data, unsigned long int size);
72
73        /* flush has to make sure that the pending communications are achieved */
74        void (*flush) (gras_socket_t sd);
75
76        void *data;              /* plugin-specific data */
77
78        /* exit is responsible for freeing data and telling to the OS that 
79           this plugin is gone */
80        /* exit=NULL, data gets brutally free()d by the generic interface. 
81           (ie exit function needed only when data contains pointers) */
82        void (*exit) (gras_trp_plugin_t);
83      };
84
85 XBT_PUBLIC(gras_trp_plugin_t)
86   gras_trp_plugin_get_by_name(const char *name);
87
88 /* Data of this module specific to each process
89  * (used by sg_process.c to cleanup the SG channel cruft)
90  */
91      typedef struct {
92        /* set headers */
93        unsigned int ID;
94        char *name;
95        unsigned int name_len;
96
97        int myport;              /* Port on which I listen myself */
98
99        xbt_dynar_t sockets;     /* all sockets known to this process */
100
101        /* SG only elements. In RL, they are part of the OS ;) */
102
103        /* List of sockets ready to be select()ed */
104        xbt_queue_t msg_selectable_sockets;      /* regular sockets  */
105        xbt_queue_t meas_selectable_sockets;     /* measurement ones */
106
107      } s_gras_trp_procdata_t, *gras_trp_procdata_t;
108
109 /* Display the content of our socket set (debugging purpose) */
110 XBT_PUBLIC(void) gras_trp_socketset_dump(const char *name);
111
112 #endif /* GRAS_TRP_INTERFACE_H */