summaryrefslogtreecommitdiffstats
path: root/src/buffio.h
blob: e0a2d0adba5d88103031bd337240f3105bf61d81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef foobuffiohfoo
#define foobuffiohfoo

#include <inttypes.h>
#include <sys/types.h>

struct buffio {
    int ifd;
    int ofd;

    uint8_t *input_buf;
    size_t input_max_length, input_index, input_length, input_watermark;

    uint8_t *output_buf;
    size_t output_max_length, output_index, output_length, output_watermark;

    int b_read_cb, b_write_cb;

    void *user;

    void (*eof_cb) (struct buffio *b, void *user);
    void (*output_empty_cb) (struct buffio *b, void *user);
    void (*input_ready_cb) (struct buffio *b, void *user);
};

struct buffio* buffio_new(int ifd, int ofd);
void buffio_free(struct buffio *b);

int buffio_write(struct buffio *b, const uint8_t *d, size_t l);
int buffio_print(struct buffio *b, const char *s);

int buffio_command(struct buffio *b, const char *c);
void buffio_flush_input(struct buffio *b);
int buffio_find_input(struct buffio *b, const char *c);
char *buffio_read_line(struct buffio *b, char *c, size_t l);

void buffio_dump(struct buffio *b);

#endif