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
123struct link *link_serve_address_range(const char *addr, int low, int high);
124
132struct link *link_serve_addrrange(const char *addr, int low, int high);
133
139struct link *link_accept(struct link *parent, time_t stoptime);
140
141
149int link_ssl_wrap_accept(struct link *lnk, const char *key, const char *cert);
150
151
161ssize_t link_read(struct link *link, char *data, size_t length, time_t stoptime);
162
172ssize_t link_read_avail(struct link *link, char *data, size_t length, time_t stoptime);
173
181ssize_t link_write(struct link *link, const char *data, size_t length, time_t stoptime);
182
183/* Write a string of length len to a connection. All data is written until
184 * finished or an error is encountered.
185@param link The link to write.
186@param str A pointer to the string.
187@param len Length of the string.
188@param stoptime The time at which to abort.
189@return The number of bytes actually written, or less than zero on error.
190*/
191ssize_t link_putlstring(struct link *link, const char *str, size_t len, time_t stoptime);
192
193/* Write a C string to a connection. All data is written until finished or an
194 error is encountered. It is defined as a macro.
195@param link The link to write.
196@param str A pointer to the string.
197@param stoptime The time at which to abort.
198@return The number of bytes actually written, or less than zero on error.
199*/
200#define link_putstring(l,s,t) (link_putlstring(l,s,strlen(s),t))
201
202/* Write a C literal string to a connection. All data is written until finished
203 or an error is encountered. It is defined as a macro.
204@param link The link to write.
205@param str A pointer to the string.
206@param stoptime The time at which to abort.
207@return The number of bytes actually written, or less than zero on error.
208*/
209#define link_putliteral(l,s,t) (link_putlstring(l,s "",((sizeof(s))-1),t))
210
219ssize_t link_printf(struct link *link, time_t stoptime, const char *fmt, ...)
220 __attribute__ (( format(printf,3,4) )) ;
221
230ssize_t link_vprintf(struct link *link, time_t stoptime, const char *fmt, va_list va);
231
239int link_usleep(struct link *link, int usec, int reading, int writing);
240
241int link_usleep_mask(struct link *link, int usec, sigset_t *mask, int reading, int writing);
242
250int link_sleep(struct link *link, time_t stoptime, int reading, int writing);
251
255void link_close(struct link *link);
256
257
262void link_detach(struct link *link);
263
275void link_window_set(int send_window, int recv_window);
276
283void link_window_get(struct link *link, int *send_window, int *recv_window);
284
296int link_readline(struct link *link, char *line, size_t length, time_t stoptime);
297
302int link_fd(struct link *link);
303
308int link_buffer_output(struct link *link, size_t size );
309
313int link_flush_output(struct link *link );
314
319int link_using_ssl(struct link *link);
320
321int link_keepalive(struct link *link, int onoff);
322
323int link_nonblocking(struct link *link, int onoff);
324
325
330int link_buffer_empty(struct link *link);
331
338int link_address_local(struct link *link, char *addr, int *port);
339
346int link_address_remote(struct link *link, char *addr, int *port);
347
348ssize_t link_stream_to_buffer(struct link *link, char **buffer, time_t stoptime);
349
350int64_t link_stream_to_fd(struct link *link, int fd, int64_t length, time_t stoptime);
351int64_t link_stream_to_file(struct link *link, FILE * file, int64_t length, time_t stoptime);
352
353int64_t link_stream_from_fd(struct link *link, int fd, int64_t length, time_t stoptime);
354int64_t link_stream_from_file(struct link *link, FILE * file, int64_t length, time_t stoptime);
355
356int64_t link_soak(struct link *link, int64_t length, time_t stoptime);
357
363
370int link_tune(struct link *link, link_tune_t mode);
371
373#define LINK_READ 1
374
376#define LINK_WRITE 2
377
379struct link_info {
380 struct link *link;
381 int events;
383};
384
393int link_poll(struct link_info *array, int nlinks, int msec);
394
399int link_get_buffer_bytes(struct link *link);
400
401
402int errno_is_temporary(int e);
403
404#endif
Definition buffer.h:26