记录使用luarocks cqueues时碰到的一些问题:
1.
2. cqueues socket 实现 I/O多路复用
function myfunc()
local cqueues = require("cqueues").new()
local server = require("cqueues.socket").listen({
host = "0.0.0.0",
port = "3456",
reuseaddr = true,
reuseport = true
})
local con = cqueues:wrap(function()
for cli in server:clients() do
print(cli:peername())
local cq = require("cqueues").new()
cqueues:wrap(function()
cq:loop()
end)
cq:wrap(function()
local buf=""
repeat
buf = cli:read()
local host, port = select(2, cli:peername())
print("recv from "..host..":"..port.." buf = ",buf)
until #buf == 0
end)
end
end)
assert(cqueues:loop())
end