aboutsummaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/io.c b/src/io.c
index 902124a..2d62147 100644
--- a/src/io.c
+++ b/src/io.c
@@ -1,8 +1,48 @@
1/*=========================================================================*\
2* Input/Output abstraction
3* LuaSocket toolkit
4*
5* RCS ID: $Id$
6\*=========================================================================*/
1#include "io.h" 7#include "io.h"
2 8
9/*=========================================================================*\
10* Exported functions
11\*=========================================================================*/
12/*-------------------------------------------------------------------------*\
13* Initializes C structure
14\*-------------------------------------------------------------------------*/
3void 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, void *ctx)
4{ 16{
5 io->send = send; 17 io->send = send;
6 io->recv = recv; 18 io->recv = recv;
7 io->ctx = ctx; 19 io->ctx = ctx;
8} 20}
21
22/*-------------------------------------------------------------------------*\
23* Translate error codes to Lua
24\*-------------------------------------------------------------------------*/
25void io_pusherror(lua_State *L, int code)
26{
27 switch (code) {
28 case IO_DONE:
29 lua_pushnil(L);
30 break;
31 case IO_TIMEOUT:
32 lua_pushstring(L, "timeout");
33 break;
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 }
47}
48