mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
watchdog returns addr,port
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user