1 /* $OpenBSD: ioev.h,v 1.20 2021/07/28 19:39:50 benno Exp $ */ 2 /* 3 * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> 4 * 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. 8 * 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. 16 */ 17 18 enum { 19 IO_CONNECTED = 0, /* connection successful */ 20 IO_TLSREADY, /* TLS started successfully */ 21 IO_DATAIN, /* new data in input buffer */ 22 IO_LOWAT, /* output queue running low */ 23 IO_DISCONNECTED, /* error? */ 24 IO_TIMEOUT, /* error? */ 25 IO_ERROR, /* details? */ 26 }; 27 28 #define IO_IN 0x01 29 #define IO_OUT 0x02 30 31 struct io; 32 struct tls; 33 34 void io_set_nonblocking(int); 35 void io_set_nolinger(int); 36 37 struct io *io_new(void); 38 void io_free(struct io *); 39 void io_set_read(struct io *); 40 void io_set_write(struct io *); 41 void io_set_fd(struct io *, int); 42 void io_set_callback(struct io *io, void(*)(struct io *, int, void *), void *); 43 void io_set_timeout(struct io *, int); 44 void io_set_lowat(struct io *, size_t); 45 void io_pause(struct io *, int); 46 void io_resume(struct io *, int); 47 void io_reload(struct io *); 48 int io_connect(struct io *, const struct sockaddr *, const struct sockaddr *); 49 int io_connect_tls(struct io *, struct tls *, const char *); 50 int io_accept_tls(struct io *, struct tls *); 51 const char* io_strio(struct io *); 52 const char* io_strevent(int); 53 const char* io_error(struct io *); 54 struct tls* io_tls(struct io *); 55 int io_fileno(struct io *); 56 int io_paused(struct io *, int); 57 58 /* Buffered output functions */ 59 int io_write(struct io *, const void *, size_t); 60 int io_writev(struct io *, const struct iovec *, int); 61 int io_print(struct io *, const char *); 62 int io_printf(struct io *, const char *, ...) 63 __attribute__((__format__ (printf, 2, 3))); 64 int io_vprintf(struct io *, const char *, va_list) 65 __attribute__((__format__ (printf, 2, 0))); 66 size_t io_queued(struct io *); 67 68 /* Buffered input functions */ 69 void* io_data(struct io *); 70 size_t io_datalen(struct io *); 71 char* io_getline(struct io *, size_t *); 72 void io_drop(struct io *, size_t); 73