[fpc-pascal] How to detect connection status of a socket

Xiangrong Fang xrfang at gmail.com
Mon Apr 22 15:06:32 CEST 2013


2013/4/22 Marco van de Voort <marcov at stack.nl>

> In our previous episode, Xiangrong Fang said:
> > I am writing a redis client in fpc and found that even when the
> connection
> > is closed by server (via redis CLIENT KILL),
>
> I don't know the redis protocol is, but "CLIENT KILL" sounds like redis
> protocol, while you are trying to detect disconnect at socket level. And is
> your socket layer really connection oriented ?
>

Yes, it is redis protocol.  I can only be sure that it is TCP based.


> IOW does the remote server really actively close the socket?
>
> Maybe stracing the application during a disconnect event might yield some
> more information.
>

I will study stracing if necessary. But will simple "netstat" show the
status of a socket?

>
> > How do I tell if a socket is still connected or not?
>
> Limit the timeout time (some socketoption or ioctl iirc, search the web),
> send something, and wait the timeout time.  Then read something.
>

I am using blocking mode, it just return immediately.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130422/4896378e/attachment.html>


More information about the fpc-pascal mailing list