Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
A new little function I did need
[simgrid.git] / include / gras / transport.h
1 /* $Id$ */
2
3 /* transport - low level communication (send/receive bunches of bytes)      */
4 /* module's public interface exported to end user.                          */
5
6 /* Copyright (c) 2004 Martin Quinson. 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_TRANSPORT_H
12 #define GRAS_TRANSPORT_H
13
14 /** \addtogroup GRAS_sock
15  *  \brief Socket handling (Communication facility).
16  */
17
18 /** \name Socket creation functions
19  *  \ingroup GRAS_sock
20  */
21 /* @{*/
22 /** \brief Opaque type describing a socket */
23 typedef struct s_gras_socket *gras_socket_t;
24
25 /** \brief Simply create a client socket (to speak to a remote host) */
26 gras_socket_t gras_socket_client(const char *host, unsigned short port);
27 /** \brief Simply create a server socket (to ear from remote hosts speaking to you) */
28 gras_socket_t gras_socket_server(unsigned short port);
29 /** \brief Close socket */
30 void          gras_socket_close(gras_socket_t sd);
31
32 /** \brief Create a client socket, full interface to all relevant settings */
33 gras_socket_t gras_socket_client_ext(const char *host,
34                                      unsigned short port,
35                                      unsigned long int bufSize,
36                                      int measurement);
37 /** \brief Create a server socket, full interface to all relevant settings */
38 gras_socket_t gras_socket_server_ext(unsigned short port,
39                                      unsigned long int bufSize,
40                                      int measurement);
41 /* @}*/
42 /** \name Retrieving data about sockets and peers 
43  *  \ingroup GRAS_sock
44  * 
45  * Who are you talking to?
46  */
47 /* @{*/
48
49 /** Get the port number on which this socket is connected on my side */
50 int   gras_socket_my_port  (gras_socket_t sock);
51 /** Get the port number on which this socket is connected on remote side */
52 int   gras_socket_peer_port(gras_socket_t sock);
53 /** Get the host name of the remote side */
54 char *gras_socket_peer_name(gras_socket_t sock);
55 /* @}*/
56
57 /** \name Using measurement sockets
58  *  \ingroup GRAS_sock
59  * 
60  * You may want to use sockets not to exchange valuable data (in messages), 
61  * but to conduct some bandwidth measurements and related experiments. If so, try those measurement sockets.
62  * 
63  * You can only use those functions on sockets openned with the "measurement" boolean set to true.
64  * 
65  */
66 /* @{*/
67
68
69
70 int gras_socket_is_meas(gras_socket_t sock);
71 void gras_socket_meas_send(gras_socket_t peer, 
72                            unsigned int timeout,
73                            unsigned long int expSize, 
74                            unsigned long int msgSize);
75 void gras_socket_meas_recv(gras_socket_t peer, 
76                            unsigned int timeout,
77                            unsigned long int expSize, 
78                            unsigned long int msgSize);
79 gras_socket_t gras_socket_meas_accept(gras_socket_t peer);
80             
81 /* @}*/
82
83 /** \name Using files as sockets
84  *  \ingroup GRAS_sock
85  * 
86  * For debugging purpose, it is possible to deal with files as if they were sockets.
87  * It can even be useful to store stuff in a portable manner, but writing messages to a file
88  * may be strange...
89  * 
90  * \bug Don't use '-' on windows. this file represents stdin or stdout, but I failed to deal with it on windows.
91  */
92 /* @{*/
93 /* debuging functions */
94 gras_socket_t gras_socket_client_from_file(const char*path);
95 gras_socket_t gras_socket_server_from_file(const char*path);
96                                           
97 /* @} */
98    
99 #endif /* GRAS_TRANSPORT_H */