cosocket read interrupt

43 views
Skip to first unread message

Sergey Shevchik

unread,
Dec 20, 2018, 2:34:42 PM12/20/18
to openresty-en
I have cosocket created in timer context and connected to some server, and thread that call receive() in loop, reading data from server and processing it.

while true do
    local data, err = sock:receive(size)
    while err == 'timeout' do
        data, err = sock:receive(size)
    end
    -- process data and continue reading from socket
end

(read restarted in case of timeout error)

At some point I want to cancel waiting data from server (for example when nginx is in exiting state) and close connection, however I don't know how to do this.
I tried to close socket from other thread (spawned from the same context as reading thread), but get 'socket busy reading' error.

I thought that it is possible to read and write to the same cosocket object from different threads, and my understanding is that
receive()

means 'read', and
close()

means 'write'.

Please, tell me where I'm wrong.
Is there any way to close connection that is in 'reading' state?


tokers

unread,
Dec 24, 2018, 12:40:00 AM12/24/18
to openresty-en
Hello!

> Is there any way to close connection that is in 'reading' state?

No. As per current design, there is no way to cancel the reading state,
except the read timed out or the connection abort.
Reply all
Reply to author
Forward
0 new messages