Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
411f4217d6dd3332fe5ca89f93953cb78fc06f09
[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
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, int stable);
27 XBT_PUBLIC(void) gras_trp_recv(gras_socket_t sd, char *data, long int size);
28 XBT_PUBLIC(void) gras_trp_flush(gras_socket_t sd);
29
30 /* Find which socket needs to be read next */
31 XBT_PUBLIC(gras_socket_t) gras_trp_select(double timeout);
32
33 /* Set the peer process name (used by messaging layer) */
34 XBT_PUBLIC(void) gras_socket_peer_proc_set(gras_socket_t sock,char*peer_proc);
35
36 /***
37  *** Plugin mechanism 
38  ***/
39
40 /* A plugin type */
41 typedef struct gras_trp_plugin_ s_gras_trp_plugin_t, *gras_trp_plugin_t;
42
43 /* A plugin type */
44 struct gras_trp_plugin_ {
45   char          *name;
46  
47   /* dst pointers are created and initialized with default values
48      before call to socket_client/server. 
49      Retrive the info you need from there. */
50   void (*socket_client)(gras_trp_plugin_t self,
51                         gras_socket_t    dst);
52   void (*socket_server)(gras_trp_plugin_t self,
53                         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,
68               char *data,
69               unsigned long int size);
70   /* raw_send/raw_recv is never buffered (use it for measurement stuff) */
71   void (*raw_send)(gras_socket_t sd,
72                    const char *data,
73                    unsigned long int size);
74   int (*raw_recv)(gras_socket_t sd,
75                   char *data,
76                   unsigned long int size);
77
78   /* flush has to make sure that the pending communications are achieved */
79   void (*flush)(gras_socket_t sd);
80
81   void *data; /* plugin-specific data */
82  
83    /* exit is responsible for freeing data and telling the OS this plugin goes */
84    /* exit=NULL, data gets freed. (ie exit function needed only when data contains pointers) */
85   void (*exit)(gras_trp_plugin_t);
86 };
87
88 XBT_PUBLIC(gras_trp_plugin_t) 
89 gras_trp_plugin_get_by_name(const char *name);
90
91 /* Data of this module specific to each process
92  * (used by sg_process.c to cleanup the SG channel cruft)
93  */
94 typedef struct {
95   /* set headers */
96   unsigned int ID;
97   char        *name;
98   unsigned int name_len;
99
100   xbt_dynar_t sockets; /* all sockets known to this process */
101   int myport; /* Port on which I listen myself */
102   fd_set *fdset;
103
104   /* SG only elements. In RL, they are part of the OS ;) */
105   int chan;    /* Formated messages channel */
106   int measChan; /* Unformated echange channel for performance measurement*/
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 */