aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_network_lib.h
diff options
context:
space:
mode:
authorNils Durner <durner@gnunet.org>2009-08-30 21:06:23 +0000
committerNils Durner <durner@gnunet.org>2009-08-30 21:06:23 +0000
commita095a849fcd95efeb57db80b4346e4f2eedf9899 (patch)
tree07a94b227de9f37927d3aed7cc417821f80ddec1 /src/include/gnunet_network_lib.h
parentd986f2c7460120ffc3f199b29a06126d0b97b75b (diff)
downloadgnunet-a095a849fcd95efeb57db80b4346e4f2eedf9899.tar.gz
gnunet-a095a849fcd95efeb57db80b4346e4f2eedf9899.zip
docs & GNUnet-style return codes
Diffstat (limited to 'src/include/gnunet_network_lib.h')
-rw-r--r--src/include/gnunet_network_lib.h170
1 files changed, 160 insertions, 10 deletions
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h
index b475ff4f0..97fcf2618 100644
--- a/src/include/gnunet_network_lib.h
+++ b/src/include/gnunet_network_lib.h
@@ -51,93 +51,243 @@ struct GNUNET_NETWORK_FDSet;
51#include "gnunet_disk_lib.h" 51#include "gnunet_disk_lib.h"
52#include "gnunet_time_lib.h" 52#include "gnunet_time_lib.h"
53 53
54 54/**
55 * accept a new connection on a socket
56 *
57 * @param desc bound socket
58 * @param address address of the connecting peer, may be NULL
59 * @param address_len length of address
60 * @return client socket
61 */
55struct GNUNET_NETWORK_Handle * 62struct GNUNET_NETWORK_Handle *
56GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, 63GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
57 struct sockaddr *address, 64 struct sockaddr *address,
58 socklen_t *address_len); 65 socklen_t *address_len);
59 66
67/**
68 * Make a non-inheritable to child processes
69 * @param socket
70 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
71 * @warning Not implemented on Windows
72 */
60int 73int
61GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle 74GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle
62 *desc); 75 *desc);
63 76
64 77/**
78 * Bind to a connected socket
79 * @param desc socket
80 * @param address address to be bound
81 * @param address_len length of address
82 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
83 */
65int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, 84int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
66 const struct sockaddr *address, socklen_t address_len); 85 const struct sockaddr *address, socklen_t address_len);
67 86
87/**
88 * Close a socket
89 * @param desc socket
90 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
91 */
68int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc); 92int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc);
69 93
94/**
95 * Connect a socket
96 * @param desc socket
97 * @param address peer address
98 * @param length of address
99 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
100 */
70int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, 101int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
71 const struct sockaddr *address, socklen_t address_len); 102 const struct sockaddr *address, socklen_t address_len);
72 103
104/**
105 * Get socket options
106 * @param desc socket
107 * @param level protocol level of the option
108 * @param optname identifier of the option
109 * @param optval options
110 * @param optlen length of optval
111 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
112 */
73int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, int level, int optname, 113int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, int level, int optname,
74 void *optval, socklen_t *optlen); 114 void *optval, socklen_t *optlen);
75 115
116/**
117 * Listen on a socket
118 * @param desc socket
119 * @param backlog length of the listen queue
120 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
121 */
76int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, int backlog); 122int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, int backlog);
77 123
78ssize_t GNUNET_NETWORK_socket_read (const struct GNUNET_NETWORK_Handle *desc, void *buf, 124/**
79 size_t nbyte); 125 * Read data from a connected socket
80 126 * @param desc socket
127 * @param buffer buffer
128 * @param length length of buffer
129 * @param flags type of message reception
130 */
81ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc, void *buffer, 131ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc, void *buffer,
82 size_t length, int flags); 132 size_t length, int flags);
83 133
134/**
135 * Check if sockets meet certain conditions
136 * @param rfds set of sockets to be checked for readability
137 * @param wfds set of sockets to be checked for writability
138 * @param efds set of sockets to be checked for exceptions
139 * @param timeout relative value when to return
140 * @return number of selected sockets, GNUNET_SYSERR on error
141 */
84int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, 142int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
85 struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds, 143 struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds,
86 struct GNUNET_TIME_Relative timeout); 144 struct GNUNET_TIME_Relative timeout);
87 145
88/** 146/**
89 * Set if a socket should use blocking or non-blocking IO. 147 * Set if a socket should use blocking or non-blocking IO.
90 * 148 * @param fd socket
149 * @param doBlock blocking mode
91 * @return GNUNET_OK on success, GNUNET_SYSERR on error 150 * @return GNUNET_OK on success, GNUNET_SYSERR on error
92 */ 151 */
93int GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock); 152int GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock);
94 153
154/**
155 * Send data
156 * @param desc socket
157 * @param buffer data to send
158 * @param length size of the buffer
159 * @param flags type of message transmission
160 * @return number of bytes sent, GNUNET_SYSERR on error
161 */
95ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc, 162ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc,
96 const void *buffer, size_t length, int flags); 163 const void *buffer, size_t length, int flags);
97 164
165/**
166 * Send data
167 * @param desc socket
168 * @param message data to send
169 * @param length size of the data
170 * @param flags type of message transmission
171 * @param dest_addr destination address
172 * @param dest_len length of address
173 * @return number of bytes sent, GNUNET_SYSERR on error
174 */
98ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle *desc, 175ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle *desc,
99 const void *message, size_t length, int flags, 176 const void *message, size_t length, int flags,
100 const struct sockaddr *dest_addr, 177 const struct sockaddr *dest_addr,
101 socklen_t dest_len); 178 socklen_t dest_len);
102 179
180/**
181 * Set socket option
182 * @param fd socket
183 * @param level protocol level of the option
184 * @param option_name option identifier
185 * @param option_value value to set
186 * @param option_len size of option_value
187 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
188 */
103int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, 189int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name,
104 const void *option_value, socklen_t option_len); 190 const void *option_value, socklen_t option_len);
105 191
192/**
193 * Shut down socket operations
194 * @param desc socket
195 * @param how type of shutdown
196 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
197 */
106int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how); 198int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how);
107 199
200/**
201 * Create a new socket
202 * @param domain domain of the socket
203 * @param type socket type
204 * @param protocol network protocol
205 * @return new socket, NULL on error
206 */
108struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_socket (int domain, int type, int protocol); 207struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_socket (int domain, int type, int protocol);
109 208
110ssize_t GNUNET_NETWORK_socket_write (const struct GNUNET_NETWORK_Handle *desc, 209/**
111 const void *buf, size_t nbyte); 210 * Reset FD set
112 211 * @param fds fd set
113 212 */
114void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds); 213void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds);
115 214
215/**
216 * Add a socket to the FD set
217 * @param fds fd set
218 * @param desc socket to add
219 */
116void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds, 220void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds,
117 const struct GNUNET_NETWORK_Handle *desc); 221 const struct GNUNET_NETWORK_Handle *desc);
118 222
223/**
224 * Check whether a socket is part of the fd set
225 * @param fds fd set
226 * @param desc socket
227 */
119int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, 228int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds,
120 const struct GNUNET_NETWORK_Handle *desc); 229 const struct GNUNET_NETWORK_Handle *desc);
121 230
231/**
232 * Add one fd set to another
233 * @param dst the fd set to add to
234 * @param src the fd set to add from
235 */
122void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, 236void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
123 const struct GNUNET_NETWORK_FDSet *src); 237 const struct GNUNET_NETWORK_FDSet *src);
124 238
239/**
240 * Copy one fd set to another
241 * @param to destination
242 * @param from source
243 */
125void GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to, 244void GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to,
126 const struct GNUNET_NETWORK_FDSet *from); 245 const struct GNUNET_NETWORK_FDSet *from);
127 246
247/**
248 * Copy a native fd set
249 * @param to destination
250 * @param from native source set
251 * @param the biggest socket number in from + 1
252 */
128void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, const fd_set *from, 253void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, const fd_set *from,
129 int nfds); 254 int nfds);
130 255
256/**
257 * Add a file handle to the fd set
258 * @param fds fd set
259 * @param h the file handle to add
260 */
131void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, 261void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
132 const struct GNUNET_DISK_FileHandle *h); 262 const struct GNUNET_DISK_FileHandle *h);
133 263
264/**
265 * Check if a file handle is part of an fd set
266 * @param fds fd set
267 * @param h file handle
268 * @return GNUNET_YES if the file handle is part of the set
269 */
134int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, 270int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
135 const struct GNUNET_DISK_FileHandle *h); 271 const struct GNUNET_DISK_FileHandle *h);
136 272
273/**
274 * Checks if two fd sets overlap
275 * @param fds1 first fd set
276 * @param fds2 second fd set
277 * @return GNUNET_YES if they do overlap, GNUNET_NO otherwise
278 */
137int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2); 279int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2);
138 280
281/**
282 * Creates an fd set
283 * @return a new fd set
284 */
139struct GNUNET_NETWORK_FDSet *GNUNET_NETWORK_fdset_create (void); 285struct GNUNET_NETWORK_FDSet *GNUNET_NETWORK_fdset_create (void);
140 286
287/**
288 * Releases the associated memory of an fd set
289 * @param fds fd set
290 */
141void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds); 291void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds);
142 292
143 293