aboutsummaryrefslogtreecommitdiff
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
parent2562738e2db9d7654c48c10247e683215e09b4a5 (diff)
downloadluasocket-63807d647624df155a81a2b323f370e2c36192f6.tar.gz
luasocket-63807d647624df155a81a2b323f370e2c36192f6.tar.bz2
luasocket-63807d647624df155a81a2b323f370e2c36192f6.zip
Added getstats.
-rw-r--r--FIX1
-rw-r--r--TODO5
-rw-r--r--src/buffer.c14
-rw-r--r--src/buffer.h3
-rw-r--r--src/tcp.c13
-rw-r--r--test/httptest.lua1
-rw-r--r--test/testclnt.lua1
7 files changed, 31 insertions, 7 deletions
diff --git a/FIX b/FIX
index c2b04e0..d126226 100644
--- a/FIX
+++ b/FIX
@@ -1,3 +1,4 @@
1added getstats to help throttle.
1setup error messages in the default case. 2setup error messages in the default case.
2listen defaults to 32 backlog 3listen defaults to 32 backlog
3smtp/ftp/http fail gracefully 4smtp/ftp/http fail gracefully
diff --git a/TODO b/TODO
index 9d736d0..6fa2914 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,3 @@
1create the getstats method.
2
3 sent, received, age = sock:getstats()
4 1
5take a look at DB's smtp patch 2take a look at DB's smtp patch
6 3
@@ -28,5 +25,7 @@ testar os options!
28 - inet_ntoa também é uma merda. 25 - inet_ntoa também é uma merda.
29 26
30 27
28create the getstats method.
29 sent, received, age = sock:getstats()
31*fix local domain socket kludge of name size 30*fix local domain socket kludge of name size
32*use TLS 31*use TLS
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;
diff --git a/src/buffer.h b/src/buffer.h
index 4b7563f..3ea2648 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -27,6 +27,8 @@
27 27
28/* buffer control structure */ 28/* buffer control structure */
29typedef struct t_buf_ { 29typedef struct t_buf_ {
30 double birthday; /* throttle support info: creation time, */
31 int sent, received; /* bytes sent, and bytes received */
30 p_io io; /* IO driver used for this buffer */ 32 p_io io; /* IO driver used for this buffer */
31 p_tm tm; /* timeout management for this buffer */ 33 p_tm tm; /* timeout management for this buffer */
32 size_t first, last; /* index of first and last bytes of stored data */ 34 size_t first, last; /* index of first and last bytes of stored data */
@@ -38,6 +40,7 @@ int buf_open(lua_State *L);
38void buf_init(p_buf buf, p_io io, p_tm tm); 40void buf_init(p_buf buf, p_io io, p_tm tm);
39int buf_meth_send(lua_State *L, p_buf buf); 41int buf_meth_send(lua_State *L, p_buf buf);
40int buf_meth_receive(lua_State *L, p_buf buf); 42int buf_meth_receive(lua_State *L, p_buf buf);
43int buf_meth_getstats(lua_State *L, p_buf buf);
41int buf_isempty(p_buf buf); 44int buf_isempty(p_buf buf);
42 45
43#endif /* BUF_H */ 46#endif /* BUF_H */
diff --git a/src/tcp.c b/src/tcp.c
index 037a23a..512f11b 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -23,6 +23,7 @@ static int meth_connect(lua_State *L);
23static int meth_listen(lua_State *L); 23static int meth_listen(lua_State *L);
24static int meth_bind(lua_State *L); 24static int meth_bind(lua_State *L);
25static int meth_send(lua_State *L); 25static int meth_send(lua_State *L);
26static int meth_getstats(lua_State *L);
26static int meth_getsockname(lua_State *L); 27static int meth_getsockname(lua_State *L);
27static int meth_getpeername(lua_State *L); 28static int meth_getpeername(lua_State *L);
28static int meth_shutdown(lua_State *L); 29static int meth_shutdown(lua_State *L);
@@ -47,6 +48,7 @@ static luaL_reg tcp[] = {
47 {"getfd", meth_getfd}, 48 {"getfd", meth_getfd},
48 {"getpeername", meth_getpeername}, 49 {"getpeername", meth_getpeername},
49 {"getsockname", meth_getsockname}, 50 {"getsockname", meth_getsockname},
51 {"getstats", meth_getstats},
50 {"listen", meth_listen}, 52 {"listen", meth_listen},
51 {"receive", meth_receive}, 53 {"receive", meth_receive},
52 {"send", meth_send}, 54 {"send", meth_send},
@@ -100,18 +102,21 @@ int tcp_open(lua_State *L)
100/*-------------------------------------------------------------------------*\ 102/*-------------------------------------------------------------------------*\
101* Just call buffered IO methods 103* Just call buffered IO methods
102\*-------------------------------------------------------------------------*/ 104\*-------------------------------------------------------------------------*/
103static int meth_send(lua_State *L) 105static int meth_send(lua_State *L) {
104{
105 p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{client}", 1); 106 p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{client}", 1);
106 return buf_meth_send(L, &tcp->buf); 107 return buf_meth_send(L, &tcp->buf);
107} 108}
108 109
109static int meth_receive(lua_State *L) 110static int meth_receive(lua_State *L) {
110{
111 p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{client}", 1); 111 p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{client}", 1);
112 return buf_meth_receive(L, &tcp->buf); 112 return buf_meth_receive(L, &tcp->buf);
113} 113}
114 114
115static int meth_getstats(lua_State *L) {
116 p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1);
117 return buf_meth_getstats(L, &tcp->buf);
118}
119
115/*-------------------------------------------------------------------------*\ 120/*-------------------------------------------------------------------------*\
116* Just call option handler 121* Just call option handler
117\*-------------------------------------------------------------------------*/ 122\*-------------------------------------------------------------------------*/
diff --git a/test/httptest.lua b/test/httptest.lua
index 3a4d461..8f94861 100644
--- a/test/httptest.lua
+++ b/test/httptest.lua
@@ -69,6 +69,7 @@ end
69io.write("testing request uri correctness: ") 69io.write("testing request uri correctness: ")
70local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" 70local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string"
71local back, c, h = http.request("http://" .. host .. forth) 71local back, c, h = http.request("http://" .. host .. forth)
72print(back, c, h)
72if not back then fail(c) end 73if not back then fail(c) end
73back = url.parse(back) 74back = url.parse(back)
74if similar(back.query, "this+is+the+query+string") then print("ok") 75if similar(back.query, "this+is+the+query+string") then print("ok")
diff --git a/test/testclnt.lua b/test/testclnt.lua
index 58a3574..38dc19a 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -448,6 +448,7 @@ test_methods(socket.tcp(), {
448 "getfd", 448 "getfd",
449 "getpeername", 449 "getpeername",
450 "getsockname", 450 "getsockname",
451 "getstats",
451 "listen", 452 "listen",
452 "receive", 453 "receive",
453 "send", 454 "send",