lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,All,
There is a copas-test function:
local client
local co_socket
local function connect()
if client then client:close(); end
client=socket.tcp()
co_socket=copas.wrap(client)
co_socket:settimeout(10)
while true do
local ret,err=copas.connect(client,'127.0.0.1',12345)
print(ret,err)
if ret then break;end
end
end

If the server is not ready first , the copas will block lua vm at copas.connect and forever.
I added some prints  to connect function:

-- waits until connection is completed
function connect(skt,host, port)
       skt:settimeout(0)
       local ret,err = skt:connect (host, port)
  if err=='timeout' then print('connect timeout.'); end
       if ret or err ~= "timeout" then
 print'ret'
    return ret, err
  end
   _writing_log[skt] = os.time()
       coroutine.yield(skt, _writing)
  print'try connect'
       ret,err = skt:connect (host, port)
   _writing_log[skt] = nil
       if (err=="already connected") then
               return 1
       end
       return ret, err
end

the output is :
connect timeout.

Why?
Is it a copas bug?
Thanks.

--
Regards,
Linker Lin
linker.m.lin@gmail.com