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) 2022 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 int link_ssl_wrap_connect(struct link *link);
76 
81 struct link *link_attach_to_file(FILE *file);
82 
87 struct link *link_attach_to_fd(int fd);
88 
89 
96 struct link *link_serve(int port);
97 
104 struct link *link_serve_range(int low, int high);
105 
112 struct link *link_serve_address(const char *addr, int port);
113 
121 struct link *link_serve_addrrange(const char *addr, int low, int high);
122 
128 struct link *link_accept(struct link *parent, time_t stoptime);
129 
130 
138 int link_ssl_wrap_accept(struct link *lnk, const char *key, const char *cert);
139 
140 
150 ssize_t link_read(struct link *link, char *data, size_t length, time_t stoptime);
151 
161 ssize_t link_read_avail(struct link *link, char *data, size_t length, time_t stoptime);
162 
170 ssize_t link_write(struct link *link, const char *data, size_t length, time_t stoptime);
171 
172 /* Write a string of length len to a connection. All data is written until
173  * finished or an error is encountered.
174 @param link The link to write.
175 @param str A pointer to the string.
176 @param len Length of 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 ssize_t link_putlstring(struct link *link, const char *str, size_t len, time_t stoptime);
181 
182 /* Write a C string to a connection. All data is written until finished or an
183  error is encountered. It is defined as a macro.
184 @param link The link to write.
185 @param str A pointer to the string.
186 @param stoptime The time at which to abort.
187 @return The number of bytes actually written, or less than zero on error.
188 */
189 #define link_putstring(l,s,t) (link_putlstring(l,s,strlen(s),t))
190 
191 /* Write a C literal string to a connection. All data is written until finished
192  or an error is encountered. It is defined as a macro.
193 @param link The link to write.
194 @param str A pointer to the string.
195 @param stoptime The time at which to abort.
196 @return The number of bytes actually written, or less than zero on error.
197 */
198 #define link_putliteral(l,s,t) (link_putlstring(l,s "",((sizeof(s))-1),t))
199 
208 ssize_t link_printf(struct link *link, time_t stoptime, const char *fmt, ...)
209  __attribute__ (( format(printf,3,4) )) ;
210 
219 ssize_t link_vprintf(struct link *link, time_t stoptime, const char *fmt, va_list va);
220 
228 int link_usleep(struct link *link, int usec, int reading, int writing);
229 
230 int link_usleep_mask(struct link *link, int usec, sigset_t *mask, int reading, int writing);
231 
239 int link_sleep(struct link *link, time_t stoptime, int reading, int writing);
240 
244 void link_close(struct link *link);
245 
246 
251 void link_detach(struct link *link);
252 
264 void link_window_set(int send_window, int recv_window);
265 
272 void link_window_get(struct link *link, int *send_window, int *recv_window);
273 
285 int link_readline(struct link *link, char *line, size_t length, time_t stoptime);
286 
291 int link_fd(struct link *link);
292 
297 int link_buffer_output(struct link *link, size_t size );
298 
302 int link_flush_output(struct link *link );
303 
308 int link_using_ssl(struct link *link);
309 
310 int link_keepalive(struct link *link, int onoff);
311 
312 int link_nonblocking(struct link *link, int onoff);
313 
314 
319 int link_buffer_empty(struct link *link);
320 
327 int link_address_local(struct link *link, char *addr, int *port);
328 
335 int link_address_remote(struct link *link, char *addr, int *port);
336 
337 ssize_t link_stream_to_buffer(struct link *link, char **buffer, time_t stoptime);
338 
339 int64_t link_stream_to_fd(struct link *link, int fd, int64_t length, time_t stoptime);
340 int64_t link_stream_to_file(struct link *link, FILE * file, int64_t length, time_t stoptime);
341 
342 int64_t link_stream_from_fd(struct link *link, int fd, int64_t length, time_t stoptime);
343 int64_t link_stream_from_file(struct link *link, FILE * file, int64_t length, time_t stoptime);
344 
345 int64_t link_soak(struct link *link, int64_t length, time_t stoptime);
346 
348 typedef enum {
351 } link_tune_t;
352 
359 int link_tune(struct link *link, link_tune_t mode);
360 
362 #define LINK_READ 1
363 
365 #define LINK_WRITE 2
366 
368 struct link_info {
369  struct link *link;
370  int events;
371  int revents;
372 };
373 
382 int link_poll(struct link_info *array, int nlinks, int msec);
383 
384 int errno_is_temporary(int e);
385 
386 #endif
buffer
Definition: buffer.h:26