aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/net/socket.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-08-24 20:47:59 +0800
committerchai <chaifix@163.com>2018-08-24 20:47:59 +0800
commitb52aa211c801a0cc15ed09553e3ff1835662b60b (patch)
tree58eddcc673a88f2d1912267bf6d26cd3565b32f7 /src/lua/modules/net/socket.cpp
parent106dfe48c40fdb24b7f5e8a84c992d15363a38d9 (diff)
*update
Diffstat (limited to 'src/lua/modules/net/socket.cpp')
-rw-r--r--src/lua/modules/net/socket.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/lua/modules/net/socket.cpp b/src/lua/modules/net/socket.cpp
index 6d3fdfb..ef6d4ac 100644
--- a/src/lua/modules/net/socket.cpp
+++ b/src/lua/modules/net/socket.cpp
@@ -12,9 +12,11 @@ namespace lua
using namespace jin::net;
using namespace lua::net;
+ typedef Ref<Socket>& SocketRef;
+
const int BUFFER_SIZE = 1024;
- static inline Ref<Socket>& checkSocket(lua_State* L, int pos = 1)
+ static inline SocketRef checkSocket(lua_State* L, int pos = 1)
{
Proxy* proxy = (Proxy*)luax_checktype(L, pos, JIN_NETWORK_SOCKET);
return proxy->getRef<Socket>();
@@ -29,7 +31,7 @@ namespace lua
// return net.Socket
static int l_accept(lua_State* L)
{
- Ref<Socket>& socket = checkSocket(L);
+ SocketRef socket = checkSocket(L);
Socket* client = socket->accept();
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy));
proxy->bind(new Ref<Socket>(client, JIN_NETWORK_SOCKET));
@@ -39,7 +41,7 @@ namespace lua
// return net.Buffer
static int l_receive(lua_State* L)
{
- Ref<Socket>& socket = checkSocket(L);
+ SocketRef socket = checkSocket(L);
char buffer[BUFFER_SIZE] = {0};
int size = socket->receive(buffer, BUFFER_SIZE);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
@@ -51,7 +53,7 @@ namespace lua
// Socket:receiveFrom(address, port)
static int l_receiveFrom(lua_State* L)
{
- Ref<Socket>& socket = checkSocket(L);
+ SocketRef socket = checkSocket(L);
int address = luax_checkinteger(L, 2);
int port = luax_checkinteger(L, 3);
char buffer[BUFFER_SIZE];
@@ -65,7 +67,7 @@ namespace lua
// Socket:send(net.Buffer) -> data_length
static int l_send(lua_State* L)
{
- Ref<Socket>& socket = checkSocket(L);
+ SocketRef socket = checkSocket(L);
Ref<Buffer>& ref = checkNetBuffer(L, 2);
int len = socket->send(ref->buffer, ref->size);
luax_pushinteger(L, len);
@@ -75,7 +77,7 @@ namespace lua
// Socket:sendTo(address, port, net.Buffer)
static int l_sendTo(lua_State* L)
{
- Ref<Socket>& socket = checkSocket(L);
+ SocketRef socket = checkSocket(L);
int address = luax_checkinteger(L, 2);
int port = luax_checkinteger(L, 3);
Ref<Buffer>& buffer = checkNetBuffer(L, 4);
@@ -85,14 +87,14 @@ namespace lua
static int l_close(lua_State* L)
{
- Ref<Socket>& socket = checkSocket(L);
+ SocketRef socket = checkSocket(L);
socket->close();
return 0;
}
static int l_configBlocking(lua_State* L)
{
- Ref<Socket>& socket = checkSocket(L);
+ SocketRef socket = checkSocket(L);
bool blocking = luax_checkbool(L, 2);
socket->configureBlocking(blocking);
return 0;