sblocks
[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
39
40 /**
41  * @brief handle to a socket
42  */
43 struct GNUNET_NETWORK_Handle;
44
45 /**
46  * @brief collection of IO descriptors
47  */
48 struct GNUNET_NETWORK_FDSet;
49
50
51 #include "gnunet_disk_lib.h"
52 #include "gnunet_time_lib.h"
53
54
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);
59
60 int
61 GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle
62                                        *desc);
63
64
65 int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
66                     const struct sockaddr *address, socklen_t address_len);
67
68 int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc);
69
70 int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
71                        const struct sockaddr *address, socklen_t address_len);
72
73 int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, int level, int optname,
74        void *optval, socklen_t *optlen);
75
76 int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, int backlog);
77
78 ssize_t GNUNET_NETWORK_socket_read (const struct GNUNET_NETWORK_Handle *desc, void *buf,
79                         size_t nbyte);
80
81 ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc, void *buffer,
82                         size_t length, int flags);
83
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);
87
88 /**
89  * Set if a socket should use blocking or non-blocking IO.
90  *
91  * @return GNUNET_OK on success, GNUNET_SYSERR on error
92  */
93 int GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock);
94
95 ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc,
96                         const void *buffer, size_t length, int flags);
97
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,
101                           socklen_t dest_len);
102
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);
105
106 int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how);
107
108 struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_socket (int domain, int type, int protocol);
109
110 ssize_t GNUNET_NETWORK_socket_write (const struct GNUNET_NETWORK_Handle *desc,
111                          const void *buf, size_t nbyte);
112
113
114 void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds);
115
116 void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds,
117     const struct GNUNET_NETWORK_Handle *desc);
118
119 int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds,
120     const struct GNUNET_NETWORK_Handle *desc);
121
122 void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
123     const struct GNUNET_NETWORK_FDSet *src);
124
125 void GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to,
126     const struct GNUNET_NETWORK_FDSet *from);
127
128 void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, const fd_set *from,
129     int nfds);
130
131 void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
132     const struct GNUNET_DISK_FileHandle *h);
133
134 int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
135     const struct GNUNET_DISK_FileHandle *h);
136
137 int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2);
138
139 struct GNUNET_NETWORK_FDSet *GNUNET_NETWORK_fdset_create (void);
140
141 void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds);
142
143
144 #if 0                           /* keep Emacsens' auto-indent happy */
145 {
146 #endif
147 #ifdef __cplusplus
148 }
149 #endif
150
151 #endif /* GNUNET_NETWORK_LIB_H */