1 /* $OpenBSD: ioev.h,v 1.17 2019/06/12 17:42:53 eric Exp $ */
3 * Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 IO_CONNECTED = 0, /* connection successful */
20 IO_TLSREADY, /* TLS started successfully */
21 IO_TLSERROR, /* XXX - needs more work */
22 IO_DATAIN, /* new data in input buffer */
23 IO_LOWAT, /* output queue running low */
24 IO_DISCONNECTED, /* error? */
25 IO_TIMEOUT, /* error? */
26 IO_ERROR, /* details? */
32 /* From OpenNTPD-ish portable */
34 #define SA_LEN(x) ((x)->sa_family == AF_INET6 ? \
35 sizeof(struct sockaddr_in6) : \
36 sizeof(struct sockaddr_in))
39 #define __unused __attribute__((unused))
44 void io_set_nonblocking(int);
45 void io_set_nolinger(int);
47 struct io *io_new(void);
48 void io_free(struct io *);
49 void io_set_read(struct io *);
50 void io_set_write(struct io *);
51 void io_set_fd(struct io *, int);
52 void io_set_callback(struct io *io, void(*)(struct io *, int, void *), void *);
53 void io_set_timeout(struct io *, int);
54 void io_set_lowat(struct io *, size_t);
55 void io_pause(struct io *, int);
56 void io_resume(struct io *, int);
57 void io_reload(struct io *);
58 int io_connect(struct io *, const struct sockaddr *, const struct sockaddr *);
59 int io_start_tls(struct io *, void *);
60 const char* io_strio(struct io *);
61 const char* io_strevent(int);
62 const char* io_error(struct io *);
63 void* io_tls(struct io *);
64 int io_fileno(struct io *);
65 int io_paused(struct io *, int);
67 /* Buffered output functions */
68 int io_write(struct io *, const void *, size_t);
69 int io_writev(struct io *, const struct iovec *, int);
70 int io_print(struct io *, const char *);
71 int io_printf(struct io *, const char *, ...);
72 int io_vprintf(struct io *, const char *, va_list);
73 size_t io_queued(struct io *);
75 /* Buffered input functions */
76 void* io_data(struct io *);
77 size_t io_datalen(struct io *);
78 char* io_getline(struct io *, size_t *);
79 void io_drop(struct io *, size_t);