diff options
Diffstat (limited to 'src/io.h')
-rw-r--r-- | src/io.h | 28 |
1 files changed, 13 insertions, 15 deletions
@@ -21,13 +21,18 @@ | |||
21 | 21 | ||
22 | /* IO error codes */ | 22 | /* IO error codes */ |
23 | enum { | 23 | enum { |
24 | IO_DONE, /* operation completed successfully */ | 24 | IO_DONE = 0, /* operation completed successfully */ |
25 | IO_TIMEOUT, /* operation timed out */ | 25 | IO_TIMEOUT = -1, /* operation timed out */ |
26 | IO_CLOSED, /* the connection has been closed */ | 26 | IO_CLOSED = -2, /* the connection has been closed */ |
27 | IO_CLIPPED, /* maxium bytes count reached */ | 27 | IO_CLIPPED = -3 /* maxium bytes count reached */ |
28 | IO_USER /* last element in enum is user custom error */ | ||
29 | }; | 28 | }; |
30 | 29 | ||
30 | /* interface to error message function */ | ||
31 | typedef const char *(*p_error) ( | ||
32 | void *ctx, /* context needed by send */ | ||
33 | int err /* error code */ | ||
34 | ); | ||
35 | |||
31 | /* interface to send function */ | 36 | /* interface to send function */ |
32 | typedef int (*p_send) ( | 37 | typedef int (*p_send) ( |
33 | void *ctx, /* context needed by send */ | 38 | void *ctx, /* context needed by send */ |
@@ -37,12 +42,6 @@ typedef int (*p_send) ( | |||
37 | p_tm tm /* timeout control */ | 42 | p_tm tm /* timeout control */ |
38 | ); | 43 | ); |
39 | 44 | ||
40 | /* returns an error string */ | ||
41 | typedef const char *(*p_geterr) ( | ||
42 | void *ctx, /* context needed by geterror */ | ||
43 | int code /* error code */ | ||
44 | ); | ||
45 | |||
46 | /* interface to recv function */ | 45 | /* interface to recv function */ |
47 | typedef int (*p_recv) ( | 46 | typedef int (*p_recv) ( |
48 | void *ctx, /* context needed by recv */ | 47 | void *ctx, /* context needed by recv */ |
@@ -57,12 +56,11 @@ typedef struct t_io_ { | |||
57 | void *ctx; /* context needed by send/recv */ | 56 | void *ctx; /* context needed by send/recv */ |
58 | p_send send; /* send function pointer */ | 57 | p_send send; /* send function pointer */ |
59 | p_recv recv; /* receive function pointer */ | 58 | p_recv recv; /* receive function pointer */ |
60 | p_geterr geterr; /* receive function pointer */ | 59 | p_error error; /* strerror function */ |
61 | } t_io; | 60 | } t_io; |
62 | typedef t_io *p_io; | 61 | typedef t_io *p_io; |
63 | 62 | ||
64 | const char *io_strerror(int code); | 63 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); |
65 | void io_pusherror(lua_State *L, p_io io, int code); | 64 | const char *io_strerror(int err); |
66 | void io_init(p_io io, p_send send, p_recv recv, p_geterr geterr, void *ctx); | ||
67 | 65 | ||
68 | #endif /* IO_H */ | 66 | #endif /* IO_H */ |