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

Marco van de Voort marcov at stack.nl
Mon Apr 22 14:30:57 CEST 2013

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 ?

IOW does the remote server really actively close the socket?

Maybe stracing the application during a disconnect event might yield some
more information.

> 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.

More information about the fpc-pascal mailing list