Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Indent include and src using this command:
[simgrid.git] / src / gras / Transport / transport_private.h
1 /* transport - low level communication (send/receive bunches of bytes)      */
2
3 /* module's private interface masked even to other parts of GRAS.           */
4
5 /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
6  * All rights reserved.                                                     */
7
8 /* This program is free software; you can redistribute it and/or modify it
9  * under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #ifndef GRAS_TRP_PRIVATE_H
12 #define GRAS_TRP_PRIVATE_H
13
14 #include "xbt/sysdep.h"
15 #include "xbt/log.h"
16 #include "xbt/dynar.h"
17 #include "xbt/dict.h"
18
19 #include "gras/emul.h"          /* gras_if_RL() */
20
21 #include "gras_modinter.h"      /* module init/exit */
22 #include "gras/transport.h"     /* rest of module interface */
23
24 #include "gras/Transport/transport_interface.h" /* semi-public API */
25 #include "gras/Virtu/virtu_interface.h" /* libdata management */
26
27 extern int gras_trp_libdata_id; /* our libdata identifier */
28
29 /* The function that select returned the last time we asked. We need this
30    because the TCP read are greedy and try to get as much data in their 
31    buffer as possible (to avoid subsequent syscalls).
32    (measurement sockets are not buffered and thus not concerned).
33   
34    So, we can get more than one message in one shoot. And when this happens,
35    we have to handle the same socket again afterward without select()ing at
36    all. 
37  
38    Then, this data is not a static of the TCP driver because we want to
39    zero it when it gets closed by the user. If not, we use an already freed 
40    pointer, which is bad.
41  
42    It gets tricky since gras_socket_close is part of the common API, not 
43    only the RL one. */
44 extern gras_socket_t _gras_lastly_selected_socket;
45
46 /**
47  * s_gras_socket:
48  * 
49  * Description of a socket.
50  */
51 typedef struct gras_trp_bufdata_ gras_trp_bufdata_t;
52
53 typedef struct s_gras_socket {
54   gras_trp_plugin_t plugin;
55
56   int incoming:1;               /* true if we can read from this sock */
57   int outgoing:1;               /* true if we can write on this sock */
58   int accepting:1;              /* true if master incoming sock in tcp */
59   int meas:1;                   /* true if this is an experiment socket instead of messaging */
60   int valid:1;                  /* false if a select returned that the peer quitted, forcing us to "close" the socket */
61   int moredata:1;               /* TCP socket use a buffer and read operation get as much 
62                                    data as possible. It is possible that several messages
63                                    are received in one shoot, and select won't catch them 
64                                    afterward again. 
65                                    This boolean indicates that this is the case, so that we
66                                    don't call select in that case.  Note that measurement
67                                    sockets are not concerned since they use the TCP
68                                    interface directly, with no buffer. */
69
70   int recvd:1;                  /* true if the recvd_val field contains one byte of the stream (that we peek'ed to check the socket validity) */
71   char recvd_val;               /* what we peeked from the socket, if any */
72
73   unsigned long int buf_size;   /* what to say to the OS. 
74                                    Field here to remember it when accepting */
75
76   int sd;
77   int port;                     /* port on this side */
78   int peer_port;                /* port on the other side */
79   char *peer_name;              /* hostname of the other side */
80   char *peer_proc;              /* process on the other side */
81
82   void *data;                   /* plugin specific data */
83
84   /* buffer plugin specific data. Yeah, C is not OO, so I got to trick */
85   gras_trp_bufdata_t *bufdata;
86 } s_gras_socket_t;
87
88 void gras_trp_socket_new(int incomming, gras_socket_t * dst);
89
90 /* The drivers */
91 typedef void (*gras_trp_setup_t) (gras_trp_plugin_t dst);
92
93 void gras_trp_tcp_setup(gras_trp_plugin_t plug);
94 void gras_trp_iov_setup(gras_trp_plugin_t plug);
95 void gras_trp_file_setup(gras_trp_plugin_t plug);
96 void gras_trp_sg_setup(gras_trp_plugin_t plug);
97
98 /* FIXME: this should be solved by SIMIX
99
100   I'm tired of that shit. the select in SG has to create a socket to expeditor
101   manually do deal with the weirdness of the hostdata, themselves here to deal
102   with the weird channel concept of SG and convert them back to ports.
103   
104   When introducing buffered transport (which I want to get used in SG to debug
105   the buffering itself), we should not make the rest of the code aware of the
106   change and not specify code for this. This is bad design.
107   
108   But there is bad design all over the place, so fuck off for now, when we can
109   get rid of MSG and rely directly on SG, this crude hack can go away. But in
110   the meanwhile, I want to sleep this night (FIXME).
111   
112   Hu! You evil problem! Taste my axe!
113
114 */
115
116 gras_socket_t gras_trp_buf_init_sock(gras_socket_t sock);
117
118 #endif                          /* GRAS_TRP_PRIVATE_H */