mirror of
https://github.com/nmap/nmap.git
synced 2026-11-29 19:10:31 +00:00
Simplify pcall to avoid creating closures
This commit is contained in:
parent
843b78e694
commit
7755daa0f1
2 changed files with 14 additions and 11 deletions
|
|
@ -1074,7 +1074,7 @@ end
|
|||
-- @param sock Connected Nmap socket (TLS)
|
||||
-- @return certificate table (see nmap sslcert), or nil
|
||||
function get_cert(sock)
|
||||
local ok, cert = pcall(function() return sock:get_ssl_certificate() end)
|
||||
local ok, cert = pcall(sock.get_ssl_certificate, sock)
|
||||
if ok then return cert end
|
||||
return nil
|
||||
end
|
||||
|
|
@ -1482,7 +1482,7 @@ function do_release(sock, timeout_s)
|
|||
PDU_CODES.RELEASE_REQUEST, 0x00, 0x04, 0x00000000)
|
||||
sock:set_timeout((timeout_s or 3) * 1000)
|
||||
tcp_send(sock, rel_rq)
|
||||
pcall(function() sock:receive() end)
|
||||
pcall(sock.receive, sock)
|
||||
sock:close()
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -202,11 +202,12 @@ end
|
|||
local function count_alive(socks)
|
||||
local alive = 0
|
||||
for i = 1, #socks do
|
||||
if socks[i] then
|
||||
if sock_alive(socks[i]) then
|
||||
local sock = socks[i]
|
||||
if sock then
|
||||
if sock_alive(sock) then
|
||||
alive = alive + 1
|
||||
else
|
||||
pcall(function() socks[i]:close() end)
|
||||
pcall(sock.close, sock)
|
||||
socks[i] = false
|
||||
end
|
||||
end
|
||||
|
|
@ -390,11 +391,12 @@ action = function(host, port)
|
|||
while elapsed < hold_time do
|
||||
if mode == "echo" and elapsed >= next_echo then
|
||||
for i = 1, #socks do
|
||||
if socks[i] then
|
||||
local sock = socks[i]
|
||||
if sock then
|
||||
echoes = echoes + 1
|
||||
if not keepalive(socks[i], pctxs[i], echoes, max_pdu, timeout_s)
|
||||
if not keepalive(sock, pctxs[i], echoes, max_pdu, timeout_s)
|
||||
then
|
||||
pcall(function() socks[i]:close() end)
|
||||
pcall(sock.close, sock)
|
||||
socks[i] = false
|
||||
drops = drops + 1
|
||||
end
|
||||
|
|
@ -425,11 +427,12 @@ action = function(host, port)
|
|||
-- Phase 3: release and measure recovery.
|
||||
local released = 0
|
||||
for i = 1, #socks do
|
||||
if socks[i] then
|
||||
local sock = socks[i]
|
||||
if sock then
|
||||
if mode == "partial" then
|
||||
pcall(function() socks[i]:close() end)
|
||||
pcall(sock.close, sock)
|
||||
else
|
||||
pcall(function() dicom.do_release(socks[i], 2) end)
|
||||
pcall(dicom.do_release, sock, 2)
|
||||
end
|
||||
released = released + 1
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue