Exemplo n.º 1
0
/**
	mainloop: read frames and process them
*/
static void mainLoop(void)
{
    int count;
    unsigned int numberOfTimeouts;

    numberOfTimeouts = 0;
    count = 3;

    while (count-- > 0) {
        for (;;) {
            fd_set fds;
            struct timeval tv;
            int r;

            FD_ZERO(&fds);
            FD_SET(fd, &fds);

            /* Timeout. */
            tv.tv_sec = 1;
            tv.tv_usec = 0;

            r = select(fd + 1, &fds, NULL, NULL, &tv);

            if (-1 == r) {
                if (EINTR == errno)
                    continue;

                errno_exit("select");
            }

            if (0 == r) {
                if (numberOfTimeouts <= 0) {
                    count++;
                } else {
                    fprintf(stderr, "select timeout\n");
                    exit(EXIT_FAILURE);
                }
            }
            if(continuous == 1) {
                count = 3;
            }

            if (frameRead())
                break;

            /* EAGAIN - continue select loop. */
        }
    }
}
Exemplo n.º 2
0
void Function::mainLoop(unsigned char* src)
{
    unsigned int count;
    count = 1;

    while (count-- > 0)
    {
            for (;;)
            {
                    fd_set fds;
                    struct timeval tv;
                    int r;

                    FD_ZERO(&fds);
                    FD_SET(fd, &fds);

                    /* Timeout. */
                    tv.tv_sec = 2;
                    tv.tv_usec = 0;

                    r = select(fd + 1, &fds, NULL, NULL, &tv);

                    if (-1 == r)
                    {
                            if (EINTR == errno)
                                    continue;
                            errno_exit("select");
                    }

                    if (0 == r)
                    {
                           QMessageBox::about(NULL,"Information","select timeout");
                            exit(EXIT_FAILURE);
                     }
                    if (frameRead(src))
                             break;
            }
       }
}