diff options
author | chai <chaifix@163.com> | 2018-08-14 09:26:22 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-08-14 09:26:22 +0800 |
commit | 5162f84be0a4deb447c6ba1226722b049335d525 (patch) | |
tree | 5f7ed0ddc05b1499eaf0607b88fd5cb5e2a961c1 /src/lua/net/luaopen_Socket.cpp | |
parent | 636e766791dc8680d237fafe4ff6dd904e16a860 (diff) |
*update
Diffstat (limited to 'src/lua/net/luaopen_Socket.cpp')
-rw-r--r-- | src/lua/net/luaopen_Socket.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/lua/net/luaopen_Socket.cpp b/src/lua/net/luaopen_Socket.cpp index 395729a..327cda1 100644 --- a/src/lua/net/luaopen_Socket.cpp +++ b/src/lua/net/luaopen_Socket.cpp @@ -2,13 +2,14 @@ #include "../luaopen_types.h" #include "libjin/jin.h" #include "lua_net_Buffer.h" +#include "lua_net_Socket.h" namespace jin { namespace lua { - - using namespace jin::net; + + using namespace jin::lua::net; const int BUFFER_SIZE = 1024; @@ -34,6 +35,7 @@ namespace lua Socket* socket = checkSocket(L); Socket* client = socket->accept(); Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy)); + client->retain(); proxy->bind(client, JIN_NETWORK_SOCKET); return 1; } @@ -46,6 +48,7 @@ namespace lua int size = socket->receive(buffer, BUFFER_SIZE); net::Buffer* netBuffer = new net::Buffer(buffer, size); Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy)); + netBuffer->retain(); proxy->bind(netBuffer, JIN_NETWORK_BUFFER); return 1; } @@ -60,6 +63,7 @@ namespace lua int size = socket->receiveFrom(buffer, BUFFER_SIZE, address, port); net::Buffer* netBuffer = new net::Buffer(buffer, size); Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy)); + netBuffer->retain(); proxy->bind(netBuffer, JIN_NETWORK_BUFFER); return 1; } @@ -100,7 +104,15 @@ namespace lua return 0; } + static int l_gc(lua_State* L) + { + Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_SOCKET); + proxy->release(); + return 0; + } + static const luaL_Reg socket_function[] = { + { "__gc", l_gc }, { "accept", l_accept }, { "receive", l_receive }, { "receiveFrom", l_receiveFrom }, |