cctools
link.h
Go to the documentation of this file.
1/*
2Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
3Copyright (C) 2022 The University of Notre Dame
4This software is distributed under the GNU General Public License.
5See 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
69struct link *link_connect(const char *addr, int port, time_t stoptime);
70
76int link_ssl_wrap_connect(struct link *link, const char *sni_hostname);
77
82struct link *link_attach_to_file(FILE *file);
83
88struct link *link_attach_to_fd(int fd);
89
90
97struct link *link_serve(int port);
98
105struct link *link_serve_range(int low, int high);
106
113struct link *link_serve_address(const char *addr, int port);
114
115
122struct link *link_serve_address_range(const char *addr, int low, int high);
123
131struct link *link_serve_addrrange(const char *addr, int low, int high);
132
138struct link *link_accept(struct link *parent, time_t stoptime);
139
140
148int link_ssl_wrap_accept(struct link *lnk, const char *key, const char *cert);
149
150
160ssize_t link_read(struct link *link, char *data, size_t length, time_t stoptime);
161
171ssize_t link_read_avail(struct link *link, char *data, size_t length, time_t stoptime);
172
180ssize_t link_write(struct link *link, const char *data, size_t length, time_t stoptime);
181
182/* Write a string of length len to a connection. All data is written until
183 * finished or an error is encountered.
184@param link The link to write.
185@param str A pointer to the string.
186@param len Length of the string.
187@param stoptime The time at which to abort.
188@return The number of bytes actually written, or less than zero on error.
189*/
190ssize_t link_putlstring(struct link *link, const char *str, size_t len, time_t stoptime);
191
192/* Write a C string to a connection. All data is written until finished or an
193 error is encountered. It is defined as a macro.
194@param link The link to write.
195@param str A pointer to the string.
196@param stoptime The time at which to abort.
197@return The number of bytes actually written, or less than zero on error.
198*/
199#define link_putstring(l,s,t) (link_putlstring(l,s,strlen(s),t))
200
201/* Write a C literal string to a connection. All data is written until finished
202 or an error is encountered. It is defined as a macro.
203@param link The link to write.
204@param str A pointer to the string.
205@param stoptime The time at which to abort.
206@return The number of bytes actually written, or less than zero on error.
207*/
208#define link_putliteral(l,s,t) (link_putlstring(l,s "",((sizeof(s))-1),t))
209
218ssize_t link_printf(struct link *link, time_t stoptime, const char *fmt, ...)
219 __attribute__ (( format(printf,3,4) )) ;
220
229ssize_t link_vprintf(struct link *link, time_t stoptime, const char *fmt, va_list va);
230
238int link_usleep(struct link *link, int usec, int reading, int writing);
239
240int link_usleep_mask(struct link *link, int usec, sigset_t *mask, int reading, int writing);
241
249int link_sleep(struct link *link, time_t stoptime, int reading, int writing);
250
254void link_close(struct link *link);
255
256
261void link_detach(struct link *link);
262
274void link_window_set(int send_window, int recv_window);
275
282void link_window_get(struct link *link, int *send_window, int *recv_window);
283
295int link_readline(struct link *link, char *line, size_t length, time_t stoptime);
296
301int link_fd(struct link *link);
302
307int link_buffer_output(struct link *link, size_t size );
308
312int link_flush_output(struct link *link );
313
318int link_using_ssl(struct link *link);
319
320int link_keepalive(struct link *link, int onoff);
321
322int link_nonblocking(struct link *link, int onoff);
323
324
329int link_buffer_empty(struct link *link);
330
337int link_address_local(struct link *link, char *addr, int *port);
338
345int link_address_remote(struct link *link, char *addr, int *port);
346
347ssize_t link_stream_to_buffer(struct link *link, char **buffer, time_t stoptime);
348
349int64_t link_stream_to_fd(struct link *link, int fd, int64_t length, time_t stoptime);
350int64_t link_stream_to_file(struct link *link, FILE * file, int64_t length, time_t stoptime);
351
352int64_t link_stream_from_fd(struct link *link, int fd, int64_t length, time_t stoptime);
353int64_t link_stream_from_file(struct link *link, FILE * file, int64_t length, time_t stoptime);
354
355int64_t link_soak(struct link *link, int64_t length, time_t stoptime);
356
362
369int link_tune(struct link *link, link_tune_t mode);
370
372#define LINK_READ 1
373
375#define LINK_WRITE 2
376
378struct link_info {
379 struct link *link;
380 int events;
382};
383
392int link_poll(struct link_info *array, int nlinks, int msec);
393
398int link_get_buffer_bytes(struct link *link);
399
400
401int errno_is_temporary(int e);
402
403#endif
Definition buffer.h:26