aboutsummaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-07-01 03:32:09 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-07-01 03:32:09 +0000
commit7115c12fbc9aae1cd46fdf049697a27fb996181a (patch)
tree2e918f54f729766701aabdef488a6461bc623da1 /src/io.c
parent7aaba59909e8527190694285f56ca68772c97f6a (diff)
downloadluasocket-7115c12fbc9aae1cd46fdf049697a27fb996181a.tar.gz
luasocket-7115c12fbc9aae1cd46fdf049697a27fb996181a.tar.bz2
luasocket-7115c12fbc9aae1cd46fdf049697a27fb996181a.zip
Moving on to beta2.
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/io.c b/src/io.c
index 612454b..30595c7 100644
--- a/src/io.c
+++ b/src/io.c
@@ -12,34 +12,34 @@
12/*-------------------------------------------------------------------------*\ 12/*-------------------------------------------------------------------------*\
13* Initializes C structure 13* Initializes C structure
14\*-------------------------------------------------------------------------*/ 14\*-------------------------------------------------------------------------*/
15void io_init(p_io io, p_send send, p_recv recv, void *ctx) 15void io_init(p_io io, p_send send, p_recv recv, p_geterr geterr, void *ctx) {
16{
17 io->send = send; 16 io->send = send;
18 io->recv = recv; 17 io->recv = recv;
18 io->geterr = geterr;
19 io->ctx = ctx; 19 io->ctx = ctx;
20} 20}
21 21
22/*-------------------------------------------------------------------------*\ 22/*-------------------------------------------------------------------------*\
23* Translate error codes to Lua 23* Translate error codes to Lua
24\*-------------------------------------------------------------------------*/ 24\*-------------------------------------------------------------------------*/
25const char *io_strerror(int code) 25const char *io_strerror(int code) {
26{
27 switch (code) { 26 switch (code) {
28 case IO_DONE: return NULL; 27 case IO_DONE: return NULL;
29 case IO_TIMEOUT: return "timeout";
30 case IO_RETRY: return "retry";
31 case IO_CLOSED: return "closed"; 28 case IO_CLOSED: return "closed";
32 case IO_REFUSED: return "refused"; 29 case IO_TIMEOUT: return "timeout";
30 case IO_CLIPPED: return "clipped";
33 default: return "unknown error"; 31 default: return "unknown error";
34 } 32 }
35} 33}
36 34
37/*-------------------------------------------------------------------------*\ 35/*-------------------------------------------------------------------------*\
38* Translate error codes to Lua 36* Push error message from code or from driver
39\*-------------------------------------------------------------------------*/ 37\*-------------------------------------------------------------------------*/
40void io_pusherror(lua_State *L, int code) 38void io_pusherror(lua_State *L, p_io io, int code)
41{ 39{
42 const char *err = io_strerror(code); 40 const char *err = NULL;
41 if (code < IO_USER) err = io_strerror(code);
42 else err = io->geterr(io->ctx, code);
43 if (err) lua_pushstring(L, err); 43 if (err) lua_pushstring(L, err);
44 else lua_pushnil(L); 44 else lua_pushnil(L);
45} 45}