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_disk_lib.h"
39 #include "gnunet_time_lib.h"
43 * @brief handle to a socket
45 struct GNUNET_NETWORK_Descriptor;
48 * @brief collection of IO descriptors
50 struct GNUNET_NETWORK_FDSet;
53 struct GNUNET_NETWORK_Descriptor *GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Descriptor *desc,
54 struct sockaddr *address,
55 socklen_t *address_len);
58 GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Descriptor
62 int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Descriptor *desc,
63 const struct sockaddr *address, socklen_t address_len);
65 int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Descriptor *desc);
67 int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Descriptor *desc,
68 const struct sockaddr *address, socklen_t address_len);
70 int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Descriptor *desc, int level, int optname,
71 void *optval, socklen_t *optlen);
73 int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Descriptor *desc, int backlog);
75 ssize_t GNUNET_NETWORK_socket_read (const struct GNUNET_NETWORK_Descriptor *desc, void *buf,
78 ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Descriptor *desc, void *buffer,
79 size_t length, int flags);
81 int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
82 struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds,
83 struct GNUNET_TIME_Relative timeout);
86 * Set if a socket should use blocking or non-blocking IO.
88 * @return GNUNET_OK on success, GNUNET_SYSERR on error
90 int GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Descriptor *fd, int doBlock);
92 ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Descriptor *desc,
93 const void *buffer, size_t length, int flags);
95 ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Descriptor *desc,
96 const void *message, size_t length, int flags,
97 const struct sockaddr *dest_addr,
100 int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Descriptor *fd, int level, int option_name,
101 const void *option_value, socklen_t option_len);
103 int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Descriptor *desc, int how);
105 struct GNUNET_NETWORK_Descriptor *GNUNET_NETWORK_socket_socket (int domain, int type, int protocol);
107 ssize_t GNUNET_NETWORK_socket_write (const struct GNUNET_NETWORK_Descriptor *desc,
108 const void *buf, size_t nbyte);
111 void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds);
113 void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds,
114 const struct GNUNET_NETWORK_Descriptor *desc);
116 int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds,
117 const struct GNUNET_NETWORK_Descriptor *desc);
119 void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
120 const struct GNUNET_NETWORK_FDSet *src);
122 void GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to,
123 const struct GNUNET_NETWORK_FDSet *from);
125 void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, const fd_set *from,
128 void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
129 const struct GNUNET_DISK_FileHandle *h);
131 int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
132 const struct GNUNET_DISK_FileHandle *h);
134 int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2);
136 struct GNUNET_NETWORK_FDSet *GNUNET_NETWORK_fdset_create (void);
138 void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds);
141 #if 0 /* keep Emacsens' auto-indent happy */
148 #endif /* GNUNET_NETWORK_LIB_H */