3 /* gras/socket.h - handling sockets in GRAS */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2003 the OURAGAN project. */
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. */
15 #include <stddef.h> /* offsetof() */
16 #include <sys/types.h> /* size_t */
20 /*! C++ users need love */
23 # define BEGIN_DECL extern "C" {
29 /*! C++ users need love */
37 /* End of cruft for C++ */
41 /****************************************************************************/
42 /* Openning/Maintaining/Closing connexions */
43 /****************************************************************************/
44 /** Number of channel opened at most on a given host within SimGrid */
45 #define MAX_CHANNEL 10
47 /*! Type of a communication socket */
48 typedef struct gras_sock_s gras_sock_t;
51 * gras_sock_client_open:
52 * @host: name of the host we want to connect to
53 * @Param2: port on which we want to connect on this host
54 * @sock: Newly created socket
55 * @Returns: an errcode
57 * Attempts to establish a connection to the server listening to host:port
60 gras_sock_client_open(const char *host, short port,
61 /* OUT */ gras_sock_t **sock);
64 * gras_sock_server_open:
65 * @Param1: starting port
66 * @Param2: ending port
67 * @sock: Newly create socket
68 * @Returns: an errcode
70 * Attempts to bind to any port between #startingPort# and #endingPort#,
73 * You can get the port on which you connected using grasSockGetPort().
76 gras_sock_server_open(unsigned short startingPort,
77 unsigned short endingPort,
78 /* OUT */ gras_sock_t **sock);
82 * @sock: The socket to close.
83 * @Returns: an errcode
85 * Tears down a socket.
87 gras_error_t gras_sock_close(gras_sock_t *sock);
90 /****************************************************************************/
91 /* Converting DNS name <-> IP */
92 /****************************************************************************/
94 * gras_sock_get_peer_name:
96 * @Returns: the DNS name of the host connected to #sd#, or descriptive text if
97 * #sd# is not an inter-host connection: returns NULL in case of error
99 * The value returned should not be freed.
102 gras_sock_get_peer_name(gras_sock_t *sd);
105 * gras_sock_get_peer_port:
107 * @Returns: the port number on the other side of socket sd. -1 is returned
108 * if pipes or unknown
111 gras_sock_get_peer_port(gras_sock_t *sd);
114 * gras_sock_get_peer_addr:
116 * @Returns: the IP address of the other side of this socket.
118 * can return NULL (out of memory condition).
119 * Do not free the result.
122 gras_sock_get_peer_addr(gras_sock_t *sd);
125 * gras_sock_get_my_port:
127 * @Returns: the port number on the this side of socket sd. -1 is returned
128 * if pipes or unknown
131 gras_sock_get_my_port(gras_sock_t *sd);
133 /* **************************************************************************
134 * Raw sockets and BW experiments (should be placed in another file)
135 * **************************************************************************/
136 typedef struct gras_rawsock_s gras_rawsock_t;
139 * gras_rawsock_client_open:
141 * Establishes a connection to @machine : @port on which the buffer sizes have
142 * been set to @bufSize bytes.
144 * Those sockets are meant to send raw data without any conversion, for example
145 * for bandwidth tests.
148 gras_rawsock_client_open(const char *host, short port, unsigned int bufSize,
149 /* OUT */ gras_rawsock_t **sock);
152 * gras_rawsock_server_open:
154 * Open a connexion waiting for external input, on which the buffer sizes have
155 * been set to @bufSize bytes.
157 * Those sockets are meant to send raw data without any conversion, for example
158 * for bandwidth tests.
161 gras_rawsock_server_open(unsigned short startingPort, unsigned short endingPort,
162 unsigned int bufSize, /* OUT */ gras_rawsock_t **sock);
165 * gras_rawsock_close:
167 * Close a raw socket.
169 * Those sockets are meant to send raw data without any conversion, for example
170 * for bandwidth tests.
173 gras_rawsock_close(gras_rawsock_t *sock);
176 * gras_rawsocket_get_my_port:
178 * @Returns: the port number on the this side of socket sd. -1 is returned
179 * if pipes or unknown
182 gras_rawsocket_get_my_port(gras_rawsock_t *sd);
185 * gras_rawsocket_get_peer_port:
187 * @Returns: the port number on the other side of socket sd. -1 is returned
188 * if pipes or unknown
191 gras_rawsock_get_peer_port(gras_rawsock_t *sd);
195 * @sock: on which raw socket to send the data
196 * @expSize: total size of data sent
197 * @msgSize: size of each message sent one after the other
199 * Send a raw bunch of data, for example for a bandwith test.
203 gras_rawsock_send(gras_rawsock_t *sd, unsigned int expSize, unsigned int msgSize);
207 * @sock: on which raw socket to read the data
208 * @expSize: total size of data received
209 * @msgSize: size of each message received one after the other
210 * @timeout: time to wait for that data
212 * Receive a raw bunch of data, for example for a bandwith test.
216 gras_rawsock_recv(gras_rawsock_t *sd, unsigned int expSize, unsigned int msgSize,
217 unsigned int timeout);
222 #endif /* GRAS_SOCK_H */