aboutsummaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-07-01 06:09:29 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-07-01 06:09:29 +0000
commit63807d647624df155a81a2b323f370e2c36192f6 (patch)
tree28d53540d166cc01eb0a3302e4f0dc5d2cc6c809 /src/buffer.c
parent2562738e2db9d7654c48c10247e683215e09b4a5 (diff)
downloadluasocket-63807d647624df155a81a2b323f370e2c36192f6.tar.gz
luasocket-63807d647624df155a81a2b323f370e2c36192f6.tar.bz2
luasocket-63807d647624df155a81a2b323f370e2c36192f6.zip
Added getstats.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c
index aa50db0..baa248a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -45,6 +45,18 @@ void buf_init(p_buf buf, p_io io, p_tm tm) {
45 buf->first = buf->last = 0; 45 buf->first = buf->last = 0;
46 buf->io = io; 46 buf->io = io;
47 buf->tm = tm; 47 buf->tm = tm;
48 buf->received = buf->sent = 0;
49 buf->birthday = tm_gettime();
50}
51
52/*-------------------------------------------------------------------------*\
53* object:getstats() interface
54\*-------------------------------------------------------------------------*/
55int buf_meth_getstats(lua_State *L, p_buf buf) {
56 lua_pushnumber(L, buf->received);
57 lua_pushnumber(L, buf->sent);
58 lua_pushnumber(L, tm_gettime() - buf->birthday);
59 return 3;
48} 60}
49 61
50/*-------------------------------------------------------------------------*\ 62/*-------------------------------------------------------------------------*\
@@ -141,6 +153,7 @@ static int sendraw(p_buf buf, const char *data, size_t count, size_t *sent) {
141 total += done; 153 total += done;
142 } 154 }
143 *sent = total; 155 *sent = total;
156 buf->sent += total;
144 return err; 157 return err;
145} 158}
146 159
@@ -205,6 +218,7 @@ static int recvline(p_buf buf, luaL_Buffer *b) {
205* transport layer 218* transport layer
206\*-------------------------------------------------------------------------*/ 219\*-------------------------------------------------------------------------*/
207static void buf_skip(p_buf buf, size_t count) { 220static void buf_skip(p_buf buf, size_t count) {
221 buf->received += count;
208 buf->first += count; 222 buf->first += count;
209 if (buf_isempty(buf)) 223 if (buf_isempty(buf))
210 buf->first = buf->last = 0; 224 buf->first = buf->last = 0;