4 /* transport - low level communication (send/receive bunches of bytes) */
5 /* module's public interface exported to end user. */
7 /* Copyright (c) 2004 Martin Quinson. All rights reserved. */
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. */
12 #ifndef GRAS_TRANSPORT_H
13 #define GRAS_TRANSPORT_H
15 /** \addtogroup GRAS_sock
16 * \brief Socket handling
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.
23 * The main difference is that you cannot exchange arbitrary bytes on
24 * sockets, but messages. See the \ref GRAS_msg section for details.
26 * If you need an example of how to use sockets, check \ref GRAS_ex_ping.
30 /** \defgroup GRAS_sock_create Socket creation functions
35 /** \brief Opaque type describing a socket */
36 typedef struct s_gras_socket *gras_socket_t;
38 /** \brief Simply create a client socket (to speak to a remote host) */
39 gras_socket_t gras_socket_client(const char *host, unsigned short port);
40 /** \brief Simply create a server socket (to ear from remote hosts speaking to you) */
41 gras_socket_t gras_socket_server(unsigned short port);
42 /** \brief Close socket */
43 void gras_socket_close(gras_socket_t sd);
45 /** \brief Create a client socket, full interface to all relevant settings */
46 gras_socket_t gras_socket_client_ext(const char *host,
48 unsigned long int bufSize,
50 /** \brief Create a server socket, full interface to all relevant settings */
51 gras_socket_t gras_socket_server_ext(unsigned short port,
52 unsigned long int bufSize,
55 /** \defgroup GRAS_sock_info Retrieving data about sockets and peers
58 * Who are you talking to?
62 /** Get the port number on which this socket is connected on my side */
63 int gras_socket_my_port (gras_socket_t sock);
64 /** Get the port number on which this socket is connected on remote side */
65 int gras_socket_peer_port(gras_socket_t sock);
66 /** Get the host name of the remote side */
67 char *gras_socket_peer_name(gras_socket_t sock);
68 /** Get the process name of the remote side */
69 char *gras_socket_peer_proc(gras_socket_t sock);
72 /** \defgroup GRAS_sock_meas Using measurement sockets
75 * You may want to use sockets not to exchange valuable data (in messages),
76 * but to conduct some bandwidth measurements and related experiments. If so, try those measurement sockets.
78 * You can only use those functions on sockets openned with the "measurement" boolean set to true.
85 int gras_socket_is_meas(gras_socket_t sock);
86 void gras_socket_meas_send(gras_socket_t peer,
88 unsigned long int expSize,
89 unsigned long int msgSize);
90 void gras_socket_meas_recv(gras_socket_t peer,
92 unsigned long int expSize,
93 unsigned long int msgSize);
94 gras_socket_t gras_socket_meas_accept(gras_socket_t peer);
98 /** \defgroup GRAS_sock_file Using files as sockets
102 * For debugging purpose, it is possible to deal with files as if they were sockets.
103 * It can even be useful to store stuff in a portable manner, but writing messages to a file
106 * \bug Don't use '-' on windows. this file represents stdin or stdout, but I failed to deal with it on windows.
109 /* debuging functions */
110 gras_socket_t gras_socket_client_from_file(const char*path);
111 gras_socket_t gras_socket_server_from_file(const char*path);
115 #endif /* GRAS_TRANSPORT_H */