Logo AND Algorithmique Numérique Distribuée

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