diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2013-05-04 21:26:49 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2013-05-04 21:26:49 (GMT) |
| commit | 66e21ce0498f623ccffcee95b1fdcbc218464caa (patch) | |
| tree | 83de913847ce0b1808c46a1bdedb1c4c6c66296d /src/socket/buffer.h | |
| parent | 3799d5ed86e7b508b39544cad3b3346655c804f1 (diff) | |
| parent | e7b29ab9b5e037a8896c62f0473cae8d353d5114 (diff) | |
| download | powder-66e21ce0498f623ccffcee95b1fdcbc218464caa.zip powder-66e21ce0498f623ccffcee95b1fdcbc218464caa.tar.gz | |
Merge pull request #131 from mniip/lua
builtin luasocket
Diffstat (limited to 'src/socket/buffer.h')
| -rw-r--r-- | src/socket/buffer.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/socket/buffer.h b/src/socket/buffer.h new file mode 100644 index 0000000..baf93ca --- /dev/null +++ b/src/socket/buffer.h @@ -0,0 +1,47 @@ +#ifndef BUF_H +#define BUF_H +/*=========================================================================*\ +* Input/Output interface for Lua programs +* LuaSocket toolkit +* +* Line patterns require buffering. Reading one character at a time involves +* too many system calls and is very slow. This module implements the +* LuaSocket interface for input/output on connected objects, as seen by +* Lua programs. +* +* Input is buffered. Output is *not* buffered because there was no simple +* way of making sure the buffered output data would ever be sent. +* +* The module is built on top of the I/O abstraction defined in io.h and the +* timeout management is done with the timeout.h interface. +* +* RCS ID: $Id: buffer.h,v 1.12 2005/10/07 04:40:59 diego Exp $ +\*=========================================================================*/ +#include "lua.h" + +#include "io.h" +#include "timeout.h" + +/* buffer size in bytes */ +#define BUF_SIZE 8192 + +/* buffer control structure */ +typedef struct t_buffer_ { + double birthday; /* throttle support info: creation time, */ + size_t sent, received; /* bytes sent, and bytes received */ + p_io io; /* IO driver used for this buffer */ + p_timeout tm; /* timeout management for this buffer */ + size_t first, last; /* index of first and last bytes of stored data */ + char data[BUF_SIZE]; /* storage space for buffer data */ +} t_buffer; +typedef t_buffer *p_buffer; + +int buffer_open(lua_State *L); +void buffer_init(p_buffer buf, p_io io, p_timeout tm); +int buffer_meth_send(lua_State *L, p_buffer buf); +int buffer_meth_receive(lua_State *L, p_buffer buf); +int buffer_meth_getstats(lua_State *L, p_buffer buf); +int buffer_meth_setstats(lua_State *L, p_buffer buf); +int buffer_isempty(p_buffer buf); + +#endif /* BUF_H */ |
