[fpc-pascal] fpselect does not work on linux
Jonas Maebe
jonas.maebe at elis.ugent.be
Sat May 9 12:43:00 CEST 2009
On 09 May 2009, at 09:38, Rainer Stratmann wrote:
> To find out if a nonblocking socket has connected I use the
> following piece of
> code:
>
> With windows that works, but with linux I get alwas the result that
> the socket
> is writable.
>
> function is_writable_socket( sck : integer ) : boolean;
> var
> fds : tfdset;
> tv : timeval;
> begin
> {$ifdef linux} fpfd_zero( fds ); fpfd_set( sck , fds ); {$endif}
> {$ifdef windows} fd_zero( fds ); fd_set( sck , fds ); {$endif}
> tv.tv_sec := 0;
> tv.tv_usec := 0;
> // socket+1 , read , write , except , timeout
> {$ifdef linux}
> result := fpselect( sck + 1 ,
Where does the "+ 1" come from?
> nil , @fds , nil , @tv ) > 0;
This is probably unrelated to your problem, but you have a bug here.
(fp)select can also return EINTR (possibly under Windows as well, I
don't know), in which case you have to retry. You need something like
this:
repeat
res:=fpselect( sck + 1 , nil , @fds , nil , @tv );
until (res<>-1) or (fpgeterrno<>ESysEIntr);
Note that you have to use this construct for many low level unix
calls. Check the man pages to see which routines can return EINTR and
may need restarting.
Jonas
More information about the fpc-pascal
mailing list