1 /* $OpenBSD: ioev.h,v 1.18 2019/09/11 04:19:19 martijn 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_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? */ 27 }; 28 29 #define IO_IN 0x01 30 #define IO_OUT 0x02 31 32 struct io; 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_start_tls(struct io *, void *); 50 const char* io_strio(struct io *); 51 const char* io_strevent(int); 52 const char* io_error(struct io *); 53 void* io_tls(struct io *); 54 int io_fileno(struct io *); 55 int io_paused(struct io *, int); 56 57 /* Buffered output functions */ 58 int io_write(struct io *, const void *, size_t); 59 int io_writev(struct io *, const struct iovec *, int); 60 int io_print(struct io *, const char *); 61 int io_printf(struct io *, const char *, ...) 62 __attribute__((__format__ (printf, 2, 3))); 63 int io_vprintf(struct io *, const char *, va_list); 64 size_t io_queued(struct io *); 65 66 /* Buffered input functions */ 67 void* io_data(struct io *); 68 size_t io_datalen(struct io *); 69 char* io_getline(struct io *, size_t *); 70 void io_drop(struct io *, size_t); 71