mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
fix half close issue, #1358
This commit is contained in:
@@ -12,6 +12,9 @@ local CMD = setmetatable({}, { __gc = function() netpack.clear(queue) end })
|
|||||||
local nodelay = false
|
local nodelay = false
|
||||||
|
|
||||||
local connection = {}
|
local connection = {}
|
||||||
|
-- true : connected
|
||||||
|
-- nil : closed
|
||||||
|
-- false : close read
|
||||||
|
|
||||||
function gateserver.openclient(fd)
|
function gateserver.openclient(fd)
|
||||||
if connection[fd] then
|
if connection[fd] then
|
||||||
@@ -21,8 +24,8 @@ end
|
|||||||
|
|
||||||
function gateserver.closeclient(fd)
|
function gateserver.closeclient(fd)
|
||||||
local c = connection[fd]
|
local c = connection[fd]
|
||||||
if c then
|
if c ~= nil then
|
||||||
connection[fd] = false
|
connection[fd] = nil
|
||||||
socketdriver.close(fd)
|
socketdriver.close(fd)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -80,7 +83,7 @@ function gateserver.start(handler)
|
|||||||
|
|
||||||
function MSG.open(fd, msg)
|
function MSG.open(fd, msg)
|
||||||
if client_number >= maxclient then
|
if client_number >= maxclient then
|
||||||
socketdriver.close(fd)
|
socketdriver.shutdown(fd)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if nodelay then
|
if nodelay then
|
||||||
@@ -91,20 +94,17 @@ function gateserver.start(handler)
|
|||||||
handler.connect(fd, msg)
|
handler.connect(fd, msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function close_fd(fd)
|
|
||||||
local c = connection[fd]
|
|
||||||
if c ~= nil then
|
|
||||||
connection[fd] = nil
|
|
||||||
client_number = client_number - 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function MSG.close(fd)
|
function MSG.close(fd)
|
||||||
if fd ~= socket then
|
if fd ~= socket then
|
||||||
|
client_number = client_number - 1
|
||||||
|
if connection[fd] then
|
||||||
|
connection[fd] = false -- close read
|
||||||
|
end
|
||||||
if handler.disconnect then
|
if handler.disconnect then
|
||||||
handler.disconnect(fd)
|
handler.disconnect(fd)
|
||||||
|
else
|
||||||
|
socketdriver.close(fd)
|
||||||
end
|
end
|
||||||
close_fd(fd)
|
|
||||||
else
|
else
|
||||||
socket = nil
|
socket = nil
|
||||||
end
|
end
|
||||||
@@ -114,10 +114,10 @@ function gateserver.start(handler)
|
|||||||
if fd == socket then
|
if fd == socket then
|
||||||
skynet.error("gateserver accpet error:",msg)
|
skynet.error("gateserver accpet error:",msg)
|
||||||
else
|
else
|
||||||
|
socketdriver.shutdown(fd)
|
||||||
if handler.error then
|
if handler.error then
|
||||||
handler.error(fd, msg)
|
handler.error(fd, msg)
|
||||||
end
|
end
|
||||||
close_fd(fd)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user