From owner-svn-src-head@freebsd.org Thu Feb 2 08:29:26 2017 Return-Path: Delivered-To: svn-src-head@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 0CBC4CCCBDC; Thu, 2 Feb 2017 08:29:26 +0000 (UTC) (envelope-from Hartmut.Brandt@dlr.de) Received: from mailhost.dlr.de (mailhost.dlr.de [129.247.252.32]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mailhost.dlr.de", Issuer "DLR CA - G02" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7106F175B; Thu, 2 Feb 2017 08:29:25 +0000 (UTC) (envelope-from Hartmut.Brandt@dlr.de) Received: from DLREXHUB01.intra.dlr.de (172.21.152.130) by mailhost.dlr.de (172.21.163.100) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 2 Feb 2017 09:29:16 +0100 Received: from DLREXMBX01.intra.dlr.de ([fe80::d198:77e5:d411:fccd]) by dlrexhub01.intra.dlr.de ([::1]) with mapi id 14.03.0319.002; Thu, 2 Feb 2017 09:29:20 +0100 From: To: CC: , , Subject: RE: svn commit: r313043 - head/sys/kern Thread-Topic: svn commit: r313043 - head/sys/kern Thread-Index: AQHSfIzUaHU0GSnLtUmrDysUntoftKFUYnQAgAD1jAA= Date: Thu, 2 Feb 2017 08:29:20 +0000 Message-ID: <611243783F62AF48AFB07BC25FA4B1061CED9FD9@DLREXMBX01.intra.dlr.de> References: <201702011312.v11DC7WJ085025@repo.freebsd.org> <20170201180816.GF3334@FreeBSD.org> In-Reply-To: <20170201180816.GF3334@FreeBSD.org> Accept-Language: en-US, de-DE Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: Content-Type: multipart/mixed; boundary="_002_611243783F62AF48AFB07BC25FA4B1061CED9FD9DLREXMBX01intra_" MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-11.0.0.4255-8.100.1062-22860.005 X-TM-AS-Result: No--18.826300-5.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Feb 2017 08:29:26 -0000 --_002_611243783F62AF48AFB07BC25FA4B1061CED9FD9DLREXMBX01intra_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable To be honest - I feared that when I saw your messages regarding this. Here = is my original message from july. Attached is also a small test program. Hi, I'm trying to use asio (that's boost::asio without boost) to handle listeni= ng sockets asynchronuosly. This appears not to work. There are also some re= ports on the net about this problem. I was able to reproduce the problem wi= th a small C-programm that does the same steps as asio. The relevant sequen= ce of system calls is: kqueue() =3D 3 (0x3) socket(PF_INET,SOCK_STREAM,6) =3D 4 (0x4) setsockopt(0x4,0xffff,0x800,0x7fffffffea2c,0x4) =3D 0 (0x0) kevent(3,{ 4,EVFILT_READ,EV_ADD|EV_CLEAR,0x0,0x0,0x0 4,EVFILT_WRITE,EV_ADD|= EV_CLEAR,0x0,0x0,0x0 },2,0x0,0,0x0) =3D 0 (0x0) setsockopt(0x4,0xffff,0x4,0x7fffffffea2c,0x4) =3D 0 (0x0) bind(4,{ AF_INET 0.0.0.0:8080 },16) =3D 0 (0x0) listen(0x4,0x80) =3D 0 (0x0) ioctl(4,FIONBIO,0xffffea2c) =3D 0 (0x0) kevent(3,{ 4,EVFILT_READ,EV_ADD|EV_CLEAR,0x0,0x0,0x0 4,EVFILT_WRITE,EV_ADD|= EV_CLEAR,0x0,0x0,0x0 },2,0x0,0,0x0) =3D 0 (0x0) kevent(3,0x0,0,0x7fffffffe5a0,32,0x0) ERR#4 'Interrupted system call' The problem here is that asio registers each file descriptor with EVFILT_RE= AD and EVFILT_WRITE as soon as it is opened (first kevent call).=20 After bringing the socket into the listening state and when async_accept() = is called it registers the socket a second time. According to the man page = this is perfectly legal and can be used to modify the registration. With this sequence of calls kevent() does not return when a connection is e= stablished successfully. I tracked down the problem and the reason is in soo_kqfilter(). This is cal= led for the first EVFILT_READ registration and decides based on the SO_ACCE= PTCONN flag which filter operations to use solisten_filtops or soread_filto= ps. In this case it chooses soread_filtops. The second EVFILT_READ registration does not call soo_kqfilter() again, but= just updates the filter from the data and fflags field so the listening so= cket ends up with the wrong filter operations. -----Original Message----- From: Gleb Smirnoff [mailto:glebius@FreeBSD.org]=20 Sent: Wednesday, February 01, 2017 7:08 PM To: Hartmut Brandt Cc: src-committers@freebsd.org; svn-src-all@freebsd.org; svn-src-head@freeb= sd.org Subject: Re: svn commit: r313043 - head/sys/kern On Wed, Feb 01, 2017 at 01:12:07PM +0000, Hartmut Brandt wrote: H> Author: harti H> Date: Wed Feb 1 13:12:07 2017 H> New Revision: 313043 H> URL: https://svnweb.freebsd.org/changeset/base/313043 H>=20 H> Log: H> Merge filt_soread and filt_solisten and decide what to do when checkin= g H> for EVFILT_READ at the point of the check not when the event is regist= ers. H> This fixes a problem with asio when accepting a connection. H> =20 H> Reviewed by: kib@, Scott Mitchell This goes into opposite direction with what I am doing: https://reviews.freebsd.org/D9356 Can you please explain the problem with asio when accepting a connection? --=20 Totus tuus, Glebius. --_002_611243783F62AF48AFB07BC25FA4B1061CED9FD9DLREXMBX01intra_ Content-Type: text/plain; name="k.c" Content-Description: k.c Content-Disposition: attachment; filename="k.c"; size=1459; creation-date="Thu, 02 Feb 2017 07:47:39 GMT"; modification-date="Thu, 02 Feb 2017 07:47:39 GMT" Content-Transfer-Encoding: base64 I2luY2x1ZGUgPHN5cy9zb2NrZXQuaD4NCiNpbmNsdWRlIDxzeXMvdHlwZXMuaD4NCiNpbmNsdWRl IDxzeXMvZXZlbnQuaD4NCiNpbmNsdWRlIDxzeXMvZmlsaW8uaD4NCg0KI2luY2x1ZGUgPHN5cy9p b2N0bC5oPg0KI2luY2x1ZGU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