aboutsummaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2003-06-26 18:47:49 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2003-06-26 18:47:49 +0000
commit71f6bb60bf2b7457091c7106190f92ab7e51f7c6 (patch)
tree8ad3668667bd3da3c34f7ff7ae0a9a7a4daa4679 /src/buffer.c
parentf330540576031528f0daac231c61d4dd06e8ba1e (diff)
downloadluasocket-71f6bb60bf2b7457091c7106190f92ab7e51f7c6.tar.gz
luasocket-71f6bb60bf2b7457091c7106190f92ab7e51f7c6.tar.bz2
luasocket-71f6bb60bf2b7457091c7106190f92ab7e51f7c6.zip
Finished implementation of LuaSocket 2.0 alpha on Linux.
Some testing still needed.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/buffer.c b/src/buffer.c
index ab059bb..c860f35 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1,12 +1,12 @@
1/*=========================================================================*\ 1/*=========================================================================*\
2* Buffered input/output routines 2* Input/Output interface for Lua programs
3* LuaSocket toolkit
3* 4*
4* RCS ID: $Id$ 5* RCS ID: $Id$
5\*=========================================================================*/ 6\*=========================================================================*/
6#include <lua.h> 7#include <lua.h>
7#include <lauxlib.h> 8#include <lauxlib.h>
8 9
9#include "error.h"
10#include "auxiliar.h" 10#include "auxiliar.h"
11#include "buffer.h" 11#include "buffer.h"
12 12
@@ -42,7 +42,7 @@ void buf_init(p_buf buf, p_io io, p_tm tm)
42} 42}
43 43
44/*-------------------------------------------------------------------------*\ 44/*-------------------------------------------------------------------------*\
45* Send data through buffered object 45* object:send() interface
46\*-------------------------------------------------------------------------*/ 46\*-------------------------------------------------------------------------*/
47int buf_meth_send(lua_State *L, p_buf buf) 47int buf_meth_send(lua_State *L, p_buf buf)
48{ 48{
@@ -59,7 +59,7 @@ int buf_meth_send(lua_State *L, p_buf buf)
59 total += sent; 59 total += sent;
60 } 60 }
61 lua_pushnumber(L, total); 61 lua_pushnumber(L, total);
62 error_push(L, err); 62 io_pusherror(L, err);
63#ifdef LUASOCKET_DEBUG 63#ifdef LUASOCKET_DEBUG
64 /* push time elapsed during operation as the last return value */ 64 /* push time elapsed during operation as the last return value */
65 lua_pushnumber(L, (tm_gettime() - tm_getstart(tm))/1000.0); 65 lua_pushnumber(L, (tm_gettime() - tm_getstart(tm))/1000.0);
@@ -68,7 +68,7 @@ int buf_meth_send(lua_State *L, p_buf buf)
68} 68}
69 69
70/*-------------------------------------------------------------------------*\ 70/*-------------------------------------------------------------------------*\
71* Receive data from a buffered object 71* object:receive() interface
72\*-------------------------------------------------------------------------*/ 72\*-------------------------------------------------------------------------*/
73int buf_meth_receive(lua_State *L, p_buf buf) 73int buf_meth_receive(lua_State *L, p_buf buf)
74{ 74{
@@ -101,13 +101,13 @@ int buf_meth_receive(lua_State *L, p_buf buf)
101 luaL_argcheck(L, 0, arg, "invalid receive pattern"); 101 luaL_argcheck(L, 0, arg, "invalid receive pattern");
102 break; 102 break;
103 } 103 }
104 /* raw pattern */ 104 /* get a fixed number of bytes */
105 } else err = recvraw(L, buf, (size_t) lua_tonumber(L, arg)); 105 } else err = recvraw(L, buf, (size_t) lua_tonumber(L, arg));
106 } 106 }
107 /* push nil for each pattern after an error */ 107 /* push nil for each pattern after an error */
108 for ( ; arg <= top; arg++) lua_pushnil(L); 108 for ( ; arg <= top; arg++) lua_pushnil(L);
109 /* last return is an error code */ 109 /* last return is an error code */
110 error_push(L, err); 110 io_pusherror(L, err);
111#ifdef LUASOCKET_DEBUG 111#ifdef LUASOCKET_DEBUG
112 /* push time elapsed during operation as the last return value */ 112 /* push time elapsed during operation as the last return value */
113 lua_pushnumber(L, (tm_gettime() - tm_getstart(tm))/1000.0); 113 lua_pushnumber(L, (tm_gettime() - tm_getstart(tm))/1000.0);
@@ -127,9 +127,10 @@ int buf_isempty(p_buf buf)
127* Internal functions 127* Internal functions
128\*=========================================================================*/ 128\*=========================================================================*/
129/*-------------------------------------------------------------------------*\ 129/*-------------------------------------------------------------------------*\
130* Sends a raw block of data through a buffered object. 130* Sends a block of data (unbuffered)
131\*-------------------------------------------------------------------------*/ 131\*-------------------------------------------------------------------------*/
132static int sendraw(p_buf buf, const char *data, size_t count, size_t *sent) 132static
133int sendraw(p_buf buf, const char *data, size_t count, size_t *sent)
133{ 134{
134 p_io io = buf->io; 135 p_io io = buf->io;
135 p_tm tm = buf->tm; 136 p_tm tm = buf->tm;
@@ -145,7 +146,7 @@ static int sendraw(p_buf buf, const char *data, size_t count, size_t *sent)
145} 146}
146 147
147/*-------------------------------------------------------------------------*\ 148/*-------------------------------------------------------------------------*\
148* Reads a raw block of data from a buffered object. 149* Reads a fixed number of bytes (buffered)
149\*-------------------------------------------------------------------------*/ 150\*-------------------------------------------------------------------------*/
150static 151static
151int recvraw(lua_State *L, p_buf buf, size_t wanted) 152int recvraw(lua_State *L, p_buf buf, size_t wanted)
@@ -167,7 +168,7 @@ int recvraw(lua_State *L, p_buf buf, size_t wanted)
167} 168}
168 169
169/*-------------------------------------------------------------------------*\ 170/*-------------------------------------------------------------------------*\
170* Reads everything until the connection is closed 171* Reads everything until the connection is closed (buffered)
171\*-------------------------------------------------------------------------*/ 172\*-------------------------------------------------------------------------*/
172static 173static
173int recvall(lua_State *L, p_buf buf) 174int recvall(lua_State *L, p_buf buf)
@@ -187,12 +188,12 @@ int recvall(lua_State *L, p_buf buf)
187 188
188/*-------------------------------------------------------------------------*\ 189/*-------------------------------------------------------------------------*\
189* Reads a line terminated by a CR LF pair or just by a LF. The CR and LF 190* Reads a line terminated by a CR LF pair or just by a LF. The CR and LF
190* are not returned by the function and are discarded from the buffer. 191* are not returned by the function and are discarded from the buffer
191\*-------------------------------------------------------------------------*/ 192\*-------------------------------------------------------------------------*/
192static 193static
193int recvline(lua_State *L, p_buf buf) 194int recvline(lua_State *L, p_buf buf)
194{ 195{
195 int err = 0; 196 int err = IO_DONE;
196 luaL_Buffer b; 197 luaL_Buffer b;
197 luaL_buffinit(L, &b); 198 luaL_buffinit(L, &b);
198 while (err == IO_DONE) { 199 while (err == IO_DONE) {
@@ -215,7 +216,8 @@ int recvline(lua_State *L, p_buf buf)
215} 216}
216 217
217/*-------------------------------------------------------------------------*\ 218/*-------------------------------------------------------------------------*\
218* Skips a given number of bytes in read buffer 219* Skips a given number of bytes from read buffer. No data is read from the
220* transport layer
219\*-------------------------------------------------------------------------*/ 221\*-------------------------------------------------------------------------*/
220static 222static
221void buf_skip(p_buf buf, size_t count) 223void buf_skip(p_buf buf, size_t count)
@@ -227,7 +229,7 @@ void buf_skip(p_buf buf, size_t count)
227 229
228/*-------------------------------------------------------------------------*\ 230/*-------------------------------------------------------------------------*\
229* Return any data available in buffer, or get more data from transport layer 231* Return any data available in buffer, or get more data from transport layer
230* if buffer is empty. 232* if buffer is empty
231\*-------------------------------------------------------------------------*/ 233\*-------------------------------------------------------------------------*/
232static 234static
233int buf_get(p_buf buf, const char **data, size_t *count) 235int buf_get(p_buf buf, const char **data, size_t *count)
@@ -245,3 +247,4 @@ int buf_get(p_buf buf, const char **data, size_t *count)
245 *data = buf->data + buf->first; 247 *data = buf->data + buf->first;
246 return err; 248 return err;
247} 249}
250