Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
388d5d4381b45824fdca519f38be2992a149655e
[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  *** Main user functions
19  ***/
20 /* stable if we know the storage will keep as is until the next trp_flush */
21 void gras_trp_send(gras_socket_t sd, char *data, long int size, int stable);
22 void gras_trp_recv(gras_socket_t sd, char *data, long int size);
23 void gras_trp_flush(gras_socket_t sd);
24
25 /* Find which socket needs to be read next */
26 gras_socket_t gras_trp_select(double timeout);
27
28
29 /***
30  *** Plugin mechanism 
31  ***/
32
33 /* A plugin type */
34 typedef struct gras_trp_plugin_ s_gras_trp_plugin_t, *gras_trp_plugin_t;
35
36 /* A plugin type */
37 struct gras_trp_plugin_ {
38   char          *name;
39  
40   /* dst pointers are created and initialized with default values
41      before call to socket_client/server. 
42      Retrive the info you need from there. */
43   void (*socket_client)(gras_trp_plugin_t self,
44                         gras_socket_t    dst);
45   void (*socket_server)(gras_trp_plugin_t self,
46                         gras_socket_t    dst);
47    
48   gras_socket_t (*socket_accept)(gras_socket_t  from);
49    
50    
51    /* socket_close() is responsible of telling the OS that the socket is over,
52     but should not free the socket itself (beside the specific part) */
53   void (*socket_close)(gras_socket_t sd);
54     
55   /* send/recv may be buffered */
56   void (*send)(gras_socket_t sd,
57                const char *data,
58                unsigned long int size,
59                int stable /* storage will survive until flush*/);
60   int (*recv)(gras_socket_t sd,
61               char *data,
62               unsigned long int size);
63   /* raw_send/raw_recv is never buffered (use it for measurement stuff) */
64   void (*raw_send)(gras_socket_t sd,
65                    const char *data,
66                    unsigned long int size);
67   int (*raw_recv)(gras_socket_t sd,
68                   char *data,
69                   unsigned long int size);
70
71   /* flush has to make sure that the pending communications are achieved */
72   void (*flush)(gras_socket_t sd);
73
74   void *data; /* plugin-specific data */
75  
76    /* exit is responsible for freeing data and telling the OS this plugin goes */
77    /* exit=NULL, data gets freed. (ie exit function needed only when data contains pointers) */
78   void (*exit)(gras_trp_plugin_t);
79 };
80
81 gras_trp_plugin_t
82 gras_trp_plugin_get_by_name(const char *name);
83
84 /* Data of this module specific to each process
85  * (used by sg_process.c to cleanup the SG channel cruft)
86  */
87 typedef struct {
88   /* set headers */
89   unsigned int ID;
90   char        *name;
91   unsigned int name_len;
92
93   xbt_dynar_t sockets; /* all sockets known to this process */
94   fd_set *fdset;
95
96   /* SG only elements. In RL, they are part of the OS ;) */
97   int chan;    /* Formated messages channel */
98   int measChan; /* Unformated echange channel for performance measurement*/
99    
100 } s_gras_trp_procdata_t,*gras_trp_procdata_t;
101
102 #endif /* GRAS_TRP_INTERFACE_H */