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 "int_sizes.h"
45 
46 #include <time.h>
47 #include <limits.h>
48 #include <stdio.h>
49 #include <stdarg.h>
50 #include <sys/types.h>
51 
53 #define LINK_ADDRESS_MAX 48
54 
56 #define LINK_PORT_ANY 0
57 
59 #define LINK_FOREVER ((time_t)INT_MAX)
60 
67 struct link *link_connect(const char *addr, int port, time_t stoptime);
68 
75 struct link *link_serve(int port);
76 
83 struct link *link_serve_range(int low, int high);
84 
91 struct link *link_serve_address(const char *addr, int port);
92 
100 struct link *link_serve_addrrange(const char *addr, int low, int high);
101 
107 struct link *link_accept(struct link *master, time_t stoptime);
108 
118 int link_read(struct link *link, char *data, size_t length, time_t stoptime);
119 
129 int link_read_avail(struct link *link, char *data, size_t length, time_t stoptime);
130 
138 int link_write(struct link *link, const char *data, size_t length, time_t stoptime);
139 
140 /* Write a string of length len to a connection. All data is written until
141  * finished or an error is encountered.
142 @param link The link to write.
143 @param str A pointer to the string.
144 @param len Length of the string.
145 @param stoptime The time at which to abort.
146 @return The number of bytes actually written, or less than zero on error.
147 */
148 int link_putlstring(struct link *link, const char *str, size_t len, time_t stoptime);
149 
150 /* Write a C string to a connection. All data is written until finished or an
151  error is encountered. It is defined as a macro.
152 @param link The link to write.
153 @param str A pointer to the string.
154 @param stoptime The time at which to abort.
155 @return The number of bytes actually written, or less than zero on error.
156 */
157 #define link_putstring(l,s,t) (link_putlstring(l,s,strlen(s),t))
158 
159 /* Write a C literal string to a connection. All data is written until finished
160  or an error is encountered. It is defined as a macro.
161 @param link The link to write.
162 @param str A pointer to the string.
163 @param stoptime The time at which to abort.
164 @return The number of bytes actually written, or less than zero on error.
165 */
166 #define link_putliteral(l,s,t) (link_putlstring(l,s "",((sizeof(s))-1),t))
167 
176 int link_putfstring(struct link *link, const char *fmt, time_t stoptime, ...);
177 
186 int link_putvfstring(struct link *link, const char *fmt, time_t stoptime, va_list va);
187 
195 int link_usleep(struct link *link, int usec, int reading, int writing);
196 
204 int link_sleep(struct link *link, time_t stoptime, int reading, int writing);
205 
209 void link_close(struct link *link);
210 
222 void link_window_set(int send_window, int recv_window);
223 
230 void link_window_get(struct link *link, int *send_window, int *recv_window);
231 
243 int link_readline(struct link *link, char *line, size_t length, time_t stoptime);
244 
249 int link_fd(struct link *link);
250 
251 int link_keepalive(struct link *link, int onoff);
252 
253 int link_nonblocking(struct link *link, int onoff);
254 
255 
260 int link_buffer_empty(struct link *link);
261 
268 int link_address_local(struct link *link, char *addr, int *port);
269 
276 int link_address_remote(struct link *link, char *addr, int *port);
277 
278 INT64_T link_stream_to_buffer(struct link *link, char **buffer, time_t stoptime);
279 
280 INT64_T link_stream_to_fd(struct link *link, int fd, INT64_T length, time_t stoptime);
281 INT64_T link_stream_to_file(struct link *link, FILE * file, INT64_T length, time_t stoptime);
282 
283 INT64_T link_stream_from_fd(struct link *link, int fd, INT64_T length, time_t stoptime);
284 INT64_T link_stream_from_file(struct link *link, FILE * file, INT64_T length, time_t stoptime);
285 
286 INT64_T link_soak(struct link *link, INT64_T length, time_t stoptime);
287 
289 typedef enum {
292 } link_tune_t;
293 
300 int link_tune(struct link *link, link_tune_t mode);
301 
303 #define LINK_READ 1
304 
306 #define LINK_WRITE 2
307 
309 struct link_info {
310  struct link *link;
311  int events;
312  int revents;
313 };
314 
323 int link_poll(struct link_info *array, int nlinks, int msec);
324 
325 #endif