From owner-freebsd-questions Thu Mar 30 17: 7: 0 2000 Delivered-To: freebsd-questions@freebsd.org Received: from hermes.avantgo.com (ws1.avantgo.com [207.214.200.194]) by hub.freebsd.org (Postfix) with ESMTP id 3D86937B837 for ; Thu, 30 Mar 2000 17:06:56 -0800 (PST) (envelope-from scott@avantgo.com) Received: from river.avantgo.com (river.avantgo.com [10.0.128.30]) by hermes.avantgo.com (Postfix) with ESMTP id 7E6D715; Thu, 30 Mar 2000 17:06:54 -0800 (PST) Received: (from scott@localhost) by river.avantgo.com (8.9.3/8.9.3) id RAA01102; Thu, 30 Mar 2000 17:06:53 -0800 Date: Thu, 30 Mar 2000 17:06:53 -0800 From: Scott Hess To: Veaceslav Revutchi Cc: freebsd-questions@FreeBSD.ORG Subject: Re: tcp_keepalives, how to set the idle time Message-ID: <20000330170653.A1084@avantgo.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0pre3us In-Reply-To: Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Thu, Mar 30, 2000 at 09:54:56PM +0300, Veaceslav Revutchi wrote: > Can anyone explain a little how tcp_keepalives work? > Is tcp sending keepalive packets to the other side > waiting for a reply? > I actually need to know how can I set the stale time at > 5min for example so that if there is no traffic on the > socket for 5 min. it should close it. Set the sysctl net.inet.tcp.always_keepalive to 1 to enable keepalives. Once enabled, net.inet.tcp.keepidle gives the number of seconds before the first keepalive packet. net.inet.tcp.keepintvl gives the number of seconds between additional keepalive packets. If 8 keepalive packets are sent with no response, the connection is dropped. It sounds like you probaby want to do something like: sysctl -w net.inet.tcp.always_keepalive=1 sysctl -w net.inet.tcp.keepidle=150 sysctl -w net.inet.tcp.keepintvl=20 I don't think you can use sysctl to set the number of keepalive packets to wait for before terminating the connection. You can turn on keepalive on a per-socket basis using setsockopt(). It's not obvious to me if you can adjust the other values the same way, though I would assume that the same sysctl values are used. Later, scott To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message