src/io.c

1
/*=========================================================================*\
2
* LuaSocket 2.0.2
3
* Copyright (C) 2004-2007 Diego Nehab
4
* 
5
* Input/Output abstraction
6
*
7
* RCS ID: $Id: io.c 2 2006-04-30 19:30:47Z brunoos $
8
\*=========================================================================*/
9
#include "io.h"
10
 
11
/*=========================================================================*\
12
* Exported functions
13
\*=========================================================================*/
14
/*-------------------------------------------------------------------------*\
15
* Initializes C structure
16
\*-------------------------------------------------------------------------*/
17
void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) {
18
    io->send = send;
19
    io->recv = recv;
20
    io->error = error;
21
    io->ctx = ctx;
22
}
23
 
24
/*-------------------------------------------------------------------------*\
25
* I/O error strings
26
\*-------------------------------------------------------------------------*/
27
const char *io_strerror(int err) {
28
    switch (err) {
29
        case IO_DONE: return NULL;
30
        case IO_CLOSED: return "closed";
31
        case IO_TIMEOUT: return "timeout";
32
        default: return "unknown error"; 
33
    }
34
}