Is there a bug using select() ?

Thomas Kim thomas73.kim at gmail.com
Thu May 22 09:09:27 UTC 2014


Dear Sir,

I am tring to integrate POSIX application on RTEMS.
our POSIX application use select() for I/O multiplexing mechanism.
At this time, select() always return "-1" value, it mean "bad file number".

Therefore, I tested simple test code using select() function in below;
Is it a bug using select() ? and, Is there how to do fix this problem ?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void test_select(void)
{
    int fd[2];
    int i;
    int n;
    int state;

    char buf[255];

    struct timeval tv;

    fd_set readfds, writefds;

mkdir ("tmp", S_IRWXU|S_IRWXG|S_IRWXO);

    if ((fd[0] = open("/tmp/testfile", O_CREAT | O_RDONLY)) == -1)
    {
        printf("file open error : ");
        exit(0);
    }
    if ((fd[1] = open("/tmp/testfile2", O_CREAT | O_RDONLY)) == -1)
    {
        printf("file open error : ");
        exit(0);
    }

    memset (buf, 0x00, 255);

    for(;;)
    {
        FD_ZERO(&readfds);
        FD_SET(fd[0], &readfds);
        FD_SET(fd[1], &readfds);

        state = select(fd[1]+1, &readfds, NULL, NULL, NULL);
        switch(state)
        {
            case -1:
                perror("select error : ");
                exit(0);
                break;

            default :
                for (i = 0; i < 2; i++)
                {
                    if (FD_ISSET(fd[i], &readfds))
                    {
                        while ((n = read(fd[i], buf, 255)) > 0)
                            printf("(%d) [%d] %s", state, i, buf);
                    }
                }
                memset (buf, 0x00, 255);
                break;
        }
        usleep(1000);
    }
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Best Regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20140522/f60445da/attachment.html>


More information about the users mailing list