aboutsummaryrefslogtreecommitdiff
path: root/src/buffer.h
blob: 1502ef090e044d6caac3ede9cc2b20d06aaad9fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*=========================================================================*\
* Buffered input/output routines
*
* RCS ID: $Id$
\*=========================================================================*/
#ifndef BUF_H
#define BUF_H 

#include <lua.h>
#include "io.h"
#include "timeout.h"

/* buffer size in bytes */
#define BUF_SIZE 8192

/*-------------------------------------------------------------------------*\
* Buffer control structure
\*-------------------------------------------------------------------------*/
typedef struct t_buf_ {
    p_io io;                /* IO driver used for this buffer */
    p_tm 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_buf;
typedef t_buf *p_buf;

/*-------------------------------------------------------------------------*\
* Exported functions
\*-------------------------------------------------------------------------*/
void buf_open(lua_State *L);
void buf_init(p_buf buf, p_io io, p_tm tm);
int buf_meth_send(lua_State *L, p_buf buf);
int buf_meth_receive(lua_State *L, p_buf buf);
int buf_isempty(p_buf buf);

#endif /* BUF_H */