<div dir="ltr">Dear Sir,<div><br></div><div>I am tring to integrate POSIX application on RTEMS.</div><div>our POSIX application use select() for I/O multiplexing mechanism.</div><div>At this time, select() always return "-1" value, it mean "bad file number".</div>
<div><br></div><div>Therefore, I tested simple test code using select() function in below;</div><div>Is it a bug using select() ? and, Is there how to do fix this problem ?</div><div><br></div><div>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</div>
<div><div>void test_select(void)</div><div>{</div><div> int fd[2];</div><div> int i;</div><div> int n;</div><div> int state;</div><div><br></div><div> char buf[255];</div><div><br></div><div> struct timeval tv;</div>
<div><br></div><div> fd_set readfds, writefds;</div><div><br></div><div><span class="" style="white-space:pre"> </span>mkdir ("tmp", S_IRWXU|S_IRWXG|S_IRWXO);</div><div><br></div><div> if ((fd[0] = open("/tmp/testfile", O_CREAT | O_RDONLY)) == -1)</div>
<div> {</div><div> printf("file open error : ");</div><div> exit(0);</div><div> }</div><div> if ((fd[1] = open("/tmp/testfile2", O_CREAT | O_RDONLY)) == -1)</div><div> {</div>
<div> printf("file open error : ");</div><div> exit(0);</div><div> }</div><div><br></div><div> memset (buf, 0x00, 255);</div><div><br></div><div> for(;;)</div><div> {</div><div> FD_ZERO(&readfds);</div>
<div> FD_SET(fd[0], &readfds);</div><div> FD_SET(fd[1], &readfds);</div><div><br></div><div> state = select(fd[1]+1, &readfds, NULL, NULL, NULL);</div><div> switch(state)</div><div>
{</div><div> case -1:</div><div> perror("select error : ");</div><div> exit(0);</div><div> break;</div><div><br></div><div> default :</div>
<div> for (i = 0; i < 2; i++)</div><div> {</div><div> if (FD_ISSET(fd[i], &readfds))</div><div> {</div><div> while ((n = read(fd[i], buf, 255)) > 0)</div>
<div> printf("(%d) [%d] %s", state, i, buf);</div><div> }</div><div> }</div><div> memset (buf, 0x00, 255);</div><div> break;</div>
<div> }</div><div> usleep(1000);</div><div> }</div><div>}</div></div><div>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br></div><div><br></div><div>Best Regards.</div><div><br></div></div>