From owner-freebsd-bugs@freebsd.org Thu Dec 8 14:34:09 2016 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AA7E8C6D094 for ; Thu, 8 Dec 2016 14:34:09 +0000 (UTC) (envelope-from dimitri.staessens@intec.ugent.be) Received: from smtp2.ugent.be (smtp2.ugent.be [157.193.49.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6D01FD2C for ; Thu, 8 Dec 2016 14:34:08 +0000 (UTC) (envelope-from dimitri.staessens@intec.ugent.be) Received: from localhost (mcheck3.ugent.be [157.193.71.89]) by smtp2.ugent.be (Postfix) with ESMTP id 7C535B2572; Thu, 8 Dec 2016 15:34:05 +0100 (CET) X-Virus-Scanned: by UGent DICT Received: from smtp2.ugent.be ([157.193.49.126]) by localhost (mcheck3.ugent.be [157.193.43.11]) (amavisd-new, port 10024) with ESMTP id 8sm5tMSf3LMI; Thu, 8 Dec 2016 15:34:05 +0100 (CET) Received: from mail2.intec.ugent.be (mail2.intec.ugent.be [157.193.214.245]) by smtp2.ugent.be (Postfix) with ESMTP id E9C6FB2549; Thu, 8 Dec 2016 15:34:04 +0100 (CET) Received: from [10.10.131.46] (hal.ilabt.iminds.be [193.191.148.129]) (using TLSv1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: dstaesse) by mail2.intec.ugent.be (Postfix) with ESMTPSA id D18762C; Thu, 8 Dec 2016 15:34:04 +0100 (CET) Subject: Re: Call to accept() does not time out when setting SO_RCVTIMEO on a socket To: Bob Bishop References: <76cee3a4-18d0-1f8c-eda3-e19c496c39b6@intec.ugent.be> <22926F6A-7E4A-49D4-BD54-1E81B1002D61@gid.co.uk> Cc: freebsd-bugs@freebsd.org From: Dimitri Staessens Message-ID: <3fc9cf5b-2e33-d667-0494-359ee6a93085@intec.ugent.be> Date: Thu, 8 Dec 2016 15:31:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <22926F6A-7E4A-49D4-BD54-1E81B1002D61@gid.co.uk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at jchkm1 with ID 58496F5C.004 by Joe's j-chkmail (http://helpdesk.ugent.be/email/)! X-j-chkmail-Enveloppe: 58496F5C.004 from mail2.intec.ugent.be/mail2.intec.ugent.be/157.193.214.245/mail2.intec.ugent.be/ X-j-chkmail-Score: MSGID : 58496F5C.004 on smtp2.ugent.be : j-chkmail score : . : R=. U=. O=. B=0.000 -> S=0.000 X-j-chkmail-Status: Ham X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Dec 2016 14:34:09 -0000 Hi Bob, thanks for the response. Setting the socket to non-blocking eats the CPU. I'll probably use select() or poll() with a single fd then. kind regards, Dimitri On 12/08/16 14:37, Bob Bishop wrote: > Hi, > >> On 8 Dec 2016, at 12:41, Dimitri Staessens wrote: >> >> Dear devs, >> >> I'm trying to get an accept() call to time out using setsockopt. >> >> On Linux, the example below terminates: >> >> [dstaesse@phoneutria]$ gcc accept_st.c -o accept_st >> [dstaesse@phoneutria]$ ./accept_st >> Timeout is 0:100000. >> Check is 0:103333. >> Accept returned: Resource temporarily unavailable. >> Accept returned: Resource temporarily unavailable. >> Accept returned: Resource temporarily unavailable. >> Bye. >> >> On FreeBSD 11.0-RELEASE however, it hangs on the accept() forever. > > accept() doesn’t work like that on *BSD. Set the socket non-blocking and then accept() returns EWOULDBLOCK if there is nothing to accept. > >> Is this a known issue? >> >> Thanks for your help, >> >> Dimitri >> >> --- example source: >> [snip] >> -- >> Dimitri Staessens >> Ghent University - imec >> Dept. of Information Technology (INTEC) >> Internet Based Communication Networks and Services >> Technologiepark 15 >> 9052 Zwijnaarde >> T: +32 9 331 48 70 >> F: +32 9 331 48 99 > -- > Bob Bishop > rb@gid.co.uk > > > > -- Dimitri Staessens Ghent University - imec Dept. of Information Technology (INTEC) Internet Based Communication Networks and Services Technologiepark 15 9052 Zwijnaarde T: +32 9 331 48 70 F: +32 9 331 48 99