Re: poll (2) - portability/alternatives
| From: | Jason Greene | Date: | Tue, 19 Mar 2002 05:09:43 +0000 |
| Subject: | Re: poll (2) - portability/alternatives | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-81473@lists.php.net to get a copy of this message | ||
If a socket is added to readfds select will return if the follow occurs:
error on the socket
EOF on the socket
data on the socket
Therefore, you should be able to call select on the socket (adding a
timeout for sanity) and if it returns call read/recv. If the return
value is 0 an EOF has occurred, if -1 an error occurred.
The worst that can happen in this scenario is that you get data, this
however can be resolved by using the MSG_PEEK option to recv, then you
don't remove the data from the buffer.
-Jason
On Mon, 2002-03-18 at 16:39, Wez Furlong wrote:
> Theres a bug in the DB where feof($sock) will not detect
> a timed-out connection.
>
> I have a fix which uses poll(2) if available to check if
> the socket has hungup.
>
> If poll(2) is not present, it will try to read a chunk
> of data; if that times out or sets the eof indicator,
> then an EOF is returned.
>
> Does anyone know just how portable poll(2) is, and if
> there is an alternative portable technique to check if
> the sock is still connected?
> My man page says that libc emulates poll(2) in older
> linux kernels using select(); can anyone point me to
> some code that does this using select()?
>
> --Wez.
>
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, visit: http://www.php.net/unsub.php
>