Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Continue documenting my changes
[simgrid.git] / include / gras / transport.h
1
2 /* $Id$ */
3
4 /* transport - low level communication (send/receive bunches of bytes)      */
5 /* module's public interface exported 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_TRANSPORT_H
13 #define GRAS_TRANSPORT_H
14
15 /** \addtogroup GRAS_sock
16  *  \brief Socket handling
17  *
18  * The model of communications in GRAS is very close to the BSD socket one.
19  * To get two hosts exchanging data, one of them need to open a
20  * <i>server</i> socket on which it can listen for incoming messages and the
21  * other one must connect a <i>client</i> socket onto the server one.
22  *
23  * The main difference is that you cannot exchange arbitrary bytes on
24  * sockets, but messages. See the \ref GRAS_msg section for details.
25  * 
26  * If you need an example of how to use sockets, check \ref GRAS_ex_ping.
27  *
28  */
29  
30 /** \defgroup GRAS_sock_create Socket creation functions
31  *  \ingroup GRAS_sock
32  *
33  */
34 /* @{*/
35 /** \brief Opaque type describing a socket */
36 typedef struct s_gras_socket *gras_socket_t;
37
38 /** \brief Simply create a client socket (to speak to a remote host) */
39 XBT_PUBLIC(gras_socket_t) gras_socket_client(const char *host, unsigned short port);
40 XBT_PUBLIC(gras_socket_t) gras_socket_client_from_string(const char *host);
41 /** \brief Simply create a server socket (to ear from remote hosts speaking to you) */
42 XBT_PUBLIC(gras_socket_t) gras_socket_server(unsigned short port);
43 XBT_PUBLIC(void)          gras_socket_close(gras_socket_t sd);
44
45 /** \brief Create a client socket, full interface to all relevant settings */
46 XBT_PUBLIC(gras_socket_t) gras_socket_client_ext(const char *host,
47                                      unsigned short port,
48                                      unsigned long int bufSize,
49                                      int measurement);
50 /** \brief Create a server socket, full interface to all relevant settings */
51 XBT_PUBLIC(gras_socket_t) gras_socket_server_ext(unsigned short port,
52                                      unsigned long int bufSize,
53                                      int measurement);
54 XBT_PUBLIC(gras_socket_t)
55 gras_socket_server_range(unsigned short minport, unsigned short maxport,
56                          unsigned long int buf_size, int measurement);
57
58 /* @}*/
59 /** \defgroup GRAS_sock_info Retrieving data about sockets and peers 
60  *  \ingroup GRAS_sock
61  * 
62  * Who are you talking to? 
63  */
64 /* @{*/
65
66 /** Get the port number on which this socket is connected on my side */
67 XBT_PUBLIC(int)   gras_socket_my_port  (gras_socket_t sock);
68 /** @brief Get the port number on which this socket is connected on remote side 
69  *
70  * This is the port declared on remote side with the
71  * gras_socket_master() function (if any, or a random number being uniq on 
72  * the remote host). If remote used gras_socket_master() more than once, the 
73  * lastly declared number will be used here.
74  *
75  * Note to BSD sockets experts: With BSD sockets, the sockaddr 
76  * structure allows you to retrieve the port of the client socket on
77  * remote side, but it is of no use (from user perspective, it is
78  * some random number above 6000). That is why GRAS sockets differ
79  * from BSD ones here. 
80  */
81
82 XBT_PUBLIC(int)   gras_socket_peer_port(gras_socket_t sock);
83 /** Get the host name of the remote side */
84 XBT_PUBLIC(char *) gras_socket_peer_name(gras_socket_t sock);
85 /** Get the process name of the remote side */
86 XBT_PUBLIC(char *) gras_socket_peer_proc(gras_socket_t sock);
87 /* @}*/
88
89 /** \defgroup GRAS_sock_meas Using measurement sockets
90  *  \ingroup GRAS_sock
91  * 
92  * You may want to use sockets not to exchange valuable data (in messages), 
93  * but to conduct some bandwidth measurements and related experiments. If so, try those measurement sockets.
94  * 
95  * You can only use those functions on sockets openned with the "measurement" boolean set to true.
96  * 
97  */
98 /* @{*/
99
100
101
102 XBT_PUBLIC(int) gras_socket_is_meas(gras_socket_t sock);
103 XBT_PUBLIC(void) gras_socket_meas_send(gras_socket_t peer, 
104                                       unsigned int timeout,
105                                       unsigned long int msgSize, 
106                                       unsigned long int msgAmount);
107 XBT_PUBLIC(void) gras_socket_meas_recv(gras_socket_t peer, 
108                                       unsigned int timeout,
109                                       unsigned long int msgSize, 
110                                       unsigned long int msgAmount);
111 XBT_PUBLIC(gras_socket_t) gras_socket_meas_accept(gras_socket_t peer);
112             
113 /* @}*/
114
115 /** \defgroup GRAS_sock_file Using files as sockets
116  *  \ingroup GRAS_sock
117  * 
118  *
119  * For debugging purpose, it is possible to deal with files as if they were sockets.
120  * It can even be useful to store stuff in a portable manner, but writing messages to a file
121  * may be strange...
122  * 
123  * \bug Don't use '-' on windows. this file represents stdin or stdout, but I failed to deal with it on windows.
124  */
125 /* @{*/
126 /* debuging functions */
127 XBT_PUBLIC(gras_socket_t) gras_socket_client_from_file(const char*path);
128 XBT_PUBLIC(gras_socket_t) gras_socket_server_from_file(const char*path);
129                                           
130 /* @} */
131    
132 #endif /* GRAS_TRANSPORT_H */