Blame


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