From owner-freebsd-current@FreeBSD.ORG Wed Aug 21 21:21:22 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 2AE922A8; Wed, 21 Aug 2013 21:21:22 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E6BF72C14; Wed, 21 Aug 2013 21:21:21 +0000 (UTC) Received: from jhbbsd.localnet (unknown [38.105.238.108]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 973EFB946; Wed, 21 Aug 2013 17:21:20 -0400 (EDT) From: John Baldwin To: freebsd-current@freebsd.org, Daniel Eischen Subject: Re: Question about socket timeouts Date: Wed, 21 Aug 2013 14:01:46 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p28; KDE/4.5.5; amd64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201308211401.46468.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Wed, 21 Aug 2013 17:21:20 -0400 (EDT) Cc: Adrian Chadd , Vitja Makarov X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Aug 2013 21:21:22 -0000 On Monday, August 19, 2013 11:13:02 pm Daniel Eischen wrote: > On Mon, 19 Aug 2013, Adrian Chadd wrote: > > > Yes! Please file a PR! > > This sorta implies that both are acceptable (although, > the Linux behavior seems more desirable). > > http://austingroupbugs.net/view.php?id=369 No, that says "round up", so it does mean that the requested timeout should be the minimum amount slept. tvtohz() does this. Really odd that the socket code is using its own version of this rather than tvtohz(). Oh, I bet this just predates tvtohz(). Interesting that it keeps getting bug fixes in its history that simply using tvtohz() would have solved. Try this: Index: uipc_socket.c =================================================================== --- uipc_socket.c (revision 254570) +++ uipc_socket.c (working copy) @@ -2699,21 +2699,16 @@ sosetopt(struct socket *so, struct sockopt *sopt) if (error) goto bad; - /* assert(hz > 0); */ if (tv.tv_sec < 0 || tv.tv_sec > INT_MAX / hz || tv.tv_usec < 0 || tv.tv_usec >= 1000000) { error = EDOM; goto bad; } - /* assert(tick > 0); */ - /* assert(ULONG_MAX - INT_MAX >= 1000000); */ - val = (u_long)(tv.tv_sec * hz) + tv.tv_usec / tick; - if (val > INT_MAX) { + val = tvtohz(&tv); + if (val == INT_MAX) { error = EDOM; goto bad; } - if (val == 0 && tv.tv_usec != 0) - val = 1; switch (sopt->sopt_name) { case SO_SNDTIMEO: -- John Baldwin