aboutsummaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/io.c b/src/io.c
index 2d62147..612454b 100644
--- a/src/io.c
+++ b/src/io.c
@@ -22,27 +22,24 @@ void io_init(p_io io, p_send send, p_recv recv, void *ctx)
22/*-------------------------------------------------------------------------*\ 22/*-------------------------------------------------------------------------*\
23* Translate error codes to Lua 23* Translate error codes to Lua
24\*-------------------------------------------------------------------------*/ 24\*-------------------------------------------------------------------------*/
25void io_pusherror(lua_State *L, int code) 25const char *io_strerror(int code)
26{ 26{
27 switch (code) { 27 switch (code) {
28 case IO_DONE: 28 case IO_DONE: return NULL;
29 lua_pushnil(L); 29 case IO_TIMEOUT: return "timeout";
30 break; 30 case IO_RETRY: return "retry";
31 case IO_TIMEOUT: 31 case IO_CLOSED: return "closed";
32 lua_pushstring(L, "timeout"); 32 case IO_REFUSED: return "refused";
33 break; 33 default: return "unknown error";
34 case IO_LIMITED:
35 lua_pushstring(L, "limited");
36 break;
37 case IO_CLOSED:
38 lua_pushstring(L, "closed");
39 break;
40 case IO_REFUSED:
41 lua_pushstring(L, "refused");
42 break;
43 default:
44 lua_pushstring(L, "unknown error");
45 break;
46 } 34 }
47} 35}
48 36
37/*-------------------------------------------------------------------------*\
38* Translate error codes to Lua
39\*-------------------------------------------------------------------------*/
40void io_pusherror(lua_State *L, int code)
41{
42 const char *err = io_strerror(code);
43 if (err) lua_pushstring(L, err);
44 else lua_pushnil(L);
45}