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
means 'read', and
means 'write'.
Please, tell me where I'm wrong.
Is there any way to close connection that is in 'reading' state?