add socket:available() --> int
This commit is contained in:
parent
e94b70fd3a
commit
13de581b4b
@ -54,6 +54,9 @@ socket:recv(
|
|||||||
-- Closes the connection
|
-- Closes the connection
|
||||||
socket:close()
|
socket:close()
|
||||||
|
|
||||||
|
-- Returns the number of data bytes available for reading
|
||||||
|
socket:available() --> int
|
||||||
|
|
||||||
-- Checks that the socket exists and is not closed.
|
-- Checks that the socket exists and is not closed.
|
||||||
socket:is_alive() --> bool
|
socket:is_alive() --> bool
|
||||||
|
|
||||||
|
|||||||
@ -54,6 +54,9 @@ socket:recv(
|
|||||||
-- Закрывает соединение
|
-- Закрывает соединение
|
||||||
socket:close()
|
socket:close()
|
||||||
|
|
||||||
|
-- Возвращает количество доступных для чтения байт данных
|
||||||
|
socket:available() --> int
|
||||||
|
|
||||||
-- Проверяет, что сокет существует и не закрыт.
|
-- Проверяет, что сокет существует и не закрыт.
|
||||||
socket:is_alive() --> bool
|
socket:is_alive() --> bool
|
||||||
|
|
||||||
|
|||||||
@ -40,6 +40,7 @@ local Socket = {__index={
|
|||||||
send=function(self, ...) return network.__send(self.id, ...) end,
|
send=function(self, ...) return network.__send(self.id, ...) end,
|
||||||
recv=function(self, ...) return network.__recv(self.id, ...) end,
|
recv=function(self, ...) return network.__recv(self.id, ...) end,
|
||||||
close=function(self) return network.__close(self.id) end,
|
close=function(self) return network.__close(self.id) end,
|
||||||
|
available=function(self) return network.__available(self.id) or 0 end,
|
||||||
is_alive=function(self) return network.__is_alive(self.id) end,
|
is_alive=function(self) return network.__is_alive(self.id) end,
|
||||||
is_connected=function(self) return network.__is_connected(self.id) end,
|
is_connected=function(self) return network.__is_connected(self.id) end,
|
||||||
get_address=function(self) return network.__get_address(self.id) end,
|
get_address=function(self) return network.__get_address(self.id) end,
|
||||||
|
|||||||
@ -424,6 +424,7 @@ function __vc_resume_coroutine(id)
|
|||||||
if co then
|
if co then
|
||||||
coroutine.resume(co)
|
coroutine.resume(co)
|
||||||
if __vc_coroutine_error then
|
if __vc_coroutine_error then
|
||||||
|
debug.error(__vc_coroutine_error)
|
||||||
error(__vc_coroutine_error)
|
error(__vc_coroutine_error)
|
||||||
end
|
end
|
||||||
return coroutine.status(co) ~= "dead"
|
return coroutine.status(co) ~= "dead"
|
||||||
|
|||||||
@ -123,6 +123,14 @@ static int l_recv(lua::State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_available(lua::State* L) {
|
||||||
|
u64id_t id = lua::tointeger(L, 1);
|
||||||
|
if (auto connection = engine->getNetwork().getConnection(id)) {
|
||||||
|
return lua::pushinteger(L, connection->available());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_open(lua::State* L) {
|
static int l_open(lua::State* L) {
|
||||||
int port = lua::tointeger(L, 1);
|
int port = lua::tointeger(L, 1);
|
||||||
lua::pushvalue(L, 2);
|
lua::pushvalue(L, 2);
|
||||||
@ -200,6 +208,7 @@ const luaL_Reg networklib[] = {
|
|||||||
{"__close", lua::wrap<l_close>},
|
{"__close", lua::wrap<l_close>},
|
||||||
{"__send", lua::wrap<l_send>},
|
{"__send", lua::wrap<l_send>},
|
||||||
{"__recv", lua::wrap<l_recv>},
|
{"__recv", lua::wrap<l_recv>},
|
||||||
|
{"__available", lua::wrap<l_available>},
|
||||||
{"__is_alive", lua::wrap<l_is_alive>},
|
{"__is_alive", lua::wrap<l_is_alive>},
|
||||||
{"__is_connected", lua::wrap<l_is_connected>},
|
{"__is_connected", lua::wrap<l_is_connected>},
|
||||||
{"__get_address", lua::wrap<l_get_address>},
|
{"__get_address", lua::wrap<l_get_address>},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user