local action = "">
table.insert(action, {socket , tcpsock.receive, 1024})
table.insert(action, {socket2, tcpsock.receive, 1024})
table.insert(action, {socket3, tcpsock.receive, 1024})
while true do
local res, err = tcpsock.poller(action, time_out)
if res then
if res.event == tcpsock.receive then
ngx.say("action event :", "read")
end
ngx.say("action index :", res.index)
ngx.say("action socket:", res.socket)
ngx.say("action data :", res.data)
-- ... do something
table.remove(action, res.index)
elseif err
ngx.say(err)
end
end
--------日志
action event :read -- its can be read, recv and timeout result.
action index :2
action socket:0024B3E0
action data :"hello the world"
------------------------------------------------------------说明
接口目的:
如何完成在一个lua thread完成对多个socket的同时控制,解决1:N的网络模型。
(HTTP协议都是1:1模型的,在多路复用实现上还不够强大)大家集思广益,
看看是否有更好、易懂的API接口表达或解决办法。
不想直接在nginx上开发模块,难度高、容易错,并且不具有通用性。想基于
openresty lua tcp,做个纯lua的版本。知道目前tcpsock在单线程中控制多
个socket还不够完善,所以打算首先扩充一下openresty的tcp实现。这样后期
的定制开发就会方便很多。