3 /* transport - low level communication (send/receive bunches of bytes) */
4 /* module's public interface exported to end user. */
6 /* Copyright (c) 2004 Martin Quinson. 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_TRANSPORT_H
12 #define GRAS_TRANSPORT_H
14 /** \addtogroup GRAS_sock
15 * \brief Socket handling (Communication facility).
17 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref GRAS_API]
18 * <tr><td><b>Prev</b> <td> [\ref GRAS_dd]
19 * <tr><td><b>Next</b> <td> [\ref GRAS_msg]
20 * <tr><td><b>Down</b> <td> [\ref GRAS_sock_create] </table></center>
22 * The model of communications in GRAS is very close to the BSD socket one. To get two hosts
23 * exchanging data, one of them need to open a <i>server</i> socket on which it can listen for incoming messages
24 * and the other one must connect a <i>client</i> socket onto the server one.
26 * If you need an example of this, check \ref GRAS_ex_ping.
30 /** \defgroup GRAS_sock_create Socket creation functions
33 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref GRAS_API]::[\ref GRAS_sock]
35 * <tr><td><b>Next</b> <td> [\ref GRAS_sock_info] </table></center>
38 /** \brief Opaque type describing a socket */
39 typedef struct s_gras_socket *gras_socket_t;
41 /** \brief Simply create a client socket (to speak to a remote host) */
42 gras_socket_t gras_socket_client(const char *host, unsigned short port);
43 /** \brief Simply create a server socket (to ear from remote hosts speaking to you) */
44 gras_socket_t gras_socket_server(unsigned short port);
45 /** \brief Close socket */
46 void gras_socket_close(gras_socket_t sd);
48 /** \brief Create a client socket, full interface to all relevant settings */
49 gras_socket_t gras_socket_client_ext(const char *host,
51 unsigned long int bufSize,
53 /** \brief Create a server socket, full interface to all relevant settings */
54 gras_socket_t gras_socket_server_ext(unsigned short port,
55 unsigned long int bufSize,
58 /** \defgroup GRAS_sock_info Retrieving data about sockets and peers
61 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref GRAS_API]::[\ref GRAS_sock]
62 * <tr><td><b>Prev</b> <td> [\ref GRAS_sock_create]
63 * <tr><td><b>Next</b> <td> [\ref GRAS_sock_meas] </table></center>
65 * Who are you talking to?
69 /** Get the port number on which this socket is connected on my side */
70 int gras_socket_my_port (gras_socket_t sock);
71 /** Get the port number on which this socket is connected on remote side */
72 int gras_socket_peer_port(gras_socket_t sock);
73 /** Get the host name of the remote side */
74 char *gras_socket_peer_name(gras_socket_t sock);
77 /** \defgroup GRAS_sock_meas Using measurement sockets
80 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref GRAS_API]::[\ref GRAS_sock]
81 * <tr><td><b>Prev</b> <td> [\ref GRAS_sock_info]
82 * <tr><td><b>Next</b> <td> [\ref GRAS_sock_file] </table></center>
84 * You may want to use sockets not to exchange valuable data (in messages),
85 * but to conduct some bandwidth measurements and related experiments. If so, try those measurement sockets.
87 * You can only use those functions on sockets openned with the "measurement" boolean set to true.
94 int gras_socket_is_meas(gras_socket_t sock);
95 void gras_socket_meas_send(gras_socket_t peer,
97 unsigned long int expSize,
98 unsigned long int msgSize);
99 void gras_socket_meas_recv(gras_socket_t peer,
100 unsigned int timeout,
101 unsigned long int expSize,
102 unsigned long int msgSize);
103 gras_socket_t gras_socket_meas_accept(gras_socket_t peer);
107 /** \defgroup GRAS_sock_file Using files as sockets
110 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref GRAS_API]::[\ref GRAS_sock]
111 * <tr><td><b>Prev</b> <td> [\ref GRAS_sock_meas]
112 * <tr><td>Next <td> </table></center>
114 * For debugging purpose, it is possible to deal with files as if they were sockets.
115 * It can even be useful to store stuff in a portable manner, but writing messages to a file
118 * \bug Don't use '-' on windows. this file represents stdin or stdout, but I failed to deal with it on windows.
121 /* debuging functions */
122 gras_socket_t gras_socket_client_from_file(const char*path);
123 gras_socket_t gras_socket_server_from_file(const char*path);
127 #endif /* GRAS_TRANSPORT_H */