简体   繁体   English

cygwin上带有FD_SET()和消息队列的核心转储

[英]Core dump with FD_SET() and message queues on cygwin

I have the following C code for setting up select() to listen for incoming data on both a TCP socket and a message queue: 我有以下C代码用于设置select()来侦听TCP套接字和消息队列上的传入数据:

fd_set readSet;
u32 maxFD = 0;
mqd_t parentQueue;
int serverSocket;

/* not shown: parentQueue and serverSocket were successfully opened */

FD_ZERO(&readSet);
FD_SET(serverSocket,&readSet);
FD_SET(parentQueue,&readSet);

/* next, not shown: block with select() and I/O processing */ 

My problem is that the code crashes (with core dump) when I add the message queue to readSet with FD_SET(), FD_SET(parentQueue,&readSet). 我的问题是,当我使用FD_SET(),FD_SET(parentQueue,&readSet)将消息队列添加到readSet时,代码崩溃(带有核心转储)。

The man page says that on Linux, mqd_t can be used with select(). 手册页指出,在Linux上,mqd_t可与select()一起使用。 And parentQueue corresponds to a valid mqd_t, obtained with mq_open(). parentQueue对应于通过mq_open()获得的有效mqd_t。 So why would FD_SET() crash ? 那么,为什么FD_SET()崩溃? Is it because on Cygwin, message queues are not files ? 是因为在Cygwin上,消息队列不是文件吗? But I can see the queue in /dev/mqueue. 但是我可以在/ dev / mqueue中看到队列。

After digging a little bit, I identified the problem. 经过一番挖掘,我发现了问题所在。 On cygwin, the queue file descriptor (mqd_t) is 64 bits long (I am using a 64 bit system) and because of that the queue file descriptor falls outside the range for select, FD_SETSIZE, causing FD_SET to crash 在cygwin上,队列文件描述符(mqd_t)的长度为64位(我使用的是64位系统),因此,队列文件描述符超出了选择FD_SETSIZE的范围,从而导致FD_SET崩溃

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM