diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-01 06:09:29 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-01 06:09:29 +0000 |
| commit | 63807d647624df155a81a2b323f370e2c36192f6 (patch) | |
| tree | 28d53540d166cc01eb0a3302e4f0dc5d2cc6c809 | |
| parent | 2562738e2db9d7654c48c10247e683215e09b4a5 (diff) | |
| download | luasocket-63807d647624df155a81a2b323f370e2c36192f6.tar.gz luasocket-63807d647624df155a81a2b323f370e2c36192f6.tar.bz2 luasocket-63807d647624df155a81a2b323f370e2c36192f6.zip | |
Added getstats.
| -rw-r--r-- | FIX | 1 | ||||
| -rw-r--r-- | TODO | 5 | ||||
| -rw-r--r-- | src/buffer.c | 14 | ||||
| -rw-r--r-- | src/buffer.h | 3 | ||||
| -rw-r--r-- | src/tcp.c | 13 | ||||
| -rw-r--r-- | test/httptest.lua | 1 | ||||
| -rw-r--r-- | test/testclnt.lua | 1 |
7 files changed, 31 insertions, 7 deletions
| @@ -1,3 +1,4 @@ | |||
| 1 | added getstats to help throttle. | ||
| 1 | setup error messages in the default case. | 2 | setup error messages in the default case. |
| 2 | listen defaults to 32 backlog | 3 | listen defaults to 32 backlog |
| 3 | smtp/ftp/http fail gracefully | 4 | smtp/ftp/http fail gracefully |
| @@ -1,6 +1,3 @@ | |||
| 1 | create the getstats method. | ||
| 2 | |||
| 3 | sent, received, age = sock:getstats() | ||
| 4 | 1 | ||
| 5 | take a look at DB's smtp patch | 2 | take 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 | ||
| 28 | create 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 | \*-------------------------------------------------------------------------*/ | ||
| 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; |
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 */ |
| 29 | typedef struct t_buf_ { | 29 | typedef 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); | |||
| 38 | void buf_init(p_buf buf, p_io io, p_tm tm); | 40 | void buf_init(p_buf buf, p_io io, p_tm tm); |
| 39 | int buf_meth_send(lua_State *L, p_buf buf); | 41 | int buf_meth_send(lua_State *L, p_buf buf); |
| 40 | int buf_meth_receive(lua_State *L, p_buf buf); | 42 | int buf_meth_receive(lua_State *L, p_buf buf); |
| 43 | int buf_meth_getstats(lua_State *L, p_buf buf); | ||
| 41 | int buf_isempty(p_buf buf); | 44 | int buf_isempty(p_buf buf); |
| 42 | 45 | ||
| 43 | #endif /* BUF_H */ | 46 | #endif /* BUF_H */ |
| @@ -23,6 +23,7 @@ static int meth_connect(lua_State *L); | |||
| 23 | static int meth_listen(lua_State *L); | 23 | static int meth_listen(lua_State *L); |
| 24 | static int meth_bind(lua_State *L); | 24 | static int meth_bind(lua_State *L); |
| 25 | static int meth_send(lua_State *L); | 25 | static int meth_send(lua_State *L); |
| 26 | static int meth_getstats(lua_State *L); | ||
| 26 | static int meth_getsockname(lua_State *L); | 27 | static int meth_getsockname(lua_State *L); |
| 27 | static int meth_getpeername(lua_State *L); | 28 | static int meth_getpeername(lua_State *L); |
| 28 | static int meth_shutdown(lua_State *L); | 29 | static 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 | \*-------------------------------------------------------------------------*/ |
| 103 | static int meth_send(lua_State *L) | 105 | static 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 | ||
| 109 | static int meth_receive(lua_State *L) | 110 | static 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 | ||
| 115 | static 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 | |||
| 69 | io.write("testing request uri correctness: ") | 69 | io.write("testing request uri correctness: ") |
| 70 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" | 70 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" |
| 71 | local back, c, h = http.request("http://" .. host .. forth) | 71 | local back, c, h = http.request("http://" .. host .. forth) |
| 72 | print(back, c, h) | ||
| 72 | if not back then fail(c) end | 73 | if not back then fail(c) end |
| 73 | back = url.parse(back) | 74 | back = url.parse(back) |
| 74 | if similar(back.query, "this+is+the+query+string") then print("ok") | 75 | if 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", |
