From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 38646 invoked by alias); 27 Mar 2015 09:30:14 -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 38613 invoked by uid 89); 27 Mar 2015 09:30:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: Yes, score=5.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-out.astrium.eads.net Received: from mail-out.astrium.eads.net (HELO mail-out.astrium.eads.net) (80.156.47.35) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 27 Mar 2015 09:30:10 +0000 Received: from mail-out.astrium.eads.net (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D90D2C063 for ; Fri, 27 Mar 2015 10:30:06 +0100 (CET) Received: from FOWEXMC002.de.astrium.corp (unknown [10.190.101.66]) by mail-out.astrium.eads.net (Postfix) with ESMTPS id 3CB602C05F for ; Fri, 27 Mar 2015 10:30:06 +0100 (CET) Received: from FOWEXMC003.de.astrium.corp ([169.254.2.44]) by FOWEXMC002.de.astrium.corp ([169.254.1.184]) with mapi id 14.03.0224.002; Fri, 27 Mar 2015 10:30:05 +0100 From: "KEREP, Mladen" To: "cygwin@cygwin.com" Subject: Handles returned by mq_open are not valid file descriptors as supposed to be under native linux distributions Date: Fri, 27 Mar 2015 11:44:00 -0000 Message-ID: <556891A1F0F6154CB3DD7811A49431534D3B8027@FOWEXMC003.de.astrium.corp> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-IsSubscribed: yes X-SW-Source: 2015-03/txt/msg00485.txt.bz2 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 di= fferent platforms. Basically linux (debian, Ubuntu, archlinux, rasbian) is = the development platform, but also vxworks platforms are supported. Several message queues are opened through mq_open calls and the returned ha= ndles are organized in file descriptor sets (fd_set). The set is then passe= d over to a select(2) call, which blocks processing and returns as soon as = any message in any of the queues arrives. This works under linux, since the handles returned are valid file descripto= rs and the macros FD_ZERO / FD_SET are able to handle that handles. However, under Cygwin, mq_open does not directly return file handles, but p= ointers 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." mq_open() and select() conform to POSIX.1-2001, at least under linux, but a= lso under Cygwin ? How can this be modified, so that it works under Cygwin as well ? Here's a small code example, showing a segmentation fault in macros FD_ZERO= /FD_SET: #include #include #include #include #include #include #include int main(void) { int res; int i =3D 0; char msgQueueTestName[] =3D "/testQueue"; mqd_t testQueue; struct mq_attr attrQueue; fd_set readfds; int highest_fd; int numMessages; memset(&attrQueue,0x00,sizeof(attrQueue)); attrQueue.mq_maxmsg =3D 10; /* room for X messages in the queue */ attrQueue.mq_msgsize =3D 20; /* maximum size of a message */ /* this example has only one message queue; usually several message queue= s are opened by different processes */ testQueue =3D mq_open(msgQueueTestName, O_RDWR | O_CREAT, S_IRWXU | S_IRW= XG, &attrQueue); if( testQueue =3D=3D (mqd_t)-1 ) { printf("Failed to open msg queue %s: %s %d\n", msgQueueTestName, sys_= errlist[errno],errno); } else { printf("msg queue descriptor %d (0x%x)\n", testQueue, testQueue); } highest_fd =3D 0; /* here, usually we scan all opened message queues for highest fd */ if (testQueue > highest_fd) highest_fd =3D testQueue; highest_fd++; printf("highest fd %d (0x%x)\n", highest_fd, highest_fd); /* add all file descriptors to be checked */ FD_ZERO(&readfds); FD_SET(testQueue, &readfds); printf("readfds entries %d\n", sizeof(readfds.fds_bits) / sizeof(fd_mask)= ); numMessages =3D select(highest_fd, &readfds, NULL, NULL, (struct timeval = *) NULL); printf("messages pending %d\n", numMessages); return EXIT_SUCCESS; } Any help will be appreciated. Mladen -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple