1#ifndef BUF_H
2#define BUF_H
3/*=========================================================================*\
4* Input/Output interface for Lua programs
5* LuaSocket toolkit
6*
7* Line patterns require buffering. Reading one character at a time involves
8* too many system calls and is very slow. This module implements the
9* LuaSocket interface for input/output on connected objects, as seen by
10* Lua programs.
11*
12* Input is buffered. Output is *not* buffered because there was no simple
13* way of making sure the buffered output data would ever be sent.
14*
15* The module is built on top of the I/O abstraction defined in io.h and the
16* timeout management is done with the timeout.h interface.
17\*=========================================================================*/
18#include "lua.h"
19
20#include "io.h"
21#include "timeout.h"
22
23/* buffer size in bytes */
24#define BUF_SIZE 8192
25
26/* buffer control structure */
27typedef struct t_buffer_ {
28 double birthday; /* throttle support info: creation time, */
29 size_t sent, received; /* bytes sent, and bytes received */
30 p_io io; /* IO driver used for this buffer */
31 p_timeout tm; /* timeout management for this buffer */
32 size_t first, last; /* index of first and last bytes of stored data */
33 char data[BUF_SIZE]; /* storage space for buffer data */
34} t_buffer;
35typedef t_buffer *p_buffer;
36
37int buffer_open(lua_State *L);
38void buffer_init(p_buffer buf, p_io io, p_timeout tm);
39int buffer_meth_send(lua_State *L, p_buffer buf);
40int buffer_meth_receive(lua_State *L, p_buffer buf);
41int buffer_meth_getstats(lua_State *L, p_buffer buf);
42int buffer_meth_setstats(lua_State *L, p_buffer buf);
43int buffer_isempty(p_buffer buf);
44
45#endif /* BUF_H */
46