Blob


1 /*
2 * bufio.h was written by Omar Polo <op@omarpolo.com>
3 *
4 * This is free and unencumbered software released into the public domain.
5 *
6 * Anyone is free to copy, modify, publish, use, compile, sell, or
7 * distribute this software, either in source code form or as a compiled
8 * binary, for any purpose, commercial or non-commercial, and by any
9 * means.
10 *
11 * In jurisdictions that recognize copyright laws, the author or authors
12 * of this software dedicate any and all copyright interest in the
13 * software to the public domain. We make this dedication for the benefit
14 * of the public at large and to the detriment of our heirs and
15 * successors. We intend this dedication to be an overt act of
16 * relinquishment in perpetuity of all present and future rights to this
17 * software under copyright law.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
28 struct tls;
30 #define BIO_CHUNK 128
31 struct buf {
32 uint8_t *buf;
33 size_t len;
34 size_t cap;
35 size_t cur;
36 };
38 struct bufio {
39 int fd;
40 struct tls *ctx;
41 int wantev;
42 struct buf wbuf;
43 struct buf rbuf;
44 };
46 #define BUFIO_WANT_READ 0x1
47 #define BUFIO_WANT_WRITE 0x2
49 int buf_init(struct buf *);
50 int buf_has_line(struct buf *, const char *);
51 char *buf_getdelim(struct buf *, const char *, size_t *);
52 void buf_drain(struct buf *, size_t);
53 void buf_drain_line(struct buf *, const char *);
54 void buf_free(struct buf *);
56 int bufio_init(struct bufio *);
57 void bufio_free(struct bufio *);
58 int bufio_close(struct bufio *);
59 int bufio_reset(struct bufio *);
60 void bufio_set_fd(struct bufio *, int);
61 int bufio_starttls(struct bufio *, const char *, int,
62 const uint8_t *, size_t, const uint8_t *, size_t);
63 int bufio_ev(struct bufio *);
64 int bufio_handshake(struct bufio *);
65 ssize_t bufio_read(struct bufio *);
66 size_t bufio_drain(struct bufio *, void *, size_t);
67 ssize_t bufio_write(struct bufio *);
68 const char *bufio_io_err(struct bufio *);
69 int bufio_compose(struct bufio *, const void *, size_t);
70 int bufio_compose_str(struct bufio *, const char *);
71 int bufio_compose_fmt(struct bufio *, const char *, ...)
72 __attribute__((__format__ (printf, 2, 3)));
73 void bufio_rewind_cursor(struct bufio *);
75 /* callbacks for pdjson */
76 int bufio_get_cb(void *);
77 int bufio_peek_cb(void *);