[fpc-pascal] socket timeout
Victor Campillo
victor.campillo at gmail.com
Tue Apr 16 12:34:48 CEST 2013
On 16/04/13 11:26, Xiangrong Fang wrote:
> Hi there,
>
> How can I set the connection and read/write timeout when using socket
> in free pascal? I like the way it works now (blocking, NOT async),
> but the timeout is a bit too long.
>
> BTW, I hope the way to control timeout is withing the program and
> platform independent (instead of, e.g. set sysctrl under linux).
>
> Thanks a lot.
Hi,
As you, when I work with sockets I like the blocking mode but the
timeout of connect was a headache for me.
I use fpsetsockopt with the options SO_SNDTIMEO and SO_RCVTIMEO for the
read/write timeout.
With connect I don't found an easy way to use my own timeout, so I made
a little hack in this situation. At the same time that I call connect I
start a new thread for registering the time pass, if the timeout is
passed then close/shutdown the socket, this unblock the connect. In case
that the connection was succesful then I terminate the parallel thread
before it close the socket.
I don't like what I do for the timeout of connect but it's works, maybe
this thread throw light in this issue and I can find a better way.
Best regards.
--
Victor Campillo
More information about the fpc-pascal
mailing list