2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_network_lib.h
23 * @brief basic low-level networking interface
27 #ifndef GNUNET_NETWORK_LIB_H_
28 #define GNUNET_NETWORK_LIB_H_
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_time_lib.h"
42 * @brief handle to a socket
44 struct GNUNET_NETWORK_Descriptor;
47 * @brief collection of IO descriptors
49 struct GNUNET_NETWORK_FDSet;
51 struct GNUNET_DISK_FileHandle;
53 struct GNUNET_NETWORK_Descriptor *GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Descriptor *desc,
54 struct sockaddr *address,
55 socklen_t *address_len);
57 int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Descriptor *desc,
58 const struct sockaddr *address, socklen_t address_len);
60 int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Descriptor *desc);
62 int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Descriptor *desc,
63 const struct sockaddr *address, socklen_t address_len);
65 int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Descriptor *desc, int level, int optname,
66 void *optval, socklen_t *optlen);
68 int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Descriptor *desc, int backlog);
70 ssize_t GNUNET_NETWORK_socket_read (const struct GNUNET_NETWORK_Descriptor *desc, void *buf,
73 ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Descriptor *desc, void *buffer,
74 size_t length, int flags);
76 int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
77 struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds,
78 struct GNUNET_TIME_Relative timeout);
81 * Set if a socket should use blocking or non-blocking IO.
83 * @return GNUNET_OK on success, GNUNET_SYSERR on error
85 int GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Descriptor *fd, int doBlock);
87 ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Descriptor *desc,
88 const void *buffer, size_t length, int flags);
90 ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Descriptor *desc,
91 const void *message, size_t length, int flags,
92 const struct sockaddr *dest_addr,
95 int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Descriptor *fd, int level, int option_name,
96 const void *option_value, socklen_t option_len);
98 int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Descriptor *desc, int how);
100 struct GNUNET_NETWORK_Descriptor *GNUNET_NETWORK_socket_socket (int domain, int type, int protocol);
102 ssize_t GNUNET_NETWORK_socket_write (const struct GNUNET_NETWORK_Descriptor *desc,
103 const void *buf, size_t nbyte);
106 void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds);
108 void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds,
109 const struct GNUNET_NETWORK_Descriptor *desc);
111 int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds,
112 const struct GNUNET_NETWORK_Descriptor *desc);
114 void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
115 const struct GNUNET_NETWORK_FDSet *src);
117 void GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to,
118 const struct GNUNET_NETWORK_FDSet *from);
120 void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, const fd_set *from,
123 void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
124 const struct GNUNET_DISK_FileHandle *h);
126 int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
127 const struct GNUNET_DISK_FileHandle *h);
129 int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2);
131 struct GNUNET_NETWORK_FDSet *GNUNET_NETWORK_fdset_create ();
133 void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds);
136 #if 0 /* keep Emacsens' auto-indent happy */
143 #endif /* GNUNET_NETWORK_LIB_H_ */