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 */
41 * @brief handle to a socket
43 struct GNUNET_NETWORK_Handle;
46 * @brief collection of IO descriptors
48 struct GNUNET_NETWORK_FDSet;
51 #include "gnunet_disk_lib.h"
52 #include "gnunet_time_lib.h"
55 struct GNUNET_NETWORK_Handle *
56 GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
57 struct sockaddr *address,
58 socklen_t *address_len);
61 GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle
65 int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
66 const struct sockaddr *address, socklen_t address_len);
68 int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc);
70 int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
71 const struct sockaddr *address, socklen_t address_len);
73 int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, int level, int optname,
74 void *optval, socklen_t *optlen);
76 int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, int backlog);
78 ssize_t GNUNET_NETWORK_socket_read (const struct GNUNET_NETWORK_Handle *desc, void *buf,
81 ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc, void *buffer,
82 size_t length, int flags);
84 int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
85 struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds,
86 struct GNUNET_TIME_Relative timeout);
89 * Set if a socket should use blocking or non-blocking IO.
91 * @return GNUNET_OK on success, GNUNET_SYSERR on error
93 int GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock);
95 ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc,
96 const void *buffer, size_t length, int flags);
98 ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle *desc,
99 const void *message, size_t length, int flags,
100 const struct sockaddr *dest_addr,
103 int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name,
104 const void *option_value, socklen_t option_len);
106 int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how);
108 struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_socket (int domain, int type, int protocol);
110 ssize_t GNUNET_NETWORK_socket_write (const struct GNUNET_NETWORK_Handle *desc,
111 const void *buf, size_t nbyte);
114 void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds);
116 void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds,
117 const struct GNUNET_NETWORK_Handle *desc);
119 int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds,
120 const struct GNUNET_NETWORK_Handle *desc);
122 void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
123 const struct GNUNET_NETWORK_FDSet *src);
125 void GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to,
126 const struct GNUNET_NETWORK_FDSet *from);
128 void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, const fd_set *from,
131 void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
132 const struct GNUNET_DISK_FileHandle *h);
134 int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
135 const struct GNUNET_DISK_FileHandle *h);
137 int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2);
139 struct GNUNET_NETWORK_FDSet *GNUNET_NETWORK_fdset_create (void);
141 void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds);
144 #if 0 /* keep Emacsens' auto-indent happy */
151 #endif /* GNUNET_NETWORK_LIB_H */