lua-users home
lua-l archive

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



> Date: Thu, 15 Oct 2009 11:55:36 -0700
> Subject: Re: Using LuaSocket with non-blocking sockets
> From: vieuxtech@gmail.com
> To: lua@bazar2.conectiva.com.br
>
> > The WinSock page in this case
> > (http://msdn.microsoft.com/en-us/library/ms740141(VS.85).aspx) specifically
> > says this:
> > exceptfds:
> > - If processing a connect call (nonblocking), connection attempt failed.
> > - OOB data is available for reading (only if SO_OOBINLINE is disabled).
> > Looking over the man page you linked me, it doesn't seem like Linux does it
> > this way, which is interesting. From what I'm hearing, it looks like I will
> > need to send a no-op to determine if it failed or is just still connecting?
>
> Linux, or any other unixy system, to my knowledge.
>
> Have you tried using luasocket's select yet, and verified that it does
> not in fact work?
>
> You can do it from the cmd line very quickly, see the code I posted.
>
> Its possible you'll see the connected fd in the read and/or write set.
>
> Sam

I have experimented with select() before I ever came to Lua-L, and tried to work around its problems on Windows, with not much luck.

Below is my test run with output. It may also be worth mentioning that I've noticed while developing my plugin that select({s}, {s}, nil) will only return 's' in the writefds table, no matter how many times in a row I call select() - yet the moment I remove 's' from the writefds table, it appears in the readfds. It's not particularly applicable to the code below - neither of them contain 's' - but it's worth further pointing out how different WinSock seems to be.

(I expect that the sock would have appeared in exceptfds, had I access to it.)


> socket = require "socket"
> s = socket.tcp()
> s:settimeout(0)
> print(s:connect("192.168.41.2", 9000))
nil timeout
> r,w,e = socket.select({s}, {s}, 0)
> print(r[1])
nil
> print(w[1])
nil
> print(e)
timeout
> print(s)
tcp{client}: 02A2A070
> print(s:receive("*l"))
nil Socket is not connected 
> print(s:send("foobar"))
nil Socket is not connected 0

> s = socket.tcp()
> s:settimeout(0)
> print(s:connect("192.168.41.2", 9000))
nil timeout
> r,w,e = socket.select({s}, {s}, 0)
> print(s:send("foobar"))
nil Socket is not connected 0


Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. Sign up now.