luasocket/src/buffer.h

46 lines
1.7 KiB
C
Raw Normal View History

#ifndef BUF_H
#define BUF_H
2002-03-27 19:00:00 +01:00
/*=========================================================================*\
* 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.
2002-03-27 19:00:00 +01:00
\*=========================================================================*/
2005-09-29 08:11:42 +02:00
#include "lua.h"
2003-05-25 03:54:13 +02:00
#include "io.h"
#include "timeout.h"
2002-03-27 19:00:00 +01:00
/* buffer size in bytes */
#define BUF_SIZE 8192
/* buffer control structure */
2005-10-07 06:40:59 +02:00
typedef struct t_buffer_ {
2004-07-01 08:09:29 +02:00
double birthday; /* throttle support info: creation time, */
2004-07-02 20:44:05 +02:00
size_t sent, received; /* bytes sent, and bytes received */
2003-05-25 03:54:13 +02:00
p_io io; /* IO driver used for this buffer */
2005-10-07 06:40:59 +02:00
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 */
2005-10-07 06:40:59 +02:00
} t_buffer;
typedef t_buffer *p_buffer;
2002-03-27 19:00:00 +01:00
2005-10-07 06:40:59 +02:00
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);
2002-03-27 19:00:00 +01:00
2003-05-25 03:54:13 +02:00
#endif /* BUF_H */