From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.75]) by sourceware.org (Postfix) with ESMTPS id B37C03846078 for ; Tue, 6 Apr 2021 12:57:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B37C03846078 Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MPXMa-1lH1Y90yQM-00Mc5H for ; Tue, 06 Apr 2021 14:57:39 +0200 Received: by calimero.vinschen.de (Postfix, from userid 500) id 928C6A80773; Tue, 6 Apr 2021 14:57:38 +0200 (CEST) Date: Tue, 6 Apr 2021 14:57:38 +0200 From: Corinna Vinschen To: cygwin-developers@cygwin.com Subject: Re: Question about non-blocking Windows pipes Message-ID: Reply-To: cygwin-developers@cygwin.com Mail-Followup-To: cygwin-developers@cygwin.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:kjg36nUbIylKOlDJe/zvfYaBTrJ60ajHbzJKnmldTCmU4eCFBK1 adALftbBmB4enHkobLxqbPZTGeA3eWIis6RSthNXT3fb6MJGL3F+P1PQV3EFLi+X11dkDDT ruNtmjGrQIVD/j0/mO/IP5C6xkky/F2HFBggPCjlxc5TtvbAUtLZM6GkkNIMDeBVHqI0tD5 ycJus8eqggYuR+5EjCQfw== X-UI-Out-Filterresults: notjunk:1;V03:K0:B5CcFOVFH28=:syHQZPUM8KtAxcqg9bG71u P+/5MlFpw7aO4A/yIgeLO9/UudtfPSKLSJ+ZvPQMcP4MrDrk0cIbFikcZYO6OrRF1WXqQRJyp xN3u4tEsh0A8vpoFJFFVsz9DRJaEp7zylZdT2xcyMoNLHZVh+yDkrrq6hwolq8p9fEMYfKYjp 2hauO1pIdftnik8CYprlLEOJn1lIAP2kgb88sOHZ9U7xWJnrK1BY8rqH//trEHS3Hk1NWu/6x WnnJjBNrBaW+4TIYOgVoIPfVQdCWglbROTaSIxuFEEQKP+14zi3bsL8wYNkI+855uT+fsiOA6 LhknGfOkAMa4HYzGXvvPqMCGGpym+DfzT9A1HaOIdp4oSkzuegFjA/8kGIm9mLKb3EiOtmPJd k4FO4c2eLa0janhEh9Xz4l+EFftUGj9J8gDYW1DedwL479aPTkaZGKlrmrnP1ruy/4ipMoFlr OUNudhBmJIwS5cPs5mW0c7D1PMn/UjV4LqfOEJz4LskgrHNl1mCl X-Spam-Status: No, score=-101.0 required=5.0 tests=BAYES_00, GOOD_FROM_CORINNA_CYGWIN, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Apr 2021 12:57:42 -0000 Hi Ken, On Apr 1 10:39, Ken Brown via Cygwin-developers wrote: > Hi Corinna, > > There are several places in fhandler_socket_unix.cc where you make a > distinction between the blocking and nonblocking cases with code like this: > > cygwait (evt ?: get_handle (),...) I only see this in fhandler_socket_unix::listen_pipe, actually. > Here evt is an event handle in the blocking case and is NULL in the > nonblocking case. See, for example, fhandler_socket_unix::listen_pipe. > > What's the reasoning behind this? Why not just always create an event or > always use the handle? In the nonblocking case, the status code returned from NtFsControlFile is either a useful status code like STATUS_SUCCESS or an error code, or it is STATUS_PENDING. STATUS_PENDING only means the call is still not finished. To get a useful result, you still need a useful status code. You get that by waiting for the handle. Note that waiting for the handle doesn't mean to wait for the connecting client. Rather, it's signalled as soon as the async NtFsControlFile call finished. If the status code is STATUS_PIPE_LISTENING then, you know that no client tries to connect, so you can return EAGAIN. The completion event object OTOH, is only signalled if a client actually connected, so that's blocking mode. Two problems with using an event object in nonblocking mode: - The event object is referenced in the call. If NtFsControlFile returns STATUS_PENDING and you leave the function, you have to use a globally available event object, because this address is used as event object until completion of the NtFsControlFile call (and a client connected). - You also have a pending NtFsControlFile until a client connects. This is contrary to what you want in a non-blocking call: You only want to know *if* a client connects, not wait for it either way. Does that help? I'm not claiming there isn't another way to handle this scenario, that's just what I came up with. Corinna