syn
[oweals/gnunet.git] / src / include / gnunet_network_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file include/gnunet_network_lib.h
23  * @brief basic low-level networking interface
24  * @author Nils Durner
25  */
26
27 #ifndef GNUNET_NETWORK_LIB_H_
28 #define GNUNET_NETWORK_LIB_H_
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_time_lib.h"
39
40
41 /**
42  * @brief handle to a socket
43  */
44 struct GNUNET_NETWORK_Descriptor;
45
46 /**
47  * @brief collection of IO descriptors
48  */
49 struct GNUNET_NETWORK_FDSet;
50
51 struct GNUNET_DISK_FileHandle;
52
53 struct GNUNET_NETWORK_Descriptor *GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Descriptor *desc,
54                       struct sockaddr *address,
55                       socklen_t *address_len);
56
57 int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Descriptor *desc,
58                     const struct sockaddr *address, socklen_t address_len);
59
60 int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Descriptor *desc);
61
62 int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Descriptor *desc,
63                        const struct sockaddr *address, socklen_t address_len);
64
65 int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Descriptor *desc, int level, int optname,
66        void *optval, socklen_t *optlen);
67
68 int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Descriptor *desc, int backlog);
69
70 ssize_t GNUNET_NETWORK_socket_read (const struct GNUNET_NETWORK_Descriptor *desc, void *buf,
71                         size_t nbyte);
72
73 ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Descriptor *desc, void *buffer,
74                         size_t length, int flags);
75
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);
79
80 /**
81  * Set if a socket should use blocking or non-blocking IO.
82  *
83  * @return GNUNET_OK on success, GNUNET_SYSERR on error
84  */
85 int GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Descriptor *fd, int doBlock);
86
87 ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Descriptor *desc,
88                         const void *buffer, size_t length, int flags);
89
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,
93                           socklen_t dest_len);
94
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);
97
98 int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Descriptor *desc, int how);
99
100 struct GNUNET_NETWORK_Descriptor *GNUNET_NETWORK_socket_socket (int domain, int type, int protocol);
101
102 ssize_t GNUNET_NETWORK_socket_write (const struct GNUNET_NETWORK_Descriptor *desc,
103                          const void *buf, size_t nbyte);
104
105
106 void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds);
107
108 void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds,
109     const struct GNUNET_NETWORK_Descriptor *desc);
110
111 int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds,
112     const struct GNUNET_NETWORK_Descriptor *desc);
113
114 void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
115     const struct GNUNET_NETWORK_FDSet *src);
116
117 void GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to,
118     const struct GNUNET_NETWORK_FDSet *from);
119
120 void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, const fd_set *from,
121     int nfds);
122
123 void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
124     const struct GNUNET_DISK_FileHandle *h);
125
126 int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
127     const struct GNUNET_DISK_FileHandle *h);
128
129 int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2);
130
131 struct GNUNET_NETWORK_FDSet *GNUNET_NETWORK_fdset_create ();
132
133 void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds);
134
135
136 #if 0                           /* keep Emacsens' auto-indent happy */
137 {
138 #endif
139 #ifdef __cplusplus
140 }
141 #endif
142
143 #endif /* GNUNET_NETWORK_LIB_H_ */