Blame src/buffer.h

Packit b53373
#ifndef BUF_H
Packit b53373
#define BUF_H 
Packit b53373
/*=========================================================================*\
Packit b53373
* Input/Output interface for Lua programs
Packit b53373
* LuaSocket toolkit
Packit b53373
*
Packit b53373
* Line patterns require buffering. Reading one character at a time involves
Packit b53373
* too many system calls and is very slow. This module implements the
Packit b53373
* LuaSocket interface for input/output on connected objects, as seen by 
Packit b53373
* Lua programs. 
Packit b53373
*
Packit b53373
* Input is buffered. Output is *not* buffered because there was no simple
Packit b53373
* way of making sure the buffered output data would ever be sent.
Packit b53373
*
Packit b53373
* The module is built on top of the I/O abstraction defined in io.h and the
Packit b53373
* timeout management is done with the timeout.h interface.
Packit b53373
\*=========================================================================*/
Packit b53373
#include "lua.h"
Packit b53373
Packit b53373
#include "io.h"
Packit b53373
#include "timeout.h"
Packit b53373
Packit b53373
/* buffer size in bytes */
Packit b53373
#define BUF_SIZE 8192
Packit b53373
Packit b53373
/* buffer control structure */
Packit b53373
typedef struct t_buffer_ {
Packit b53373
    double birthday;        /* throttle support info: creation time, */
Packit b53373
    size_t sent, received;  /* bytes sent, and bytes received */
Packit b53373
    p_io io;                /* IO driver used for this buffer */
Packit b53373
    p_timeout tm;           /* timeout management for this buffer */
Packit b53373
    size_t first, last;     /* index of first and last bytes of stored data */
Packit b53373
    char data[BUF_SIZE];    /* storage space for buffer data */
Packit b53373
} t_buffer;
Packit b53373
typedef t_buffer *p_buffer;
Packit b53373
Packit b53373
int buffer_open(lua_State *L);
Packit b53373
void buffer_init(p_buffer buf, p_io io, p_timeout tm);
Packit b53373
int buffer_meth_send(lua_State *L, p_buffer buf);
Packit b53373
int buffer_meth_receive(lua_State *L, p_buffer buf);
Packit b53373
int buffer_meth_getstats(lua_State *L, p_buffer buf);
Packit b53373
int buffer_meth_setstats(lua_State *L, p_buffer buf);
Packit b53373
int buffer_isempty(p_buffer buf);
Packit b53373
Packit b53373
#endif /* BUF_H */