diff options
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 14 |
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 | \*-------------------------------------------------------------------------*/ | ||
55 | int 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 | \*-------------------------------------------------------------------------*/ |
207 | static void buf_skip(p_buf buf, size_t count) { | 220 | static 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; |