diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-10-17 20:47:30 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-10-17 20:47:30 +0000 |
commit | 32219472d9ad7f60a82b3c68cd61115bfc1e3ad7 (patch) | |
tree | c15ed769ac06cb44cf7520d8b83c80117dadfdce /src/include/gnunet_network_lib.h | |
parent | 3c913c6ad5bb2461a01b3745b0350df7d4ac9a78 (diff) | |
download | gnunet-32219472d9ad7f60a82b3c68cd61115bfc1e3ad7.tar.gz gnunet-32219472d9ad7f60a82b3c68cd61115bfc1e3ad7.zip |
making flags, set non-blocking and set-inheritable internal issues of network.c
Diffstat (limited to 'src/include/gnunet_network_lib.h')
-rw-r--r-- | src/include/gnunet_network_lib.h | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h index e4ba55854..513787e08 100644 --- a/src/include/gnunet_network_lib.h +++ b/src/include/gnunet_network_lib.h | |||
@@ -51,8 +51,11 @@ struct GNUNET_NETWORK_FDSet; | |||
51 | #include "gnunet_disk_lib.h" | 51 | #include "gnunet_disk_lib.h" |
52 | #include "gnunet_time_lib.h" | 52 | #include "gnunet_time_lib.h" |
53 | 53 | ||
54 | |||
54 | /** | 55 | /** |
55 | * accept a new connection on a socket | 56 | * Accept a new connection on a socket. Configure it for non-blocking |
57 | * IO and mark it as non-inheritable to child processes (set the | ||
58 | * close-on-exec flag). | ||
56 | * | 59 | * |
57 | * @param desc bound socket | 60 | * @param desc bound socket |
58 | * @param address address of the connecting peer, may be NULL | 61 | * @param address address of the connecting peer, may be NULL |
@@ -64,17 +67,6 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
64 | struct sockaddr *address, | 67 | struct sockaddr *address, |
65 | socklen_t *address_len); | 68 | socklen_t *address_len); |
66 | 69 | ||
67 | /** | ||
68 | * Make a non-inheritable to child processes (sets the | ||
69 | * close-on-exec flag). | ||
70 | * | ||
71 | * @param h the socket to make non-inheritable | ||
72 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
73 | * @warning Not implemented on Windows | ||
74 | */ | ||
75 | int | ||
76 | GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle | ||
77 | *h); | ||
78 | 70 | ||
79 | /** | 71 | /** |
80 | * Bind to a connected socket | 72 | * Bind to a connected socket |
@@ -88,7 +80,7 @@ int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
88 | const struct sockaddr *address, socklen_t address_len); | 80 | const struct sockaddr *address, socklen_t address_len); |
89 | 81 | ||
90 | /** | 82 | /** |
91 | * Close a socket | 83 | * Close a socket. |
92 | * | 84 | * |
93 | * @param desc socket to close | 85 | * @param desc socket to close |
94 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | 86 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise |
@@ -132,16 +124,15 @@ int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, i | |||
132 | int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, int backlog); | 124 | int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, int backlog); |
133 | 125 | ||
134 | /** | 126 | /** |
135 | * Read data from a connected socket | 127 | * Read data from a connected socket (always non-blocking). |
136 | * | 128 | * |
137 | * @param desc socket | 129 | * @param desc socket |
138 | * @param buffer buffer | 130 | * @param buffer buffer |
139 | * @param length length of buffer | 131 | * @param length length of buffer |
140 | * @param flags type of message reception | ||
141 | * @return number of bytes read | 132 | * @return number of bytes read |
142 | */ | 133 | */ |
143 | ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc, void *buffer, | 134 | ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc, void *buffer, |
144 | size_t length, int flags); | 135 | size_t length); |
145 | 136 | ||
146 | /** | 137 | /** |
147 | * Check if sockets meet certain conditions | 138 | * Check if sockets meet certain conditions |
@@ -155,38 +146,32 @@ int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
155 | struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds, | 146 | struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds, |
156 | struct GNUNET_TIME_Relative timeout); | 147 | struct GNUNET_TIME_Relative timeout); |
157 | 148 | ||
158 | /** | 149 | |
159 | * Set if a socket should use blocking or non-blocking IO. | ||
160 | * @param fd socket | ||
161 | * @param doBlock blocking mode | ||
162 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
163 | */ | ||
164 | int GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, | ||
165 | int doBlock); | ||
166 | 150 | ||
167 | /** | 151 | /** |
168 | * Send data | 152 | * Send data (always non-blocking). |
153 | * | ||
169 | * @param desc socket | 154 | * @param desc socket |
170 | * @param buffer data to send | 155 | * @param buffer data to send |
171 | * @param length size of the buffer | 156 | * @param length size of the buffer |
172 | * @param flags type of message transmission | ||
173 | * @return number of bytes sent, GNUNET_SYSERR on error | 157 | * @return number of bytes sent, GNUNET_SYSERR on error |
174 | */ | 158 | */ |
175 | ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc, | 159 | ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc, |
176 | const void *buffer, size_t length, int flags); | 160 | const void *buffer, size_t length); |
177 | 161 | ||
178 | /** | 162 | /** |
179 | * Send data | 163 | * Send data to a particular destination (always non-blocking). |
164 | * This function only works for UDP sockets. | ||
165 | * | ||
180 | * @param desc socket | 166 | * @param desc socket |
181 | * @param message data to send | 167 | * @param message data to send |
182 | * @param length size of the data | 168 | * @param length size of the data |
183 | * @param flags type of message transmission | ||
184 | * @param dest_addr destination address | 169 | * @param dest_addr destination address |
185 | * @param dest_len length of address | 170 | * @param dest_len length of address |
186 | * @return number of bytes sent, GNUNET_SYSERR on error | 171 | * @return number of bytes sent, GNUNET_SYSERR on error |
187 | */ | 172 | */ |
188 | ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle *desc, | 173 | ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle *desc, |
189 | const void *message, size_t length, int flags, | 174 | const void *message, size_t length, |
190 | const struct sockaddr *dest_addr, | 175 | const struct sockaddr *dest_addr, |
191 | socklen_t dest_len); | 176 | socklen_t dest_len); |
192 | 177 | ||
@@ -210,14 +195,18 @@ int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level | |||
210 | */ | 195 | */ |
211 | int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how); | 196 | int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how); |
212 | 197 | ||
198 | |||
213 | /** | 199 | /** |
214 | * Create a new socket | 200 | * Create a new socket. Configure it for non-blocking IO and |
201 | * mark it as non-inheritable to child processes (set the | ||
202 | * close-on-exec flag). | ||
203 | * | ||
215 | * @param domain domain of the socket | 204 | * @param domain domain of the socket |
216 | * @param type socket type | 205 | * @param type socket type |
217 | * @param protocol network protocol | 206 | * @param protocol network protocol |
218 | * @return new socket, NULL on error | 207 | * @return new socket, NULL on error |
219 | */ | 208 | */ |
220 | struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_socket (int domain, int type, int protocol); | 209 | struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_create (int domain, int type, int protocol); |
221 | 210 | ||
222 | /** | 211 | /** |
223 | * Reset FD set (clears all file descriptors). | 212 | * Reset FD set (clears all file descriptors). |