Skip to content

Commit a37fecf

Browse files
authored
allow quick restart in Linux (actboy168#317)
1 parent 35b2912 commit a37fecf

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

extension/script/common/net.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ function m.listen(protocol, address, port)
176176
fs.remove(address)
177177
end
178178
end
179+
do
180+
-- set SO_REUSEADDR so we can bind again to the same address
181+
-- after a quick restart:
182+
local ok, err = fd:option("reuseaddr", 1)
183+
if not ok then
184+
fd:close()
185+
return nil, err
186+
end
187+
end
179188
do
180189
local ok, err = fd:bind(address, port)
181190
if not ok then

extension/script/common/socket.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ return function (param)
119119
session:close()
120120
fds[1] = session
121121
elseif t.mode == "listen" then
122-
server:close()
123-
fds[1] = server
124-
if session ~= nil then
125-
session:close()
126-
fds[2] = session
127-
end
122+
fds[1] = server
123+
if session ~= nil then
124+
session:close()
125+
fds[2] = session
126+
end
127+
server:close()
128128
end
129129
local function is_finish()
130130
for _, fd in ipairs(fds) do

0 commit comments

Comments
 (0)