mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 03:53:09 +00:00
add socket.netstat
This commit is contained in:
@@ -680,6 +680,70 @@ ludp_address(lua_State *L) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
static void
|
||||
getinfo(lua_State *L, struct socket_info *si) {
|
||||
lua_newtable(L);
|
||||
lua_pushinteger(L, si->id);
|
||||
lua_setfield(L, -2, "id");
|
||||
lua_pushinteger(L, si->opaque);
|
||||
lua_setfield(L, -2, "address");
|
||||
switch(si->type) {
|
||||
case SOCKET_INFO_LISTEN:
|
||||
lua_pushstring(L, "LISTEN");
|
||||
lua_setfield(L, -2, "type");
|
||||
lua_pushinteger(L, si->read);
|
||||
lua_setfield(L, -2, "accept");
|
||||
if (si->name[0]) {
|
||||
lua_pushstring(L, si->name);
|
||||
lua_setfield(L, -2, "sock");
|
||||
}
|
||||
return;
|
||||
case SOCKET_INFO_TCP:
|
||||
lua_pushstring(L, "TCP");
|
||||
break;
|
||||
case SOCKET_INFO_UDP:
|
||||
lua_pushstring(L, "UDP");
|
||||
break;
|
||||
case SOCKET_INFO_BIND:
|
||||
lua_pushstring(L, "BIND");
|
||||
break;
|
||||
default:
|
||||
lua_pushstring(L, "UNKNOWN");
|
||||
lua_setfield(L, -2, "type");
|
||||
return;
|
||||
}
|
||||
lua_setfield(L, -2, "type");
|
||||
lua_pushinteger(L, si->read);
|
||||
lua_setfield(L, -2, "read");
|
||||
lua_pushinteger(L, si->write);
|
||||
lua_setfield(L, -2, "write");
|
||||
lua_pushinteger(L, si->wbuffer);
|
||||
lua_setfield(L, -2, "wbuffer");
|
||||
lua_pushinteger(L, si->rtime);
|
||||
lua_setfield(L, -2, "rtime");
|
||||
lua_pushinteger(L, si->wtime);
|
||||
lua_setfield(L, -2, "wtime");
|
||||
if (si->name[0]) {
|
||||
lua_pushstring(L, si->name);
|
||||
lua_setfield(L, -2, "peer");
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
linfo(lua_State *L) {
|
||||
lua_newtable(L);
|
||||
struct socket_info * si = skynet_socket_info();
|
||||
struct socket_info * temp = si;
|
||||
int n = 0;
|
||||
while (temp) {
|
||||
getinfo(L, temp);
|
||||
lua_seti(L, -2, ++n);
|
||||
temp = temp->next;
|
||||
}
|
||||
socket_info_release(si);
|
||||
return 1;
|
||||
}
|
||||
|
||||
LUAMOD_API int
|
||||
luaopen_skynet_socketdriver(lua_State *L) {
|
||||
luaL_checkversion(L);
|
||||
@@ -693,6 +757,7 @@ luaopen_skynet_socketdriver(lua_State *L) {
|
||||
{ "readline", lreadline },
|
||||
{ "str2p", lstr2p },
|
||||
{ "header", lheader },
|
||||
{ "info", linfo },
|
||||
|
||||
{ "unpack", lunpack },
|
||||
{ NULL, NULL },
|
||||
|
||||
Reference in New Issue
Block a user