diff options
Diffstat (limited to 'src/io.h')
-rw-r--r-- | src/io.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/io.h b/src/io.h new file mode 100644 index 0000000..b5b7f1d --- /dev/null +++ b/src/io.h | |||
@@ -0,0 +1,34 @@ | |||
1 | #ifndef IO_H | ||
2 | #define IO_H | ||
3 | |||
4 | #include "error.h" | ||
5 | |||
6 | /* interface to send function */ | ||
7 | typedef int (*p_send) ( | ||
8 | void *ctx, /* context needed by send */ | ||
9 | const char *data, /* pointer to buffer with data to send */ | ||
10 | size_t count, /* number of bytes to send from buffer */ | ||
11 | size_t *sent, /* number of bytes sent uppon return */ | ||
12 | int timeout /* number of miliseconds left for transmission */ | ||
13 | ); | ||
14 | |||
15 | /* interface to recv function */ | ||
16 | typedef int (*p_recv) ( | ||
17 | void *ctx, /* context needed by recv */ | ||
18 | char *data, /* pointer to buffer where data will be writen */ | ||
19 | size_t count, /* number of bytes to receive into buffer */ | ||
20 | size_t *got, /* number of bytes received uppon return */ | ||
21 | int timeout /* number of miliseconds left for transmission */ | ||
22 | ); | ||
23 | |||
24 | /* IO driver definition */ | ||
25 | typedef struct t_io_ { | ||
26 | void *ctx; /* context needed by send/recv */ | ||
27 | p_send send; /* send function pointer */ | ||
28 | p_recv recv; /* receive function pointer */ | ||
29 | } t_io; | ||
30 | typedef t_io *p_io; | ||
31 | |||
32 | void io_init(p_io io, p_send send, p_recv recv, void *ctx); | ||
33 | |||
34 | #endif /* IO_H */ | ||