2 /* transport - low level communication (send/receive bunches of bytes) */
3 /* module's public interface exported to end user. */
5 /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
6 * 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
17 * The model of communications in GRAS is very close to the BSD socket one.
18 * To get two hosts exchanging data, one of them need to open a
19 * <i>server</i> socket on which it can listen for incoming messages and the
20 * other one must connect a <i>client</i> socket onto the server one.
22 * The main difference is that you cannot exchange arbitrary bytes on
23 * sockets, but messages. See the \ref GRAS_msg section for details.
25 * If you need an example of how to use sockets, check \ref GRAS_ex_ping.
29 /** \defgroup GRAS_sock_create Socket creation functions
34 /** \brief Opaque type describing a socket */
35 typedef struct s_gras_socket *gras_socket_t;
37 /** \brief Simply create a client socket (to speak to a remote host) */
38 XBT_PUBLIC(gras_socket_t) gras_socket_client(const char *host,
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 XBT_PUBLIC(void) gras_socket_close_voidp(void *sock);
46 /** \brief Create a client socket, full interface to all relevant settings */
47 XBT_PUBLIC(gras_socket_t) gras_socket_client_ext(const char *host,
49 unsigned long int bufSize,
51 /** \brief Create a server socket, full interface to all relevant settings */
52 XBT_PUBLIC(gras_socket_t) gras_socket_server_ext(unsigned short port,
53 unsigned long int bufSize,
55 XBT_PUBLIC(gras_socket_t)
56 gras_socket_server_range(unsigned short minport, unsigned short maxport,
57 unsigned long int buf_size, int measurement);
60 /** \defgroup GRAS_sock_info Retrieving data about sockets and peers
63 * Who are you talking to?
67 /** Get the port number on which this socket is connected on my side */
68 XBT_PUBLIC(int) gras_socket_my_port(gras_socket_t sock);
69 /** @brief Get the port number on which this socket is connected on remote side
71 * This is the port declared on remote side with the
72 * gras_socket_master() function (if any, or a random number being uniq on
73 * the remote host). If remote used gras_socket_master() more than once, the
74 * lastly declared number will be used here.
76 * Note to BSD sockets experts: With BSD sockets, the sockaddr
77 * structure allows you to retrieve the port of the client socket on
78 * remote side, but it is of no use (from user perspective, it is
79 * some random number above 6000). That is why GRAS sockets differ
83 XBT_PUBLIC(int) gras_socket_peer_port(gras_socket_t sock);
84 /** Get the host name of the remote side */
85 XBT_PUBLIC(const char *) gras_socket_peer_name(gras_socket_t sock);
86 /** Get the process name of the remote side */
87 XBT_PUBLIC(const char *) gras_socket_peer_proc(gras_socket_t sock);
90 /** \defgroup GRAS_sock_meas Using measurement sockets
93 * You may want to use sockets not to exchange valuable data (in messages),
94 * but to conduct some bandwidth measurements and related experiments. If so, try those measurement sockets.
96 * You can only use those functions on sockets openned with the "measurement" boolean set to true.
103 XBT_PUBLIC(int) gras_socket_is_meas(gras_socket_t sock);
104 XBT_PUBLIC(void) gras_socket_meas_send(gras_socket_t peer,
105 unsigned int timeout,
106 unsigned long int msgSize,
107 unsigned long int msgAmount);
108 XBT_PUBLIC(void) gras_socket_meas_recv(gras_socket_t peer,
109 unsigned int timeout,
110 unsigned long int msgSize,
111 unsigned long int msgAmount);
112 XBT_PUBLIC(gras_socket_t) gras_socket_meas_accept(gras_socket_t peer);
116 /** \defgroup GRAS_sock_file Using files as sockets
120 * For debugging purpose, it is possible to deal with files as if they were sockets.
121 * It can even be useful to store stuff in a portable manner, but writing messages to a file
124 * \bug Don't use '-' on windows. this file represents stdin or stdout, but I failed to deal with it on windows.
127 /* debuging functions */
128 XBT_PUBLIC(gras_socket_t) gras_socket_client_from_file(const char *path);
129 XBT_PUBLIC(gras_socket_t) gras_socket_server_from_file(const char *path);
133 #endif /* GRAS_TRANSPORT_H */