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