mirror of
https://github.com/nmap/nmap.git
synced 2026-11-20 08:40:36 +08:00
Add a function to check for EOF on socket
This commit is contained in:
@@ -50,6 +50,7 @@ typedef struct nse_nsock_udata
|
||||
{
|
||||
nsock_iod nsiod;
|
||||
int timeout;
|
||||
bool eof;
|
||||
|
||||
lua_State *thread;
|
||||
|
||||
@@ -656,11 +657,19 @@ static int l_sendto (lua_State *L)
|
||||
|
||||
}
|
||||
|
||||
static int l_eof (lua_State *L)
|
||||
{
|
||||
nse_nsock_udata *nu = check_nsock_udata(L, 1, false);
|
||||
lua_pushboolean(L, nu->eof);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void receive_callback (nsock_pool nsp, nsock_event nse, void *udata)
|
||||
{
|
||||
nse_nsock_udata *nu = (nse_nsock_udata *) udata;
|
||||
lua_State *L = nu->thread;
|
||||
assert(nse_type(nse) == NSE_TYPE_READ);
|
||||
nu->eof = nse_eof(nse);
|
||||
if (nse_status(nse) == NSE_STATUS_SUCCESS)
|
||||
{
|
||||
int len;
|
||||
@@ -1179,6 +1188,7 @@ LUALIB_API int luaopen_nsock (lua_State *L)
|
||||
{"receive_lines", l_receive_lines},
|
||||
{"reconnect_ssl", l_reconnect_ssl},
|
||||
{"set_timeout", l_set_timeout},
|
||||
{"eof", l_eof},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -657,6 +657,14 @@ function receive_buf(delimiter, keeppattern)
|
||||
-- @usage socket:close()
|
||||
function close()
|
||||
|
||||
--- Check whether the socket has seen EOF
|
||||
--
|
||||
-- @return Status (true or false).
|
||||
-- @return Error code (if status is false).
|
||||
-- @see new_socket
|
||||
-- @usage socket:eof()
|
||||
function eof()
|
||||
|
||||
--- Gets information about a socket.
|
||||
--
|
||||
-- This function returns information about a socket object. It returns five
|
||||
|
||||
Reference in New Issue
Block a user