1 /* $OpenBSD: iobuf.h,v 1.1.1.1 2018/04/27 16:14:36 eric Exp $ */ 2 3 /* 4 * Copyright (c) 2017 Eric Faurot <eric@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 struct ioqbuf { 20 struct ioqbuf *next; 21 char *buf; 22 size_t size; 23 size_t wpos; 24 size_t rpos; 25 }; 26 27 struct iobuf { 28 char *buf; 29 size_t max; 30 size_t size; 31 size_t wpos; 32 size_t rpos; 33 34 size_t queued; 35 struct ioqbuf *outq; 36 struct ioqbuf *outqlast; 37 }; 38 39 #define IOBUF_WANT_READ -1 40 #define IOBUF_WANT_WRITE -2 41 #define IOBUF_CLOSED -3 42 #define IOBUF_ERROR -4 43 #define IOBUF_SSLERROR -5 44 45 int iobuf_init(struct iobuf *, size_t, size_t); 46 void iobuf_clear(struct iobuf *); 47 48 int iobuf_extend(struct iobuf *, size_t); 49 void iobuf_normalize(struct iobuf *); 50 void iobuf_drop(struct iobuf *, size_t); 51 size_t iobuf_space(struct iobuf *); 52 size_t iobuf_len(struct iobuf *); 53 size_t iobuf_left(struct iobuf *); 54 char *iobuf_data(struct iobuf *); 55 char *iobuf_getline(struct iobuf *, size_t *); 56 ssize_t iobuf_read(struct iobuf *, int); 57 ssize_t iobuf_read_ssl(struct iobuf *, void *); 58 59 size_t iobuf_queued(struct iobuf *); 60 void* iobuf_reserve(struct iobuf *, size_t); 61 int iobuf_queue(struct iobuf *, const void*, size_t); 62 int iobuf_queuev(struct iobuf *, const struct iovec *, int); 63 int iobuf_fqueue(struct iobuf *, const char *, ...); 64 int iobuf_vfqueue(struct iobuf *, const char *, va_list); 65 int iobuf_flush(struct iobuf *, int); 66 int iobuf_flush_ssl(struct iobuf *, void *); 67 ssize_t iobuf_write(struct iobuf *, int); 68 ssize_t iobuf_write_ssl(struct iobuf *, void *); 69