Blob


1 /* $OpenBSD: iobuf.h,v 1.5 2019/06/12 17:42:53 eric 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 */
18 struct ioqbuf {
19 struct ioqbuf *next;
20 char *buf;
21 size_t size;
22 size_t wpos;
23 size_t rpos;
24 };
26 struct iobuf {
27 char *buf;
28 size_t max;
29 size_t size;
30 size_t wpos;
31 size_t rpos;
33 size_t queued;
34 struct ioqbuf *outq;
35 struct ioqbuf *outqlast;
36 };
38 #define IOBUF_WANT_READ -1
39 #define IOBUF_WANT_WRITE -2
40 #define IOBUF_CLOSED -3
41 #define IOBUF_ERROR -4
42 #define IOBUF_TLSERROR -5
44 int iobuf_init(struct iobuf *, size_t, size_t);
45 void iobuf_clear(struct iobuf *);
47 int iobuf_extend(struct iobuf *, size_t);
48 void iobuf_normalize(struct iobuf *);
49 void iobuf_drop(struct iobuf *, size_t);
50 size_t iobuf_space(struct iobuf *);
51 size_t iobuf_len(struct iobuf *);
52 size_t iobuf_left(struct iobuf *);
53 char *iobuf_data(struct iobuf *);
54 char *iobuf_getline(struct iobuf *, size_t *);
55 ssize_t iobuf_read(struct iobuf *, int);
56 ssize_t iobuf_read_tls(struct iobuf *, void *);
58 size_t iobuf_queued(struct iobuf *);
59 void* iobuf_reserve(struct iobuf *, size_t);
60 int iobuf_queue(struct iobuf *, const void*, size_t);
61 int iobuf_queuev(struct iobuf *, const struct iovec *, int);
62 int iobuf_fqueue(struct iobuf *, const char *, ...);
63 int iobuf_vfqueue(struct iobuf *, const char *, va_list);
64 int iobuf_flush(struct iobuf *, int);
65 int iobuf_flush_tls(struct iobuf *, void *);
66 ssize_t iobuf_write(struct iobuf *, int);
67 ssize_t iobuf_write_tls(struct iobuf *, void *);