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 
84 struct link *link_serve_address(const char *addr, int port);
85 
91 struct link *link_accept(struct link *master, time_t stoptime);
92 
102 int link_read(struct link *link, char *data, size_t length, time_t stoptime);
103 
113 int link_read_avail(struct link *link, char *data, size_t length, time_t stoptime);
114 
122 int link_write(struct link *link, const char *data, size_t length, time_t stoptime);
123 
124 /* Write a string of length len to a connection. All data is written until
125  * finished or an error is encountered.
126 @param link The link to write.
127 @param str A pointer to the string.
128 @param len Length of the string.
129 @param stoptime The time at which to abort.
130 @return The number of bytes actually written, or less than zero on error.
131 */
132 int link_putlstring(struct link *link, const char *str, size_t len, time_t stoptime);
133 
134 /* Write a C string to a connection. All data is written until finished or an
135  error is encountered. It is defined as a macro.
136 @param link The link to write.
137 @param str A pointer to the string.
138 @param stoptime The time at which to abort.
139 @return The number of bytes actually written, or less than zero on error.
140 */
141 #define link_putstring(l,s,t) (link_putlstring(l,s,strlen(s),t))
142 
143 /* Write a C literal string to a connection. All data is written until finished
144  or an error is encountered. It is defined as a macro.
145 @param link The link to write.
146 @param str A pointer to the string.
147 @param stoptime The time at which to abort.
148 @return The number of bytes actually written, or less than zero on error.
149 */
150 #define link_putliteral(l,s,t) (link_putlstring(l,s "",((sizeof(s))-1),t))
151 
160 int link_putfstring(struct link *link, const char *fmt, time_t stoptime, ...);
161 
170 int link_putvfstring(struct link *link, const char *fmt, time_t stoptime, va_list va);
171 
179 int link_usleep(struct link *link, int usec, int reading, int writing);
180 
184 void link_close(struct link *link);
185 
197 void link_window_set(int send_window, int recv_window);
198 
205 void link_window_get(struct link *link, int *send_window, int *recv_window);
206 
218 int link_readline(struct link *link, char *line, size_t length, time_t stoptime);
219 
224 int link_fd(struct link *link);
225 
226 int link_keepalive(struct link *link, int onoff);
227 
228 int link_nonblocking(struct link *link, int onoff);
229 
236 int link_address_local(struct link *link, char *addr, int *port);
237 
244 int link_address_remote(struct link *link, char *addr, int *port);
245 
246 INT64_T link_stream_to_buffer(struct link *link, char **buffer, time_t stoptime);
247 
248 INT64_T link_stream_to_fd(struct link *link, int fd, INT64_T length, time_t stoptime);
249 INT64_T link_stream_to_file(struct link *link, FILE * file, INT64_T length, time_t stoptime);
250 
251 INT64_T link_stream_from_fd(struct link *link, int fd, INT64_T length, time_t stoptime);
252 INT64_T link_stream_from_file(struct link *link, FILE * file, INT64_T length, time_t stoptime);
253 
254 INT64_T link_soak(struct link *link, INT64_T length, time_t stoptime);
255 
257 typedef enum {
260 } link_tune_t;
261 
268 int link_tune(struct link *link, link_tune_t mode);
269 
271 #define LINK_READ 1
272 
274 #define LINK_WRITE 2
275 
277 struct link_info {
278  struct link *link;
279  int events;
280  int revents;
281 };
282 
291 int link_poll(struct link_info *array, int nlinks, int msec);
292 
293 #endif