Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill a useless field
[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 #include "xbt/queue.h"
18
19 /***
20  *** Options
21  ***/
22 extern int gras_opt_trp_nomoredata_on_close;
23
24 /***
25  *** Main user functions
26  ***/
27 /* stable if we know the storage will keep as is until the next trp_flush */
28 XBT_PUBLIC(void) gras_trp_send(gras_socket_t sd, char *data, long int size,
29                                int stable);
30 XBT_PUBLIC(void) gras_trp_recv(gras_socket_t sd, char *data, 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,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,
54                         gras_socket_t    dst);
55   void (*socket_server)(gras_trp_plugin_t self,
56                         gras_socket_t    dst);
57    
58   gras_socket_t (*socket_accept)(gras_socket_t  from);
59    
60    
61    /* socket_close() is responsible of telling the OS that the socket is over,
62     but should not free the socket itself (beside the specific part) */
63   void (*socket_close)(gras_socket_t sd);
64     
65   /* send/recv may be buffered */
66   void (*send)(gras_socket_t sd,
67                const char *data,
68                unsigned long int size,
69                int stable /* storage will survive until flush*/);
70   int (*recv)(gras_socket_t sd,
71               char *data,
72               unsigned long int size);
73   /* raw_send/raw_recv is never buffered (use it for measurement stuff) */
74   void (*raw_send)(gras_socket_t sd,
75                    const char *data,
76                    unsigned long int size);
77   int (*raw_recv)(gras_socket_t sd,
78                   char *data,
79                   unsigned long int size);
80
81   /* flush has to make sure that the pending communications are achieved */
82   void (*flush)(gras_socket_t sd);
83
84   void *data; /* plugin-specific data */
85  
86    /* exit is responsible for freeing data and telling to the OS that 
87       this plugin is gone */
88    /* exit=NULL, data gets brutally free()d by the generic interface. 
89       (ie exit function needed only when data contains pointers) */
90   void (*exit)(gras_trp_plugin_t);
91 };
92
93 XBT_PUBLIC(gras_trp_plugin_t) 
94 gras_trp_plugin_get_by_name(const char *name);
95
96 /* Data of this module specific to each process
97  * (used by sg_process.c to cleanup the SG channel cruft)
98  */
99 typedef struct {
100   /* set headers */
101   unsigned int ID;
102   char        *name;
103   unsigned int name_len;
104
105   int myport; /* Port on which I listen myself */
106    
107   xbt_dynar_t sockets; /* all sockets known to this process */
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_queue_t msg_selectable_sockets; /* regular sockets  */
113   xbt_queue_t meas_selectable_sockets;/* measurement ones */
114
115 } s_gras_trp_procdata_t,*gras_trp_procdata_t;
116
117 /* Display the content of our socket set (debugging purpose) */
118 XBT_PUBLIC(void) gras_trp_socketset_dump(const char *name);
119
120 #endif /* GRAS_TRP_INTERFACE_H */