diff options
Diffstat (limited to 'src/io.h')
-rw-r--r-- | src/io.h | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -17,14 +17,15 @@ | |||
17 | #include <stdio.h> | 17 | #include <stdio.h> |
18 | #include <lua.h> | 18 | #include <lua.h> |
19 | 19 | ||
20 | #include "timeout.h" | ||
21 | |||
20 | /* IO error codes */ | 22 | /* IO error codes */ |
21 | enum { | 23 | enum { |
22 | IO_DONE, /* operation completed successfully */ | 24 | IO_DONE, /* operation completed successfully */ |
23 | IO_RETRY, /* please try again */ | ||
24 | IO_TIMEOUT, /* operation timed out */ | 25 | IO_TIMEOUT, /* operation timed out */ |
25 | IO_CLOSED, /* the connection has been closed */ | 26 | IO_CLOSED, /* the connection has been closed */ |
26 | IO_REFUSED, /* transfer has been refused */ | 27 | IO_CLIPPED, /* maxium bytes count reached */ |
27 | IO_ERROR /* something else wrong... */ | 28 | IO_USER /* last element in enum is user custom error */ |
28 | }; | 29 | }; |
29 | 30 | ||
30 | /* interface to send function */ | 31 | /* interface to send function */ |
@@ -33,7 +34,13 @@ typedef int (*p_send) ( | |||
33 | const char *data, /* pointer to buffer with data to send */ | 34 | const char *data, /* pointer to buffer with data to send */ |
34 | size_t count, /* number of bytes to send from buffer */ | 35 | size_t count, /* number of bytes to send from buffer */ |
35 | size_t *sent, /* number of bytes sent uppon return */ | 36 | size_t *sent, /* number of bytes sent uppon return */ |
36 | int timeout /* number of miliseconds left for transmission */ | 37 | p_tm tm /* timeout control */ |
38 | ); | ||
39 | |||
40 | /* returns an error string */ | ||
41 | typedef const char *(*p_geterr) ( | ||
42 | void *ctx, /* context needed by geterror */ | ||
43 | int code /* error code */ | ||
37 | ); | 44 | ); |
38 | 45 | ||
39 | /* interface to recv function */ | 46 | /* interface to recv function */ |
@@ -42,7 +49,7 @@ typedef int (*p_recv) ( | |||
42 | char *data, /* pointer to buffer where data will be writen */ | 49 | char *data, /* pointer to buffer where data will be writen */ |
43 | size_t count, /* number of bytes to receive into buffer */ | 50 | size_t count, /* number of bytes to receive into buffer */ |
44 | size_t *got, /* number of bytes received uppon return */ | 51 | size_t *got, /* number of bytes received uppon return */ |
45 | int timeout /* number of miliseconds left for transmission */ | 52 | p_tm tm /* timeout control */ |
46 | ); | 53 | ); |
47 | 54 | ||
48 | /* IO driver definition */ | 55 | /* IO driver definition */ |
@@ -50,11 +57,12 @@ typedef struct t_io_ { | |||
50 | void *ctx; /* context needed by send/recv */ | 57 | void *ctx; /* context needed by send/recv */ |
51 | p_send send; /* send function pointer */ | 58 | p_send send; /* send function pointer */ |
52 | p_recv recv; /* receive function pointer */ | 59 | p_recv recv; /* receive function pointer */ |
60 | p_geterr geterr; /* receive function pointer */ | ||
53 | } t_io; | 61 | } t_io; |
54 | typedef t_io *p_io; | 62 | typedef t_io *p_io; |
55 | 63 | ||
56 | const char *io_strerror(int code); | 64 | const char *io_strerror(int code); |
57 | void io_pusherror(lua_State *L, int code); | 65 | void io_pusherror(lua_State *L, p_io io, int code); |
58 | void io_init(p_io io, p_send send, p_recv recv, void *ctx); | 66 | void io_init(p_io io, p_send send, p_recv recv, p_geterr geterr, void *ctx); |
59 | 67 | ||
60 | #endif /* IO_H */ | 68 | #endif /* IO_H */ |