Date: Mon, 19 Aug 2013 23:13:02 -0400 (EDT) From: Daniel Eischen <deischen@freebsd.org> To: Adrian Chadd <adrian@freebsd.org> Cc: Vitja Makarov <vitja.makarov@gmail.com>, freebsd-current <freebsd-current@freebsd.org> Subject: Re: Question about socket timeouts Message-ID: <Pine.GSO.4.64.1308192307100.19722@sea.ntplx.net> In-Reply-To: <CAJ-VmokxJvSK1JjEyZ4s9LeX25Lag0ET9nq3bEebM89xOsK1BA@mail.gmail.com> References: <CAKGHGPS=HCYfXxPXuUz5G83j5sGieejPU-QHmi9TrmMhmweHLw@mail.gmail.com> <CAJ-VmokxJvSK1JjEyZ4s9LeX25Lag0ET9nq3bEebM89xOsK1BA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 > On 19 August 2013 12:33, Vitja Makarov <vitja.makarov@gmail.com> wrote: > >> Hi! >> >> Recently I was playing with small socket timeouts. setsockopt(2) >> SO_RCVTIMEO and found a problem with it: if timeout is small enough >> read(2) may return before timeout is actually expired. >> >> I was unable to reproduce this on linux box. >> >> I found that kernel uses a timer with 1/HZ precision so it converts >> time in microseconds to ticks that's ok linux does it as well. The >> problem is in details: freebsd uses floor() approach while linux uses >> ceil(): >> >> from FreeBSD's sys/kern/uipc_socket.c: >> val = (u_long)(tv.tv_sec * hz) + tv.tv_usec / tick; >> if (val == 0 && tv.tv_usec != 0) >> val = 1; /* at least one tick if tv > 0 */ >> >> from Linux's net/core/sock.c: >> *timeo_p = tv.tv_sec*HZ + (tv.tv_usec+(1000000/HZ-1))/(1000000/HZ); >> >> So, for instance, we have a freebsd system running with kern.hz set >> 100 and set receive timeout to 25ms that is converted to 2 ticks which >> is 20ms. In my test program read(2) returns with EAGAIN set in >> 0.019ms. >> >> So the question is: is that a problem or not? >> >> -- >> vitja. -- DE
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.64.1308192307100.19722>