大家好:
ngx.req.socket获取到客户端的socket后,我想在两个协程里面分别处理这个socket的读和写。
几经尝试后都失败了。是我的使用方法有问题,还是bug?
============================================版本
openresty版本:1.7.0.1、1.5.12.1 均有问题
系统centos 64bit
============================================代码
local tcpsock = ngx.req.socket(true)
-- thread work for response
local function do_response()
for i=1,10,0 do
ngx.sleep(0.1)
tcpsock:send("hello")
ngx.log(ngx.NOTICE, "send complete:", "hello")
end
end
ngx.thread.spawn(do_response)
-- main thread working for receive
for i=1,10,0 do
local req_data = tcpsock:receive()
if req_data then
ngx.log(ngx.NOTICE, "recv data", req_data)
end
end
============================================日志
nginx 日志输出:
2014/06/19 16:21:50 [notice] 14685#0: *1 [lua] req_socket.lua:8: send complete:hello, client: 172.22.31.52, server: localhost, request: "GET /req_socket HTTP/1.1", host: "172.22.31.53:9600"
2014/06/19 16:21:50 [notice] 14685#0: *1 [lua] req_socket.lua:8: send complete:hello, client: 172.22.31.52, server: localhost, request: "GET /req_socket HTTP/1.1", host: "172.22.31.53:9600"
2014/06/19 16:21:50 [notice] 14685#0: *1 [lua] req_socket.lua:8: send complete:hello, client: 172.22.31.52, server: localhost, request: "GET /req_socket HTTP/1.1", host: "172.22.31.53:9600"
2014/06/19 16:21:51 [notice] 14685#0: *1 [lua] req_socket.lua:8: send complete:hello, client: 172.22.31.52, server: localhost, request: "GET /req_socket HTTP/1.1", host: "172.22.31.53:9600"
2014/06/19 16:21:51 [notice] 14685#0: *1 [lua] req_socket.lua:8: send complete:hello, client: 172.22.31.52, server: localhost, request: "GET /req_socket HTTP/1.1", host: "172.22.31.53:9600"