iobuf.h revision 1.1
1/*	$OpenBSD: iobuf.h,v 1.1 2012/01/29 00:32:51 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 */
17
18#include <sys/types.h>
19
20#include <stdarg.h>
21
22struct ioqbuf {
23	struct ioqbuf	*next;
24	char		*buf;
25	size_t		 size;
26	size_t		 wpos;
27	size_t		 rpos;
28};
29
30struct iobuf {
31	char		*buf;
32	size_t		 max;
33	size_t		 size;
34	size_t		 wpos;
35	size_t		 rpos;
36
37	size_t		 queued;
38	struct ioqbuf	*outq;
39	struct ioqbuf	*outqlast;
40};
41
42#define IOBUF_WANT_READ		-1
43#define IOBUF_WANT_WRITE	-2
44#define IOBUF_CLOSED		-3
45#define IOBUF_ERROR		-4
46
47int	iobuf_init(struct iobuf *, size_t, size_t);
48void	iobuf_clear(struct iobuf *);
49
50int	iobuf_extend(struct iobuf *, size_t);
51void	iobuf_normalize(struct iobuf *);
52void	iobuf_drop(struct iobuf *, size_t);
53size_t	iobuf_space(struct iobuf *);
54size_t	iobuf_len(struct iobuf *);
55size_t	iobuf_left(struct iobuf *);
56char   *iobuf_data(struct iobuf *);
57char   *iobuf_getline(struct iobuf *, size_t *);
58ssize_t	iobuf_read(struct iobuf *, int);
59ssize_t	iobuf_read_ssl(struct iobuf *, void *);
60
61size_t  iobuf_queued(struct iobuf *);
62void*   iobuf_reserve(struct iobuf *, size_t);
63int	iobuf_queue(struct iobuf *, const void*, size_t);
64int	iobuf_queuev(struct iobuf *, const struct iovec *, int);
65int	iobuf_fqueue(struct iobuf *, const char *, ...);
66int	iobuf_vfqueue(struct iobuf *, const char *, va_list);
67int	iobuf_flush(struct iobuf *, int);
68int	iobuf_flush_ssl(struct iobuf *, void *);
69ssize_t	iobuf_write(struct iobuf *, int);
70ssize_t	iobuf_write_ssl(struct iobuf *, void *);
71