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 
68 struct link *link_connect(const char *addr, int port, time_t stoptime);
69 
74 struct link *link_attach_to_file(FILE *file);
75 
80 struct link *link_attach_to_fd(int fd);
81 
82 
89 struct link *link_serve(int port);
90 
97 struct link *link_serve_range(int low, int high);
98 
105 struct link *link_serve_address(const char *addr, int port);
106 
114 struct link *link_serve_addrrange(const char *addr, int low, int high);
115 
121 struct link *link_accept(struct link *master, time_t stoptime);
122 
132 ssize_t link_read(struct link *link, char *data, size_t length, time_t stoptime);
133 
143 ssize_t link_read_avail(struct link *link, char *data, size_t length, time_t stoptime);
144 
152 ssize_t link_write(struct link *link, const char *data, size_t length, time_t stoptime);
153 
154 /* Write a string of length len to a connection. All data is written until
155  * finished or an error is encountered.
156 @param link The link to write.
157 @param str A pointer to the string.
158 @param len Length of the string.
159 @param stoptime The time at which to abort.
160 @return The number of bytes actually written, or less than zero on error.
161 */
162 ssize_t link_putlstring(struct link *link, const char *str, size_t len, time_t stoptime);
163 
164 /* Write a C string to a connection. All data is written until finished or an
165  error is encountered. It is defined as a macro.
166 @param link The link to write.
167 @param str A pointer to the string.
168 @param stoptime The time at which to abort.
169 @return The number of bytes actually written, or less than zero on error.
170 */
171 #define link_putstring(l,s,t) (link_putlstring(l,s,strlen(s),t))
172 
173 /* Write a C literal string to a connection. All data is written until finished
174  or an error is encountered. It is defined as a macro.
175 @param link The link to write.
176 @param str A pointer to the string.
177 @param stoptime The time at which to abort.
178 @return The number of bytes actually written, or less than zero on error.
179 */
180 #define link_putliteral(l,s,t) (link_putlstring(l,s "",((sizeof(s))-1),t))
181 
190 ssize_t link_putfstring(struct link *link, const char *fmt, time_t stoptime, ...)
191  __attribute__ (( format(printf,2,4) )) ;
192 
201 ssize_t link_putvfstring(struct link *link, const char *fmt, time_t stoptime, va_list va);
202 
210 int link_usleep(struct link *link, int usec, int reading, int writing);
211 
212 int link_usleep_mask(struct link *link, int usec, sigset_t *mask, int reading, int writing);
213 
221 int link_sleep(struct link *link, time_t stoptime, int reading, int writing);
222 
226 void link_close(struct link *link);
227 
228 
233 void link_detach(struct link *link);
234 
246 void link_window_set(int send_window, int recv_window);
247 
254 void link_window_get(struct link *link, int *send_window, int *recv_window);
255 
267 int link_readline(struct link *link, char *line, size_t length, time_t stoptime);
268 
273 int link_fd(struct link *link);
274 
275 int link_keepalive(struct link *link, int onoff);
276 
277 int link_nonblocking(struct link *link, int onoff);
278 
279 
284 int link_buffer_empty(struct link *link);
285 
292 int link_address_local(struct link *link, char *addr, int *port);
293 
300 int link_address_remote(struct link *link, char *addr, int *port);
301 
302 ssize_t link_stream_to_buffer(struct link *link, char **buffer, time_t stoptime);
303 
304 int64_t link_stream_to_fd(struct link *link, int fd, int64_t length, time_t stoptime);
305 int64_t link_stream_to_file(struct link *link, FILE * file, int64_t length, time_t stoptime);
306 
307 int64_t link_stream_from_fd(struct link *link, int fd, int64_t length, time_t stoptime);
308 int64_t link_stream_from_file(struct link *link, FILE * file, int64_t length, time_t stoptime);
309 
310 int64_t link_soak(struct link *link, int64_t length, time_t stoptime);
311 
313 typedef enum {
316 } link_tune_t;
317 
324 int link_tune(struct link *link, link_tune_t mode);
325 
327 #define LINK_READ 1
328 
330 #define LINK_WRITE 2
331 
333 struct link_info {
334  struct link *link;
335  int events;
336  int revents;
337 };
338 
347 int link_poll(struct link_info *array, int nlinks, int msec);
348 
349 #endif
Definition: buffer.h:26