2003-06-26 20:47:49 +02:00
|
|
|
/*=========================================================================*\
|
|
|
|
* Input/Output abstraction
|
|
|
|
* LuaSocket toolkit
|
|
|
|
*
|
|
|
|
* RCS ID: $Id$
|
|
|
|
\*=========================================================================*/
|
2003-05-25 03:54:13 +02:00
|
|
|
#include "io.h"
|
|
|
|
|
2003-06-26 20:47:49 +02:00
|
|
|
/*=========================================================================*\
|
|
|
|
* Exported functions
|
|
|
|
\*=========================================================================*/
|
|
|
|
/*-------------------------------------------------------------------------*\
|
|
|
|
* Initializes C structure
|
|
|
|
\*-------------------------------------------------------------------------*/
|
2003-05-25 03:54:13 +02:00
|
|
|
void io_init(p_io io, p_send send, p_recv recv, void *ctx)
|
|
|
|
{
|
|
|
|
io->send = send;
|
|
|
|
io->recv = recv;
|
|
|
|
io->ctx = ctx;
|
|
|
|
}
|
2003-06-26 20:47:49 +02:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*\
|
|
|
|
* Translate error codes to Lua
|
|
|
|
\*-------------------------------------------------------------------------*/
|
|
|
|
void io_pusherror(lua_State *L, int code)
|
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case IO_DONE:
|
|
|
|
lua_pushnil(L);
|
|
|
|
break;
|
|
|
|
case IO_TIMEOUT:
|
|
|
|
lua_pushstring(L, "timeout");
|
|
|
|
break;
|
|
|
|
case IO_LIMITED:
|
|
|
|
lua_pushstring(L, "limited");
|
|
|
|
break;
|
|
|
|
case IO_CLOSED:
|
|
|
|
lua_pushstring(L, "closed");
|
|
|
|
break;
|
|
|
|
case IO_REFUSED:
|
|
|
|
lua_pushstring(L, "refused");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lua_pushstring(L, "unknown error");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|