I’m trying to write a program that select()s on both a connection id
and a socket. My observation is that if you include a coid in the
fd_set to select() then select() fails to return under any non-error
circumstances, even if there is activity on the socket. From what I
gather, a coid is a file descriptor, and therefore should be able to
participate in a select. This appears to be a bug.
Here is an example program that attempts to select on both stdin (not
in raw mode, but the point is valid), and a connection id. If you
select on both, then select never returns. If you select only on
stdin, then select returns on the first keystroke, correctly. This is
the same behaviour I see when selection on both a coid and a socket.
/* --------------------------------------------------------- /
/ Compile with cc -o sel sel.c */
/*
- Attempts to select from both stdin and a connection id. Run
- without arguments to only select on stdin. Run with any argument
- to select on both. I know that stdin should be raw, but this proves
- the point anyway.
- If selecting on the connection id, input on stdin is not noticed.
- This looks like a bug to me.
- Also, cannot select on a coid that is _NTO_SIDE_CHANNEL
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/select.h>
#include <sys/netmgr.h>
#include <sys/neutrino.h>
int main (int argc, char** argv)
{
int kfd;
int chid, coid, rcvid;
fd_set fdset;
int nfds, maxfd;
char msg[1024];
kfd = fileno (stdin);
chid = ChannelCreate (0);
coid = ConnectAttach (ND_LOCAL_NODE, 0, chid, 0, 0);
for (;
{
FD_ZERO (&fdset);
FD_SET (kfd, &fdset);
if (argc > 1)
FD_SET (coid, &fdset);
maxfd = coid;
nfds = select (maxfd + 1, &fdset, NULL, NULL, NULL);
if (nfds > 0)
{
if (FD_ISSET (kfd, &fdset))
{
printf (“Keyboard input\n”);
exit (0);
}
if (FD_ISSET (coid, &fdset))
{
printf (“Input on coid\n”);
rcvid = MsgReceive (coid, msg, sizeof(msg), NULL);
MsgReply (rcvid, 0, msg, sizeof(msg));
}
}
else if (nfds == -1)
{
printf (“select error: %s\n”, strerror(errno));
exit (-1);
}
}
return (0);
}
/* --------------------------------------------------------- */
Andrew Thomas, President, Cogent Real-Time Systems Inc.
2430 Meadowpine Boulevard, Suite 105, Mississauga, Ontario, Canada L5N 6S2
Email: andrew@cogent.ca WWW: http://www.cogent.ca