Open zzh442856860 opened 7 years ago
例如这样
function http_client.new(eventLoop,host,fd) if not eventLoop then return nil,"eventLoop is nil" end
local o = {}
o.__index = http_client
setmetatable(o,o)
o.conn = chuck.http.Connection(fd,http_response_max_header_size,http_response_max_content_length)
if not o.conn then
return nil,"call http.Connection() failed"
end
o.host = host
o.pendingResponse = {}
local ret = o.conn:Start(eventLoop,function (httpPacket)
if o.timer then o.timer:UnRegister() o.timer = nil end
if not httpPacket then
if o.pendingResponse then
o.pendingResponse(nil,"connection lose") --通告对端关闭
end
o.conn:Close()
o.conn = nil
return
end
if not o.pendingResponse then
--没有请求
return
end
local response = http_packet_readonly.new(httpPacket)
local OnResponse = o.pendingResponse
o.pendingResponse = nil
OnResponse(response)
end)
if ret then return nil,"call Bind() failed" end
o.timer = eventLoop:AddTimer(30,function ()
local OnResponse = o.pendingResponse
if OnResponse then
o.pendingResponse = nil
OnResponse(nil,"timeout")
end
o.timer = nil
return -1
end)
return o end
我现在的gameserver,里面有一个tcpserver,一个httpserver,一个redisclient,三个公用一个event_loop
那么minilumen/sched.lua代码 里面用的event_loop是new了一个。这个是 需要改成上面 公用的那个event_loop吗??