1 /* transport - low level communication (send/receive bunches of bytes) */
3 /* module's private interface masked even to other parts of GRAS. */
5 /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
6 * All rights reserved. */
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. */
11 #ifndef GRAS_TRP_PRIVATE_H
12 #define GRAS_TRP_PRIVATE_H
14 #include "xbt/sysdep.h"
16 #include "xbt/dynar.h"
19 #include "gras/emul.h" /* gras_if_RL() */
21 #include "gras_modinter.h" /* module init/exit */
22 #include "gras/transport.h" /* rest of module interface */
24 #include "gras/Transport/transport_interface.h" /* semi-public API */
25 #include "gras/Virtu/virtu_interface.h" /* libdata management */
27 extern int gras_trp_libdata_id; /* our libdata identifier */
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).
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
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.
42 It gets tricky since gras_socket_close is part of the common API, not
44 extern gras_socket_t _gras_lastly_selected_socket;
49 * Description of a socket.
51 typedef struct gras_trp_bufdata_ gras_trp_bufdata_t;
53 typedef struct s_gras_socket {
54 gras_trp_plugin_t plugin;
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
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. */
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 */
73 int refcount; /* refcounting on shared sockets */
75 unsigned long int buf_size; /* what to say to the OS.
76 Field here to remember it when accepting */
80 void *data; /* plugin specific data */
82 /* buffer plugin specific data. Yeah, C is not OO, so I got to trick */
83 gras_trp_bufdata_t *bufdata;
86 void gras_trp_socket_new(int incomming, gras_socket_t * dst);
89 typedef void (*gras_trp_setup_t) (gras_trp_plugin_t dst);
91 void gras_trp_tcp_setup(gras_trp_plugin_t plug);
92 void gras_trp_iov_setup(gras_trp_plugin_t plug);
93 void gras_trp_file_setup(gras_trp_plugin_t plug);
94 void gras_trp_sg_setup(gras_trp_plugin_t plug);
96 /* FIXME: this should be solved by SIMIX
98 I'm tired of that shit. the select in SG has to create a socket to expeditor
99 manually do deal with the weirdness of the hostdata, themselves here to deal
100 with the weird channel concept of SG and convert them back to ports.
102 When introducing buffered transport (which I want to get used in SG to debug
103 the buffering itself), we should not make the rest of the code aware of the
104 change and not specify code for this. This is bad design.
106 But there is bad design all over the place, so fuck off for now, when we can
107 get rid of MSG and rely directly on SG, this crude hack can go away. But in
108 the meanwhile, I want to sleep this night (FIXME).
110 Hu! You evil problem! Taste my axe!
114 gras_socket_t gras_trp_buf_init_sock(gras_socket_t sock);
116 #endif /* GRAS_TRP_PRIVATE_H */