watchdog returns addr,port

This commit is contained in:
Cloud Wu
2022-09-04 14:22:13 +08:00
parent 01314de8e1
commit b61daaccf1
5 changed files with 33 additions and 6 deletions

View File

@@ -34,6 +34,8 @@ function gateserver.start(handler)
assert(handler.message)
assert(handler.connect)
local listen_context = {}
function CMD.open( source, conf )
assert(not socket)
local address = conf.address or "0.0.0.0"
@@ -42,6 +44,12 @@ function gateserver.start(handler)
nodelay = conf.nodelay
skynet.error(string.format("Listen on %s:%d", address, port))
socket = socketdriver.listen(address, port)
listen_context.co = coroutine.running()
listen_context.fd = socket
skynet.wait(listen_context.co)
conf.address = listen_context.addr
conf.port = listen_context.port
listen_context = nil
socketdriver.start(socket)
if handler.open then
return handler.open(source, conf)
@@ -125,6 +133,19 @@ function gateserver.start(handler)
end
end
function MSG.init(id, addr, port)
if listen_context then
local co = listen_context.co
if co then
assert(id == listen_context.fd)
listen_context.addr = addr
listen_context.port = port
skynet.wakeup(co)
listen_context.co = nil
end
end
end
skynet.register_protocol {
name = "socket",
id = skynet.PTYPE_SOCKET, -- PTYPE_SOCKET = 6