--- DeviceReadBuffer.cpp.orig 2012-10-03 19:40:49.000000000 -0400 +++ DeviceReadBuffer.cpp 2012-10-03 19:37:28.000000000 -0400 @@ -421,7 +421,7 @@ "mingw DeviceReadBuffer::Poll is not implemented"); return false; #else - bool retval = true; + bool retval; MythTimer timer; timer.start(); @@ -441,6 +441,7 @@ polls[1].revents = 0; } + retval = true; while (true) { polls[0].revents = 0; @@ -455,65 +456,75 @@ int ret = poll(polls, poll_cnt, timeout); - if (polls[0].revents & (POLLHUP | POLLNVAL)) - { - LOG(VB_GENERAL, LOG_ERR, LOC + "poll error"); - error = true; - return true; - } - if (!dorun || !IsOpen() || IsPauseRequested()) { - retval = false; - break; // are we supposed to pause, stop, etc. + return false; // are we supposed to pause, stop, etc. } - - if (polls[0].revents & POLLPRI) + + if (ret < 0) // error { - readerCB->PriorityEvent(polls[0].fd); - } + if ((EOVERFLOW == errno)) + // TODO shouldn't this lock and then set error=true? + break; // we have an error to handle + + if ((EAGAIN == errno) || (EINTR == errno)) + continue; // errors that tell you to try again - if (polls[0].revents & POLLIN) + usleep(2500 /*2.5 ms*/); + } + else if (ret == 0) // timeout { - if (ret > 0) - break; // we have data to read :) - else if (ret < 0) - { - if ((EOVERFLOW == errno)) - break; // we have an error to handle - - if ((EAGAIN == errno) || (EINTR == errno)) - continue; // errors that tell you to try again - - usleep(2500 /*2.5 ms*/); - } - else // ret == 0 - { - if (poll_timeout_is_error && - (timer.elapsed() >= (int)max_poll_wait)) - { - LOG(VB_GENERAL, LOG_ERR, LOC + "Poll giving up 1"); - QMutexLocker locker(&lock); - error = true; - return true; - } + if (poll_timeout_is_error && + (timer.elapsed() >= (int)max_poll_wait)) + { + LOG(VB_GENERAL, LOG_ERR, LOC + "Poll giving up 1"); + QMutexLocker locker(&lock); + error = true; + return true; } } - - // Clear out any pending pipe reads - if ((poll_cnt > 1) && (polls[1].revents & POLLIN)) + else // normal return - some event available { - char dummy[128]; - int cnt = (wake_pipe_flags[0] & O_NONBLOCK) ? 128 : 1; - cnt = ::read(wake_pipe[0], dummy, cnt); - } + if (polls[0].revents & POLLHUP) + { + LOG(VB_GENERAL, LOG_ERR, LOC + "poll eof (POLLHUP)"); + break; + } + else if (polls[0].revents & POLLNVAL) + { + LOG(VB_GENERAL, LOG_ERR, LOC + "poll error (POLLINVAL)"); + QMutexLocker locker(&lock); + error = true; + return true; + } - if (poll_timeout_is_error && (timer.elapsed() >= (int)max_poll_wait)) - { - LOG(VB_GENERAL, LOG_ERR, LOC + "Poll giving up 2"); - QMutexLocker locker(&lock); - error = true; - return true; + if (polls[0].revents & POLLPRI) + { + readerCB->PriorityEvent(polls[0].fd); + } + + // Clear out any pending pipe reads + if (polls[1].revents & POLLIN) + { + char dummy[128]; + int cnt = (wake_pipe_flags[0] & O_NONBLOCK) ? 128 : 1; + cnt = ::read(wake_pipe[0], dummy, cnt); + } + + // we have data to read :) + if (polls[0].revents & POLLIN) + { + break; + } + + if (poll_timeout_is_error && + (timer.elapsed() >= (int)max_poll_wait)) + { + LOG(VB_GENERAL, LOG_ERR, LOC + "Poll giving up 2"); + QMutexLocker locker(&lock); + error = true; + return true; + } } }