iobuf.h
changeset 0 9e2cb1ed20b1
child 24 815ac41e5780
equal deleted inserted replaced
-1:000000000000 0:9e2cb1ed20b1
       
     1 /*	$OpenBSD: iobuf.h,v 1.1 2014/01/27 15:49:52 sunil 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 
       
    22 struct ioqbuf {
       
    23 	struct ioqbuf	*next;
       
    24 	char		*buf;
       
    25 	size_t		 size;
       
    26 	size_t		 wpos;
       
    27 	size_t		 rpos;
       
    28 };
       
    29 
       
    30 struct 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 #define IOBUF_SSLERROR		-5
       
    47 
       
    48 int	iobuf_init(struct iobuf *, size_t, size_t);
       
    49 void	iobuf_clear(struct iobuf *);
       
    50 
       
    51 int	iobuf_extend(struct iobuf *, size_t);
       
    52 void	iobuf_normalize(struct iobuf *);
       
    53 void	iobuf_drop(struct iobuf *, size_t);
       
    54 size_t	iobuf_space(struct iobuf *);
       
    55 size_t	iobuf_len(struct iobuf *);
       
    56 size_t	iobuf_left(struct iobuf *);
       
    57 char   *iobuf_data(struct iobuf *);
       
    58 char   *iobuf_getline(struct iobuf *, size_t *);
       
    59 ssize_t	iobuf_read(struct iobuf *, int);
       
    60 ssize_t	iobuf_read_ssl(struct iobuf *, void *);
       
    61 
       
    62 size_t  iobuf_queued(struct iobuf *);
       
    63 void*   iobuf_reserve(struct iobuf *, size_t);
       
    64 int	iobuf_queue(struct iobuf *, const void*, size_t);
       
    65 int	iobuf_queuev(struct iobuf *, const struct iovec *, int);
       
    66 int	iobuf_fqueue(struct iobuf *, const char *, ...);
       
    67 int	iobuf_vfqueue(struct iobuf *, const char *, va_list);
       
    68 int	iobuf_flush(struct iobuf *, int);
       
    69 int	iobuf_flush_ssl(struct iobuf *, void *);
       
    70 ssize_t	iobuf_write(struct iobuf *, int);
       
    71 ssize_t	iobuf_write_ssl(struct iobuf *, void *);