cctools
link.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
3 Copyright (C) 2005- The University of Notre Dame
4 This software is distributed under the GNU General Public License.
5 See the file COPYING for details.
6 */
7 
8 #ifndef LINK_H
9 #define LINK_H
10 
44 #include <sys/types.h>
45 
46 #include <limits.h>
47 #include <signal.h>
48 #include <stdarg.h>
49 #include <stdint.h>
50 #include <stdio.h>
51 #include <time.h>
52 
54 #define LINK_ADDRESS_MAX 48
55 
57 #define LINK_PORT_ANY 0
58 
60 #define LINK_FOREVER ((time_t)INT_MAX)
61 #define LINK_NOWAIT ((time_t)INT_MIN)
62 
69 struct link *link_connect(const char *addr, int port, time_t stoptime);
70 
75 struct link *link_attach_to_file(FILE *file);
76 
81 struct link *link_attach_to_fd(int fd);
82 
83 
90 struct link *link_serve(int port);
91 
98 struct link *link_serve_range(int low, int high);
99 
106 struct link *link_serve_address(const char *addr, int port);
107 
115 struct link *link_serve_addrrange(const char *addr, int low, int high);
116 
122 struct link *link_accept(struct link *parent, time_t stoptime);
123 
133 ssize_t link_read(struct link *link, char *data, size_t length, time_t stoptime);
134 
144 ssize_t link_read_avail(struct link *link, char *data, size_t length, time_t stoptime);
145 
153 ssize_t link_write(struct link *link, const char *data, size_t length, time_t stoptime);
154 
155 /* Write a string of length len to a connection. All data is written until
156  * finished or an error is encountered.
157 @param link The link to write.
158 @param str A pointer to the string.
159 @param len Length of the string.
160 @param stoptime The time at which to abort.
161 @return The number of bytes actually written, or less than zero on error.
162 */
163 ssize_t link_putlstring(struct link *link, const char *str, size_t len, time_t stoptime);
164 
165 /* Write a C string to a connection. All data is written until finished or an
166  error is encountered. It is defined as a macro.
167 @param link The link to write.
168 @param str A pointer to the string.
169 @param stoptime The time at which to abort.
170 @return The number of bytes actually written, or less than zero on error.
171 */
172 #define link_putstring(l,s,t) (link_putlstring(l,s,strlen(s),t))
173 
174 /* Write a C literal string to a connection. All data is written until finished
175  or an error is encountered. It is defined as a macro.
176 @param link The link to write.
177 @param str A pointer to the string.
178 @param stoptime The time at which to abort.
179 @return The number of bytes actually written, or less than zero on error.
180 */
181 #define link_putliteral(l,s,t) (link_putlstring(l,s "",((sizeof(s))-1),t))
182 
191 ssize_t link_putfstring(struct link *link, const char *fmt, time_t stoptime, ...)
192  __attribute__ (( format(printf,2,4) )) ;
193 
202 ssize_t link_putvfstring(struct link *link, const char *fmt, time_t stoptime, va_list va);
203 
211 int link_usleep(struct link *link, int usec, int reading, int writing);
212 
213 int link_usleep_mask(struct link *link, int usec, sigset_t *mask, int reading, int writing);
214 
222 int link_sleep(struct link *link, time_t stoptime, int reading, int writing);
223 
227 void link_close(struct link *link);
228 
229 
234 void link_detach(struct link *link);
235 
247 void link_window_set(int send_window, int recv_window);
248 
255 void link_window_get(struct link *link, int *send_window, int *recv_window);
256 
268 int link_readline(struct link *link, char *line, size_t length, time_t stoptime);
269 
274 int link_fd(struct link *link);
275 
276 int link_keepalive(struct link *link, int onoff);
277 
278 int link_nonblocking(struct link *link, int onoff);
279 
280 
285 int link_buffer_empty(struct link *link);
286 
293 int link_address_local(struct link *link, char *addr, int *port);
294 
301 int link_address_remote(struct link *link, char *addr, int *port);
302 
303 ssize_t link_stream_to_buffer(struct link *link, char **buffer, time_t stoptime);
304 
305 int64_t link_stream_to_fd(struct link *link, int fd, int64_t length, time_t stoptime);
306 int64_t link_stream_to_file(struct link *link, FILE * file, int64_t length, time_t stoptime);
307 
308 int64_t link_stream_from_fd(struct link *link, int fd, int64_t length, time_t stoptime);
309 int64_t link_stream_from_file(struct link *link, FILE * file, int64_t length, time_t stoptime);
310 
311 int64_t link_soak(struct link *link, int64_t length, time_t stoptime);
312 
314 typedef enum {
317 } link_tune_t;
318 
325 int link_tune(struct link *link, link_tune_t mode);
326 
328 #define LINK_READ 1
329 
331 #define LINK_WRITE 2
332 
334 struct link_info {
335  struct link *link;
336  int events;
337  int revents;
338 };
339 
348 int link_poll(struct link_info *array, int nlinks, int msec);
349 
350 int errno_is_temporary(int e);
351 
352 #endif
Definition: buffer.h:26