7 typedef struct bufio_chain_entry bufio_chain_entry;
9 struct bufio_chain_entry {
10 bufio_chain_entry *next;
17 bufio_chain_entry *head, *tail;
21 * Enqueues the given buffer for writing. After writing, it will be freed.
22 * Returns -1 if calloc failed.
24 int bufio_chain_append(bufio_chain *bc, void *buf, size_t len);
27 * Flush as much data as possible into the given FD.
28 * Returns -1 for errors, 0 for ok. errno is left
29 * intact on errors, so you might want to check for
32 int bufio_chain_flush(bufio_chain *bc, int fd);
35 * Clear the buffer chain without sending any data.
37 void bufio_chain_clear(bufio_chain *bc);
42 typedef struct bufio_connection bufio_connection;
44 typedef void (*bufio_connection_error_cb_t)(bufio_connection *con);
45 typedef void (*bufio_connection_data_cb_t)(bufio_connection *con);
47 struct bufio_connection {
48 ev_io rw; /* readonly */
49 ev_io ww; /* readonly */
50 struct ev_loop *loop; /* readonly */
51 void *inbuf; /* readonly */
52 size_t inbuf_size; /* readonly */
53 size_t inbuf_used; /* readonly */
54 bufio_chain outbuf; /* readonly */
57 * Called when an error has occured. You should react to it by destroying
58 * the connection. This property can be changed manually at any time.
60 bufio_connection_error_cb_t err_cb;
63 * Called when your read buffer has been filled completely. When this is
64 * called, nothing will be read anymore until you set a new read buffer.
65 * This property can be changed manually at any time.
67 bufio_connection_data_cb_t data_cb;
70 * Not touched by this library.
76 * Creates a bufio connection around an existing file descriptor.
77 * This call already activates the watcher without initializing some
78 * important stuff, so set it before returning to the eventloop/entering
81 * - the input buffer – set it using `bufio_connection_set_read_buffer`
82 * - the callbacks (`err_cb` and `data_cb`) – set them directly
84 bufio_connection *bufio_connection_create(struct ev_loop *loop, int fd);
86 void bufio_connection_set_read_buffer(bufio_connection *con, void *buf, size_t size);
89 * This stops our watcher and clears and frees the output buffers and the
90 * connection struct, but it doesn't touch the input buffer or the fd.
92 void bufio_connection_destroy(bufio_connection *con);
95 * This enqueues a chunk of data to be written. You are not allowed to
96 * touch the buffer anymore after calling this function!
98 int bufio_connection_write(bufio_connection *con, void *buf, size_t len);