Mercurial > luasocket
comparison src/io.h @ 0:4b915342e2a8
LuaSocket 2.0.2 + CMake build description.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Tue, 26 Aug 2008 18:40:01 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4b915342e2a8 |
---|---|
1 #ifndef IO_H | |
2 #define IO_H | |
3 /*=========================================================================*\ | |
4 * Input/Output abstraction | |
5 * LuaSocket toolkit | |
6 * | |
7 * This module defines the interface that LuaSocket expects from the | |
8 * transport layer for streamed input/output. The idea is that if any | |
9 * transport implements this interface, then the buffer.c functions | |
10 * automatically work on it. | |
11 * | |
12 * The module socket.h implements this interface, and thus the module tcp.h | |
13 * is very simple. | |
14 * | |
15 * RCS ID: $Id: io.h,v 1.11 2005/10/07 04:40:59 diego Exp $ | |
16 \*=========================================================================*/ | |
17 #include <stdio.h> | |
18 #include "lua.h" | |
19 | |
20 #include "timeout.h" | |
21 | |
22 /* IO error codes */ | |
23 enum { | |
24 IO_DONE = 0, /* operation completed successfully */ | |
25 IO_TIMEOUT = -1, /* operation timed out */ | |
26 IO_CLOSED = -2, /* the connection has been closed */ | |
27 IO_UNKNOWN = -3 | |
28 }; | |
29 | |
30 /* interface to error message function */ | |
31 typedef const char *(*p_error) ( | |
32 void *ctx, /* context needed by send */ | |
33 int err /* error code */ | |
34 ); | |
35 | |
36 /* interface to send function */ | |
37 typedef int (*p_send) ( | |
38 void *ctx, /* context needed by send */ | |
39 const char *data, /* pointer to buffer with data to send */ | |
40 size_t count, /* number of bytes to send from buffer */ | |
41 size_t *sent, /* number of bytes sent uppon return */ | |
42 p_timeout tm /* timeout control */ | |
43 ); | |
44 | |
45 /* interface to recv function */ | |
46 typedef int (*p_recv) ( | |
47 void *ctx, /* context needed by recv */ | |
48 char *data, /* pointer to buffer where data will be writen */ | |
49 size_t count, /* number of bytes to receive into buffer */ | |
50 size_t *got, /* number of bytes received uppon return */ | |
51 p_timeout tm /* timeout control */ | |
52 ); | |
53 | |
54 /* IO driver definition */ | |
55 typedef struct t_io_ { | |
56 void *ctx; /* context needed by send/recv */ | |
57 p_send send; /* send function pointer */ | |
58 p_recv recv; /* receive function pointer */ | |
59 p_error error; /* strerror function */ | |
60 } t_io; | |
61 typedef t_io *p_io; | |
62 | |
63 void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); | |
64 const char *io_strerror(int err); | |
65 | |
66 #endif /* IO_H */ | |
67 |