From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31510 invoked by alias); 30 Mar 2015 12:36:52 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 31501 invoked by uid 89); 30 Mar 2015 12:36:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.6 required=5.0 tests=AWL,BAYES_50 autolearn=ham version=3.3.2 X-HELO: calimero.vinschen.de Received: from aquarius.hirmke.de (HELO calimero.vinschen.de) (217.91.18.234) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Mar 2015 12:36:45 +0000 Received: by calimero.vinschen.de (Postfix, from userid 500) id 15862A80982; Mon, 30 Mar 2015 14:36:43 +0200 (CEST) Date: Mon, 30 Mar 2015 13:33:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: Handles returned by mq_open are not valid file descriptors as supposed to be under native linux distributions Message-ID: <20150330123643.GC10785@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <556891A1F0F6154CB3DD7811A49431534D3B8027@FOWEXMC003.de.astrium.corp> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="PmA2V3Z32TCmWXqI" Content-Disposition: inline In-Reply-To: <556891A1F0F6154CB3DD7811A49431534D3B8027@FOWEXMC003.de.astrium.corp> User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-03/txt/msg00517.txt.bz2 --PmA2V3Z32TCmWXqI Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2674 On Mar 27 09:30, KEREP, Mladen wrote: > We're using POSIX message queues to pass messages between processes. > For this we've build a library layer to be able to use message queues > on different platforms. Basically linux (debian, Ubuntu, archlinux, > rasbian) is the development platform, but also vxworks platforms are > supported. >=20 > Several message queues are opened through mq_open calls and the > returned handles are organized in file descriptor sets (fd_set). The > set is then passed over to a select(2) call, which blocks processing > and returns as soon as any message in any of the queues arrives. >=20 > This works under linux, since the handles returned are valid file > descriptors and the macros FD_ZERO / FD_SET are able to handle that > handles. >=20 > However, under Cygwin, For a start, since what you're doing sounds pretty commercial to me, may I point out https://cygwin.com/licensing.html? May I assume your code is open source? > mq_open does not directly return file handles, > but pointers to (unknown) data structures in memory (ref. > http://sourceware.org/ml/cygwin/2013-07/msg00179.html), which cannot > be used with FD_ZERO, FD_SET, so not with select(2). I know from the > man pages (mq_open): "Polling message queue descriptors On Linux, a > message queue descriptor is actually a file descriptor, and can be > monitored using select(2), poll(2), or epoll(7). This is not > portable." >=20 > mq_open() and select() conform to POSIX.1-2001, at least under linux, > but also under Cygwin ? How can this be modified, so that it works > under Cygwin as well ? "This is not portable" is the important hint in the Linux man page. On Cygwin we're using basically the implementation from W. Richard Stevens, as published for his book "UNIX Network Programming, Volume 2, Interprocess communication". It doesn't support the Linux extensions but, yes, it's POSIX compliant, see POSIX.1-2008: "A message queue descriptor *may* be implemented using a file descriptor, in which case applications can open up to at least {OPEN_MAX} file and message queues." [emphasis mine] Note that mq_open doesn't return an int, but a special message queue type mqd_t for a reason. Again, if you use message queues with select, you're creating non-portable code. Having said that, it *would* be possible to change the implementation to make mqd_t a file descriptor and to support the Linux extension, but I'm not planning to do so for the time being. But, as always, patches are welcome. Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --PmA2V3Z32TCmWXqI Content-Type: application/pgp-signature Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJVGUNbAAoJEPU2Bp2uRE+gXfgQAJV0+8caP3vAMdWrRiiccyZb yHaVh4p6k/FtyqOnOZzuqUVcTcwqZ9bypqkIPwh1lH1MOvwYxE4biA5y9DvlzW0k TcU7215HYuC7EkYREHCuK+mQPBWBOomQXDpWqdd07MZ9CyG8dQFgfIbsmaWZYp5d K/dirIBoZAnSWsGKfTez9HonDDgaOrGNSH9rgJSAWRocjQmWD6YEF9m4v5ITCmPy 8RgaHAkgvgczSqxVxzVpwgxvT92+wPLI0XV3g99jVJr+8DI2SI1vb3EWw1Lsk4Dy /ClEzmlt7GAgxxHJ/K9s66a8hUXR/m6OaMxsXl5sD1Q8moF1FHe5xPLpu+pRgj6M SW1SEjUESfnWBDBMv73/fHdQxiWf+4bsWpN5x2YxV4NW00FoN4ZoUis+VZ8VJy7d VUMTYnf5yoFzOV18ZQvxMXe1nTiZsn+TGCjZ/wOhbO+KY14wBRGYkNZhTiYbe95p uh46Y5rIwnJzoJIulNuEueXQSLLIitL/kySY72xvKh0jruqocPqNLRt12kEQOdGQ OPbzIJraJjL19SILurNJIRqaJyaNiCpoObAqV3JK0GJ6G47Wd9L1KuqrANb1e94m qtM9D1YmhOklxPyZVPslymElo2vzNIvsYl14kXhXowwZH6mjJWtXwZDSGU09EZdN nVMjMqe8IZMKni3Sjlq2 =96+a -----END PGP SIGNATURE----- --PmA2V3Z32TCmWXqI--