5 typedef struct bufio_chain_entry bufio_chain_entry;
7 struct bufio_chain_entry {
8 bufio_chain_entry *next;
15 bufio_chain_entry *head, *tail;
19 * Enqueues the given buffer for writing. After writing, it will be freed.
20 * Returns -1 if calloc failed.
22 int bufio_chain_append(bufio_chain *bc, void *buf, size_t len);
25 * Flush as much data as possible into the given FD.
26 * Returns -1 for errors, 0 for ok. errno is left
27 * intact on errors, so you might want to check for
30 int bufio_chain_flush(bufio_chain *bc, int fd);
33 * Clear the buffer chain without sending any data.
35 void bufio_chain_clear(bufio_chain *bc);
40 typedef struct bufio_connection bufio_connection;
42 typedef void (*bufio_connection_error_cb_t)(bufio_connection *con);
43 typedef void (*bufio_connection_data_cb_t)(bufio_connection *con);
45 struct bufio_connection {
46 ev_io rw; /* readonly */
47 ev_io ww; /* readonly */
48 struct ev_loop *loop; /* readonly */
49 void *inbuf; /* readonly */
50 size_t inbuf_size; /* readonly */
51 size_t inbuf_used; /* readonly */
52 bufio_chain outbuf; /* readonly */
55 * Called when an error has occured. You should react to it by destroying
56 * the connection. This property can be changed manually at any time.
58 bufio_connection_error_cb_t err_cb;
61 * Called when your read buffer has been filled completely. When this is
62 * called, nothing will be read anymore until you set a new read buffer.
63 * This property can be changed manually at any time.
65 bufio_connection_data_cb_t data_cb;
68 * Not touched by this library.
74 * Creates a bufio connection around an existing file descriptor.
75 * This call already activates the watcher without initializing some
76 * important stuff, so set it before returning to the eventloop/entering
79 * - the input buffer – set it using `bufio_connection_set_read_buffer`
80 * - the callbacks (`err_cb` and `data_cb`) – set them directly
82 bufio_connection *bufio_connection_create(struct ev_loop *loop, int fd);
84 void bufio_connection_set_read_buffer(bufio_connection *con, void *buf, size_t size);
87 * This stops our watcher and clears and frees the output buffers and the
88 * connection struct, but it doesn't touch the input buffer or the fd.
90 void bufio_connection_destroy(bufio_connection *con);
93 * This enqueues a chunk of data to be written. You are not allowed to
94 * touch the buffer anymore after calling this function!
96 int bufio_connection_write(bufio_connection *con, void *buf, size_t len);