mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-26 20:38:22 +01:00
Added getstats.
This commit is contained in:
parent
2562738e2d
commit
63807d6476
1
FIX
1
FIX
@ -1,3 +1,4 @@
|
|||||||
|
added getstats to help throttle.
|
||||||
setup error messages in the default case.
|
setup error messages in the default case.
|
||||||
listen defaults to 32 backlog
|
listen defaults to 32 backlog
|
||||||
smtp/ftp/http fail gracefully
|
smtp/ftp/http fail gracefully
|
||||||
|
5
TODO
5
TODO
@ -1,6 +1,3 @@
|
|||||||
create the getstats method.
|
|
||||||
|
|
||||||
sent, received, age = sock:getstats()
|
|
||||||
|
|
||||||
take a look at DB's smtp patch
|
take a look at DB's smtp patch
|
||||||
|
|
||||||
@ -28,5 +25,7 @@ testar os options!
|
|||||||
- inet_ntoa também é uma merda.
|
- inet_ntoa também é uma merda.
|
||||||
|
|
||||||
|
|
||||||
|
create the getstats method.
|
||||||
|
sent, received, age = sock:getstats()
|
||||||
*fix local domain socket kludge of name size
|
*fix local domain socket kludge of name size
|
||||||
*use TLS
|
*use TLS
|
||||||
|
14
src/buffer.c
14
src/buffer.c
@ -45,6 +45,18 @@ void buf_init(p_buf buf, p_io io, p_tm tm) {
|
|||||||
buf->first = buf->last = 0;
|
buf->first = buf->last = 0;
|
||||||
buf->io = io;
|
buf->io = io;
|
||||||
buf->tm = tm;
|
buf->tm = tm;
|
||||||
|
buf->received = buf->sent = 0;
|
||||||
|
buf->birthday = tm_gettime();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------*\
|
||||||
|
* object:getstats() interface
|
||||||
|
\*-------------------------------------------------------------------------*/
|
||||||
|
int buf_meth_getstats(lua_State *L, p_buf buf) {
|
||||||
|
lua_pushnumber(L, buf->received);
|
||||||
|
lua_pushnumber(L, buf->sent);
|
||||||
|
lua_pushnumber(L, tm_gettime() - buf->birthday);
|
||||||
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
@ -141,6 +153,7 @@ static int sendraw(p_buf buf, const char *data, size_t count, size_t *sent) {
|
|||||||
total += done;
|
total += done;
|
||||||
}
|
}
|
||||||
*sent = total;
|
*sent = total;
|
||||||
|
buf->sent += total;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,6 +218,7 @@ static int recvline(p_buf buf, luaL_Buffer *b) {
|
|||||||
* transport layer
|
* transport layer
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
static void buf_skip(p_buf buf, size_t count) {
|
static void buf_skip(p_buf buf, size_t count) {
|
||||||
|
buf->received += count;
|
||||||
buf->first += count;
|
buf->first += count;
|
||||||
if (buf_isempty(buf))
|
if (buf_isempty(buf))
|
||||||
buf->first = buf->last = 0;
|
buf->first = buf->last = 0;
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
/* buffer control structure */
|
/* buffer control structure */
|
||||||
typedef struct t_buf_ {
|
typedef struct t_buf_ {
|
||||||
|
double birthday; /* throttle support info: creation time, */
|
||||||
|
int sent, received; /* bytes sent, and bytes received */
|
||||||
p_io io; /* IO driver used for this buffer */
|
p_io io; /* IO driver used for this buffer */
|
||||||
p_tm tm; /* timeout management for this buffer */
|
p_tm tm; /* timeout management for this buffer */
|
||||||
size_t first, last; /* index of first and last bytes of stored data */
|
size_t first, last; /* index of first and last bytes of stored data */
|
||||||
@ -38,6 +40,7 @@ int buf_open(lua_State *L);
|
|||||||
void buf_init(p_buf buf, p_io io, p_tm tm);
|
void buf_init(p_buf buf, p_io io, p_tm tm);
|
||||||
int buf_meth_send(lua_State *L, p_buf buf);
|
int buf_meth_send(lua_State *L, p_buf buf);
|
||||||
int buf_meth_receive(lua_State *L, p_buf buf);
|
int buf_meth_receive(lua_State *L, p_buf buf);
|
||||||
|
int buf_meth_getstats(lua_State *L, p_buf buf);
|
||||||
int buf_isempty(p_buf buf);
|
int buf_isempty(p_buf buf);
|
||||||
|
|
||||||
#endif /* BUF_H */
|
#endif /* BUF_H */
|
||||||
|
13
src/tcp.c
13
src/tcp.c
@ -23,6 +23,7 @@ static int meth_connect(lua_State *L);
|
|||||||
static int meth_listen(lua_State *L);
|
static int meth_listen(lua_State *L);
|
||||||
static int meth_bind(lua_State *L);
|
static int meth_bind(lua_State *L);
|
||||||
static int meth_send(lua_State *L);
|
static int meth_send(lua_State *L);
|
||||||
|
static int meth_getstats(lua_State *L);
|
||||||
static int meth_getsockname(lua_State *L);
|
static int meth_getsockname(lua_State *L);
|
||||||
static int meth_getpeername(lua_State *L);
|
static int meth_getpeername(lua_State *L);
|
||||||
static int meth_shutdown(lua_State *L);
|
static int meth_shutdown(lua_State *L);
|
||||||
@ -47,6 +48,7 @@ static luaL_reg tcp[] = {
|
|||||||
{"getfd", meth_getfd},
|
{"getfd", meth_getfd},
|
||||||
{"getpeername", meth_getpeername},
|
{"getpeername", meth_getpeername},
|
||||||
{"getsockname", meth_getsockname},
|
{"getsockname", meth_getsockname},
|
||||||
|
{"getstats", meth_getstats},
|
||||||
{"listen", meth_listen},
|
{"listen", meth_listen},
|
||||||
{"receive", meth_receive},
|
{"receive", meth_receive},
|
||||||
{"send", meth_send},
|
{"send", meth_send},
|
||||||
@ -100,18 +102,21 @@ int tcp_open(lua_State *L)
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Just call buffered IO methods
|
* Just call buffered IO methods
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
static int meth_send(lua_State *L)
|
static int meth_send(lua_State *L) {
|
||||||
{
|
|
||||||
p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{client}", 1);
|
p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{client}", 1);
|
||||||
return buf_meth_send(L, &tcp->buf);
|
return buf_meth_send(L, &tcp->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int meth_receive(lua_State *L)
|
static int meth_receive(lua_State *L) {
|
||||||
{
|
|
||||||
p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{client}", 1);
|
p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{client}", 1);
|
||||||
return buf_meth_receive(L, &tcp->buf);
|
return buf_meth_receive(L, &tcp->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int meth_getstats(lua_State *L) {
|
||||||
|
p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1);
|
||||||
|
return buf_meth_getstats(L, &tcp->buf);
|
||||||
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Just call option handler
|
* Just call option handler
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
|
@ -69,6 +69,7 @@ end
|
|||||||
io.write("testing request uri correctness: ")
|
io.write("testing request uri correctness: ")
|
||||||
local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string"
|
local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string"
|
||||||
local back, c, h = http.request("http://" .. host .. forth)
|
local back, c, h = http.request("http://" .. host .. forth)
|
||||||
|
print(back, c, h)
|
||||||
if not back then fail(c) end
|
if not back then fail(c) end
|
||||||
back = url.parse(back)
|
back = url.parse(back)
|
||||||
if similar(back.query, "this+is+the+query+string") then print("ok")
|
if similar(back.query, "this+is+the+query+string") then print("ok")
|
||||||
|
@ -448,6 +448,7 @@ test_methods(socket.tcp(), {
|
|||||||
"getfd",
|
"getfd",
|
||||||
"getpeername",
|
"getpeername",
|
||||||
"getsockname",
|
"getsockname",
|
||||||
|
"getstats",
|
||||||
"listen",
|
"listen",
|
||||||
"receive",
|
"receive",
|
||||||
"send",
|
"send",
|
||||||
|
Loading…
Reference in New Issue
Block a user