[fpc-pascal] fpselect does not work on linux
Michael Van Canneyt
michael at freepascal.org
Sat May 9 16:52:48 CEST 2009
On Sat, 9 May 2009, Rainer Stratmann wrote:
> >Select does *not* tell you if a file descriptor is writeable or readable.
> >It tells you if the read/write operation will block.
> >This is something subtly different.
> This is interesting for blocking mode.
> But since you can switch to nonblocking mode every operation will return
> immediately.
And therefor every select() call will indicate that all is OK.
>
> Here are some descriptions I found about select:
> http://publib.boulder.ibm.com/infocenter/tpfhelp/current/index.jsp?topic=/com.ibm.ztpf-ztpfdf.doc_put.cur/gtpc2/cpp_select.html
> http://docs.sun.com/app/docs/doc/816-5168/select-3c?a=view
> http://www.developerweb.net/forum/showthread.php?p=13486
>
> "...The select socket function monitors a list of file descriptors for
> readability, readiness for writing, and exception pending conditions."
You should check what the linux manpage says. It describes the exact
behaviour.
> Of course if you are in a blocking mode then a call does not block.
> ...if the select call returns that what we expect.
>
> >For instance, it reports file descriptor 0 as writable, which is rather
> >strange, since it
> >is read-only, but correct, because the write call will not block. Indeed the
> >write call
> >will return at once with an error condition.
> >
> >This is what the kernel sees (I used strace to test your code with descriptor
> >0):
> >
> >select(1, NULL, [0], NULL, {0, 0}) = 1 (out [0], left {0, 0})
>
> May be it is better to test it with sockets descriptors.
> If I get a result that the call will not block (as you say) and then I write
> data to the descriptor then the program crashes with exitcode 13...
Yes, and this is normal: if the socket is not open, you get an error when
attempting to write to it -> program exits. select() does not say anything
about that.
In each case, the call functions correctly, because it's simply passed on
to the kernel. I verified several cases.
>
> >Which is exactly what I sent.
> >
> >In short, is_writable_socket should be implemented differently, not using
> >select.
>
> How can I find out if a socket connection in a nonblocking mode is
> established?
This, I don't know.
Michael.
More information about the fpc-pascal
mailing list