link.h
Go to the documentation of this file.
/*
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
Copyright (C) 2022 The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/
#ifndef LINK_H
#define LINK_H
#include <sys/types.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#define LINK_ADDRESS_MAX 48
#define LINK_PORT_ANY 0
#define LINK_FOREVER ((time_t)INT_MAX)
#define LINK_NOWAIT ((time_t)INT_MIN)
struct link *link_connect(const char *addr, int port, time_t stoptime);
int link_ssl_wrap_connect(struct link *link, const char *sni_hostname);
struct link *link_attach_to_file(FILE *file);
struct link *link_attach_to_fd(int fd);
struct link *link_serve(int port);
struct link *link_serve_range(int low, int high);
struct link *link_serve_address(const char *addr, int port);
struct link *link_serve_address_range(const char *addr, int low, int high);
struct link *link_serve_addrrange(const char *addr, int low, int high);
struct link *link_accept(struct link *parent, time_t stoptime);
int link_ssl_wrap_accept(struct link *lnk, const char *key, const char *cert);
ssize_t link_read(struct link *link, char *data, size_t length, time_t stoptime);
ssize_t link_read_avail(struct link *link, char *data, size_t length, time_t stoptime);
ssize_t link_write(struct link *link, const char *data, size_t length, time_t stoptime);
/* Write a string of length len to a connection. All data is written until
* finished or an error is encountered.
@param link The link to write.
@param str A pointer to the string.
@param len Length of the string.
@param stoptime The time at which to abort.
@return The number of bytes actually written, or less than zero on error.
*/
ssize_t link_putlstring(struct link *link, const char *str, size_t len, time_t stoptime);
/* Write a C string to a connection. All data is written until finished or an
error is encountered. It is defined as a macro.
@param link The link to write.
@param str A pointer to the string.
@param stoptime The time at which to abort.
@return The number of bytes actually written, or less than zero on error.
*/
#define link_putstring(l,s,t) (link_putlstring(l,s,strlen(s),t))
/* Write a C literal string to a connection. All data is written until finished
or an error is encountered. It is defined as a macro.
@param link The link to write.
@param str A pointer to the string.
@param stoptime The time at which to abort.
@return The number of bytes actually written, or less than zero on error.
*/
#define link_putliteral(l,s,t) (link_putlstring(l,s "",((sizeof(s))-1),t))
ssize_t link_printf(struct link *link, time_t stoptime, const char *fmt, ...)
__attribute__ (( format(printf,3,4) )) ;
ssize_t link_vprintf(struct link *link, time_t stoptime, const char *fmt, va_list va);
int link_usleep(struct link *link, int usec, int reading, int writing);
int link_usleep_mask(struct link *link, int usec, sigset_t *mask, int reading, int writing);
int link_sleep(struct link *link, time_t stoptime, int reading, int writing);
void link_close(struct link *link);
void link_detach(struct link *link);
void link_window_set(int send_window, int recv_window);
void link_window_get(struct link *link, int *send_window, int *recv_window);
int link_readline(struct link *link, char *line, size_t length, time_t stoptime);
int link_fd(struct link *link);
int link_buffer_output(struct link *link, size_t size );
int link_flush_output(struct link *link );
int link_using_ssl(struct link *link);
int link_keepalive(struct link *link, int onoff);
int link_nonblocking(struct link *link, int onoff);
int link_buffer_empty(struct link *link);
int link_address_local(struct link *link, char *addr, int *port);
int link_address_remote(struct link *link, char *addr, int *port);
ssize_t link_stream_to_buffer(struct link *link, char **buffer, time_t stoptime);
int64_t link_stream_to_fd(struct link *link, int fd, int64_t length, time_t stoptime);
int64_t link_stream_to_file(struct link *link, FILE * file, int64_t length, time_t stoptime);
int64_t link_stream_from_fd(struct link *link, int fd, int64_t length, time_t stoptime);
int64_t link_stream_from_file(struct link *link, FILE * file, int64_t length, time_t stoptime);
int64_t link_soak(struct link *link, int64_t length, time_t stoptime);
typedef enum {
LINK_TUNE_INTERACTIVE,
LINK_TUNE_BULK
} link_tune_t;
int link_tune(struct link *link, link_tune_t mode);
#define LINK_READ 1
#define LINK_WRITE 2
struct link_info {
struct link *link;
int events;
int revents;
};
int link_poll(struct link_info *array, int nlinks, int msec);
int link_get_buffer_bytes(struct link *link);
int errno_is_temporary(int e);
#endif
link_tune_t
link_tune_t
Options for link performance tuning.
Definition link.h:358
LINK_TUNE_BULK
@ LINK_TUNE_BULK
Data may be buffered to improve throughput of large transfers.
Definition link.h:360
LINK_TUNE_INTERACTIVE
@ LINK_TUNE_INTERACTIVE
Data is sent immediately to optimze interactive latency.
Definition link.h:359
link_serve
struct link * link_serve(int port)
Prepare to accept connections.
link_poll
int link_poll(struct link_info *array, int nlinks, int msec)
Wait for a activity on a an array of links.
link_readline
int link_readline(struct link *link, char *line, size_t length, time_t stoptime)
Read a line of text from a link.
link_ssl_wrap_accept
int link_ssl_wrap_accept(struct link *lnk, const char *key, const char *cert)
Wrap an accepted link with an ssl context.
link_vprintf
ssize_t ssize_t link_vprintf(struct link *link, time_t stoptime, const char *fmt, va_list va)
Write formatted data to a connection.
link_get_buffer_bytes
int link_get_buffer_bytes(struct link *link)
Get the number of bytes in the output buffer of a link.
link_tune
int link_tune(struct link *link, link_tune_t mode)
Tune a link for interactive or bulk performance.
link_connect
struct link * link_connect(const char *addr, int port, time_t stoptime)
Connect to a remote host.
link_serve_address_range
struct link * link_serve_address_range(const char *addr, int low, int high)
Prepare to accept connections on one network interface.
link_buffer_empty
int link_buffer_empty(struct link *link)
Check whether a link has unread contents in its buffer.
link_using_ssl
int link_using_ssl(struct link *link)
Whether the link is using ssl.
link_window_get
void link_window_get(struct link *link, int *send_window, int *recv_window)
Get the TCP window size actually allocated for this link.
link_window_set
void link_window_set(int send_window, int recv_window)
Set the TCP window size to be used for all links.
link_sleep
int link_sleep(struct link *link, time_t stoptime, int reading, int writing)
Block until a link is readable or writable.
link_flush_output
int link_flush_output(struct link *link)
Flush buffered output from link_printf.
link_close
void link_close(struct link *link)
Close a connection.
link_read
ssize_t link_read(struct link *link, char *data, size_t length, time_t stoptime)
Read data from a connection.
link_usleep
int link_usleep(struct link *link, int usec, int reading, int writing)
Block until a link is readable or writable.
link_ssl_wrap_connect
int link_ssl_wrap_connect(struct link *link, const char *sni_hostname)
Wrap a connect link with an ssl context and state.
link_attach_to_fd
struct link * link_attach_to_fd(int fd)
Turn an fd into a link.
link_fd
int link_fd(struct link *link)
Get the underlying file descriptor of a link.
link_detach
void link_detach(struct link *link)
Detach a link from the underlying file descriptor.
link_attach_to_file
struct link * link_attach_to_file(FILE *file)
Turn a FILE* into a link.
link_address_remote
int link_address_remote(struct link *link, char *addr, int *port)
Return the remote address of the link in text format.
link_serve_range
struct link * link_serve_range(int low, int high)
Prepare to accept connections.
link_printf
ssize_t link_printf(struct link *link, time_t stoptime, const char *fmt,...) __attribute__((format(printf
Write formatted data to a connection.
link_serve_addrrange
struct link * link_serve_addrrange(const char *addr, int low, int high)
Prepare to accept connections on one network interface.
link_address_local
int link_address_local(struct link *link, char *addr, int *port)
Return the local address of the link in text format.
link_serve_address
struct link * link_serve_address(const char *addr, int port)
Prepare to accept connections on one network interface.
link_read_avail
ssize_t link_read_avail(struct link *link, char *data, size_t length, time_t stoptime)
Read available data from a connection.
link_buffer_output
int link_buffer_output(struct link *link, size_t size)
Enable output buffering for link_printf.
link_accept
struct link * link_accept(struct link *parent, time_t stoptime)
Accept one connection.
link_write
ssize_t link_write(struct link *link, const char *data, size_t length, time_t stoptime)
Write data to a connection.
buffer
Definition buffer.h:26
link_info
Activity structure passed to link_poll.
Definition link.h:378
link_info::revents
int revents
The events returned (LINK_READ or LINK_WRITE).
Definition link.h:381
link_info::events
int events
The events to wait for (LINK_READ or LINK_WRITE).
Definition link.h:380
link_info::link
struct link * link
The link to be polled.
Definition link.h:379