Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Aug 2020 03:11:03 -0700
From:      "Ronald F. Guilmette" <rfg@tristatelogic.com>
To:        freebsd-questions@freebsd.org
Subject:   How to set a connect() timeout (?)
Message-ID:  <79516.1597313463@segfault.tristatelogic.com>

next in thread | raw e-mail | index | archive | help
This is driving me bonkers and I feel like I'm having deja vu all over aga=
in.
(In other words I think I may have asked about this before in the very dis=
tant
past.)

Setting a programmed time limit for the connect() system call seems to be =
a
common thing that many people, not just myself, often want to do.  It is n=
ot
at all clear if there is or isn't a simple way to do that, e.g. one that
doesn't involve calling select() or poll() or something like that.

On FreeBSD, there is a system-wide sysctl variable that sets the system-wi=
de default
connect timeout.  It's called net.inet.tcp.keepinit.  But I really do want=
 to be
able to programatically set the connect timeout for individual (outbound) =
sockets.

setsockopt() provides the SO_SNDTIMEO and SO_RCVTIMEO options which allow =
setting
of timeouts on individual sockets for writing and reading respectively, bu=
t it is
not immediately apparent, e.g. from the relevant man page, that either of =
these
setsockopt() options will have any effect on the connect() timeout period.

In online sources there is some suggestion that one or the other of these =
two
setsockopt() options can be used, at least on Linux, to programatically co=
ntrol
the per-socket connect timeout period, but I have not tried that on my own=
 Linux
system so I may be reading too much into what I have been reading.

I am forced to wonder why, on FreeBSD there is no such thing as an SO_CONT=
IMEO
option that can be used with setsockopt() to easily control the connect() =
timeout
on a per-socket basis.

Can anyone explain to me why there isn't such a thing?  Seems like rather =
a glaring
oversight to me, and a no-brainer (that such a thing really should exist).



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?79516.1597313463>