Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Detect socket closed by peer in the transport layer, so that such things don't polute...
[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 /* Set the peer process name (used by messaging layer) */
29 void gras_socket_peer_proc_set(gras_socket_t sock,char*peer_proc);
30
31 /***
32  *** Plugin mechanism 
33  ***/
34
35 /* A plugin type */
36 typedef struct gras_trp_plugin_ s_gras_trp_plugin_t, *gras_trp_plugin_t;
37
38 /* A plugin type */
39 struct gras_trp_plugin_ {
40   char          *name;
41  
42   /* dst pointers are created and initialized with default values
43      before call to socket_client/server. 
44      Retrive the info you need from there. */
45   void (*socket_client)(gras_trp_plugin_t self,
46                         gras_socket_t    dst);
47   void (*socket_server)(gras_trp_plugin_t self,
48                         gras_socket_t    dst);
49    
50   gras_socket_t (*socket_accept)(gras_socket_t  from);
51    
52    
53    /* socket_close() is responsible of telling the OS that the socket is over,
54     but should not free the socket itself (beside the specific part) */
55   void (*socket_close)(gras_socket_t sd);
56     
57   /* send/recv may be buffered */
58   void (*send)(gras_socket_t sd,
59                const char *data,
60                unsigned long int size,
61                int stable /* storage will survive until flush*/);
62   int (*recv)(gras_socket_t sd,
63               char *data,
64               unsigned long int size);
65   /* raw_send/raw_recv is never buffered (use it for measurement stuff) */
66   void (*raw_send)(gras_socket_t sd,
67                    const char *data,
68                    unsigned long int size);
69   int (*raw_recv)(gras_socket_t sd,
70                   char *data,
71                   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 the OS this plugin goes */
79    /* exit=NULL, data gets freed. (ie exit function needed only when data contains pointers) */
80   void (*exit)(gras_trp_plugin_t);
81 };
82
83 gras_trp_plugin_t
84 gras_trp_plugin_get_by_name(const char *name);
85
86 /* Data of this module specific to each process
87  * (used by sg_process.c to cleanup the SG channel cruft)
88  */
89 typedef struct {
90   /* set headers */
91   unsigned int ID;
92   char        *name;
93   unsigned int name_len;
94
95   xbt_dynar_t sockets; /* all sockets known to this process */
96   int myport; /* Port on which I listen myself */
97   fd_set *fdset;
98
99   /* SG only elements. In RL, they are part of the OS ;) */
100   int chan;    /* Formated messages channel */
101   int measChan; /* Unformated echange channel for performance measurement*/
102    
103 } s_gras_trp_procdata_t,*gras_trp_procdata_t;
104
105 #endif /* GRAS_TRP_INTERFACE_H */