| 1 |
/*=========================================================================*\ |
| 2 |
* Input/Output abstraction |
| 3 |
* LuaSocket toolkit |
| 4 |
\*=========================================================================*/ |
| 5 |
#include "io.h" |
| 6 |
|
| 7 |
/*=========================================================================*\ |
| 8 |
* Exported functions |
| 9 |
\*=========================================================================*/ |
| 10 |
/*-------------------------------------------------------------------------*\ |
| 11 |
* Initializes C structure |
| 12 |
\*-------------------------------------------------------------------------*/ |
| 13 |
void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { |
| 14 |
io->send = send; |
| 15 |
io->recv = recv; |
| 16 |
io->error = error; |
| 17 |
io->ctx = ctx; |
| 18 |
} |
| 19 |
|
| 20 |
/*-------------------------------------------------------------------------*\ |
| 21 |
* I/O error strings |
| 22 |
\*-------------------------------------------------------------------------*/ |
| 23 |
const char *io_strerror(int err) { |
| 24 |
switch (err) { |
| 25 |
case IO_DONE: return NULL; |
| 26 |
case IO_CLOSED: return "closed"; |
| 27 |
case IO_TIMEOUT: return "timeout"; |
| 28 |
default: return "unknown error"; |
| 29 |
} |
| 30 |
} |