mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-01 13:57:32 +00:00
Bug 1590984 - Use poll() instead of select() in WebRTC code r=drno
The use of select() was leading to crashes when the file descriptor value was larger than FD_SETSIZE. Recent versions of glibc have checks in the FD_CLR(), FD_SET() and FD_ISSET() macros that will abort() the program instead of doing an out-of-bounds access. poll() doesn't have limitations on the file descriptor values and provides behavior that is otherwise identical to select() thus solving the problem. Differential Revision: https://phabricator.services.mozilla.com/D50798 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
d84e72f929
commit
550a8ee421
@ -12,6 +12,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
@ -72,16 +73,13 @@ void DeviceInfoLinux::HandleEvent(inotify_event* event, int fd)
|
||||
|
||||
int DeviceInfoLinux::EventCheck(int fd)
|
||||
{
|
||||
struct timeval timeout;
|
||||
fd_set rfds;
|
||||
struct pollfd fds = {
|
||||
.fd = fd,
|
||||
.events = POLLIN,
|
||||
.revents = 0
|
||||
};
|
||||
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 100000;
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(fd, &rfds);
|
||||
|
||||
return select(fd+1, &rfds, NULL, NULL, &timeout);
|
||||
return poll(&fds, 1, 100);
|
||||
}
|
||||
|
||||
int DeviceInfoLinux::HandleEvents(int fd)
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
@ -370,25 +371,23 @@ bool VideoCaptureModuleV4L2::CaptureThread(void* obj) {
|
||||
}
|
||||
bool VideoCaptureModuleV4L2::CaptureProcess() {
|
||||
int retVal = 0;
|
||||
fd_set rSet;
|
||||
struct timeval timeout;
|
||||
struct pollfd rSet;
|
||||
|
||||
rtc::CritScope cs(&_captureCritSect);
|
||||
|
||||
FD_ZERO(&rSet);
|
||||
FD_SET(_deviceFd, &rSet);
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_usec = 0;
|
||||
rSet.fd = _deviceFd;
|
||||
rSet.events = POLLIN;
|
||||
rSet.revents = 0;
|
||||
|
||||
retVal = select(_deviceFd + 1, &rSet, NULL, NULL, &timeout);
|
||||
retVal = poll(&rSet, 1, 1000);
|
||||
if (retVal < 0 && errno != EINTR) // continue if interrupted
|
||||
{
|
||||
// select failed
|
||||
// poll failed
|
||||
return false;
|
||||
} else if (retVal == 0) {
|
||||
// select timed out
|
||||
// poll timed out
|
||||
return true;
|
||||
} else if (!FD_ISSET(_deviceFd, &rSet)) {
|
||||
} else if (!(rSet.revents & POLLIN)) {
|
||||
// not event on camera handle
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user