Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update gras_simix. Modified the implementation of ports.
[simgrid.git] / src / gras_simix / Transport / gras_simix_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
18 /***
19  *** Options
20  ***/
21 extern int gras_opt_trp_nomoredata_on_close;
22
23 /***
24  *** Main user functions
25  ***/
26 /* stable if we know the storage will keep as is until the next trp_flush */
27 XBT_PUBLIC(void) gras_trp_send(gras_socket_t sd, char *data, long int size, 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,char*peer_proc);
36
37 /***
38  *** Plugin mechanism 
39  ***/
40
41 /* A plugin type */
42 typedef struct gras_trp_plugin_ s_gras_trp_plugin_t, *gras_trp_plugin_t;
43
44 /* A plugin type */
45 struct gras_trp_plugin_ {
46   char          *name;
47  
48   /* dst pointers are created and initialized with default values
49      before call to socket_client/server. 
50      Retrive the info you need from there. */
51   void (*socket_client)(gras_trp_plugin_t self,
52                         gras_socket_t    dst);
53   void (*socket_server)(gras_trp_plugin_t self,
54                         gras_socket_t    dst);
55    
56   gras_socket_t (*socket_accept)(gras_socket_t  from);
57    
58    
59    /* socket_close() is responsible of telling the OS that the socket is over,
60     but should not free the socket itself (beside the specific part) */
61   void (*socket_close)(gras_socket_t sd);
62     
63   /* send/recv may be buffered */
64   void (*send)(gras_socket_t sd,
65                const char *data,
66                unsigned long int size,
67                int stable /* storage will survive until flush*/);
68   int (*recv)(gras_socket_t sd,
69               char *data,
70               unsigned long int size);
71   /* raw_send/raw_recv is never buffered (use it for measurement stuff) */
72   void (*raw_send)(gras_socket_t sd,
73                    const char *data,
74                    unsigned long int size);
75   int (*raw_recv)(gras_socket_t sd,
76                   char *data,
77                   unsigned long int size);
78
79   /* flush has to make sure that the pending communications are achieved */
80   void (*flush)(gras_socket_t sd);
81
82   void *data; /* plugin-specific data */
83  
84    /* exit is responsible for freeing data and telling the OS this plugin goes */
85    /* exit=NULL, data gets freed. (ie exit function needed only when data contains pointers) */
86   void (*exit)(gras_trp_plugin_t);
87 };
88
89 XBT_PUBLIC(gras_trp_plugin_t) 
90 gras_trp_plugin_get_by_name(const char *name);
91
92 /* Data of this module specific to each process
93  * (used by sg_process.c to cleanup the SG channel cruft)
94  */
95 typedef struct {
96   /* set headers */
97   unsigned int ID;
98   char        *name;
99   unsigned int name_len;
100
101   xbt_dynar_t sockets; /* all sockets known to this process */
102   int myport; /* Port on which I listen myself */
103   fd_set *fdset;
104
105   /* SG only elements. In RL, they are part of the OS ;) */
106         smx_cond_t cond;
107         smx_mutex_t mutex;
108         xbt_fifo_t active_socket;
109         long int pid;
110         long int ppid;
111
112    
113 } s_gras_trp_procdata_t,*gras_trp_procdata_t;
114
115 /* Display the content of our socket set (debugging purpose) */
116 XBT_PUBLIC(void) gras_trp_socketset_dump(const char *name);
117
118 #endif /* GRAS_TRP_INTERFACE_H */