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 #include "xbt/error.h"
16 /** \addtogroup GRAS_sock
17 * \brief Socket handling (Communication facility).
20 /** \name Socket creation functions
24 /** \brief Opaque type describing a socket */
25 typedef struct s_gras_socket *gras_socket_t;
27 /** \brief Simply create a client socket (to speak to a remote host) */
28 xbt_error_t gras_socket_client(const char *host,
30 /* OUT */ gras_socket_t *dst);
31 /** \brief Simply create a server socket (to ear from remote hosts speaking to you) */
32 xbt_error_t gras_socket_server(unsigned short port,
33 /* OUT */ gras_socket_t *dst);
34 /** \brief Close socket */
35 void gras_socket_close(gras_socket_t sd);
37 /** \brief Create a client socket, full interface to all relevant settings */
38 xbt_error_t gras_socket_client_ext(const char *host,
40 unsigned long int bufSize,
42 /* OUT */ gras_socket_t *dst);
43 /** \brief Create a server socket, full interface to all relevant settings */
44 xbt_error_t gras_socket_server_ext(unsigned short port,
45 unsigned long int bufSize,
47 /* OUT */ gras_socket_t *dst);
49 /** \name Retrieving data about sockets and peers
52 * Who are you talking to?
56 /** Get the port number on which this socket is connected on my side */
57 int gras_socket_my_port (gras_socket_t sock);
58 /** Get the port number on which this socket is connected on remote side */
59 int gras_socket_peer_port(gras_socket_t sock);
60 /** Get the host name of the remote side */
61 char *gras_socket_peer_name(gras_socket_t sock);
64 /** \name Using measurement sockets
67 * You may want to use sockets not to exchange valuable data (in messages),
68 * but to conduct some bandwidth measurements and related experiments. If so, try those measurement sockets.
70 * You can only use those functions on sockets openned with the "measurement" boolean set to true.
77 int gras_socket_is_meas(gras_socket_t sock);
78 xbt_error_t gras_socket_meas_send(gras_socket_t peer,
80 unsigned long int expSize,
81 unsigned long int msgSize);
82 xbt_error_t gras_socket_meas_recv(gras_socket_t peer,
84 unsigned long int expSize,
85 unsigned long int msgSize);
86 xbt_error_t gras_socket_meas_accept(gras_socket_t peer,gras_socket_t *accepted);
90 /** \name Using files as sockets
93 * For debugging purpose, it is possible to deal with files as if they were sockets.
94 * It can even be useful to store stuff in a portable manner, but writing messages to a file
97 * \bug Don't use '-' on windows. this file represents stdin or stdout, but I failed to deal with it on windows.
100 /* debuging functions */
101 xbt_error_t gras_socket_client_from_file(const char*path,
102 /* OUT */ gras_socket_t *dst);
103 xbt_error_t gras_socket_server_from_file(const char*path,
104 /* OUT */ gras_socket_t *dst);
108 #endif /* GRAS_TRANSPORT_H */