Extend use of poll() to Apple systems in addition to Linux and Fuchsia

To address the limitations of select(), poll() is now used for Apple
(MacOS and iOS) systems in the PhysicalSocketServer.

Bug: webrtc:15421, webrtc:15908
Change-Id: Ic6703a08653ca608a714ea37ecbbfeaf29743c1f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/316480
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com>
Cr-Commit-Position: refs/heads/main@{#42075}
This commit is contained in:
Byoungchan Lee 2024-04-16 11:06:08 +09:00 committed by WebRTC LUCI CQ
parent e33313f801
commit d86c0cdbde
2 changed files with 15 additions and 10 deletions

View File

@ -98,15 +98,15 @@ int64_t GetSocketRecvTimestamp(int socket) {
typedef char* SockOptArg; typedef char* SockOptArg;
#endif #endif
#if defined(WEBRTC_USE_EPOLL) #if defined(WEBRTC_LINUX)
// POLLRDHUP / EPOLLRDHUP are only defined starting with Linux 2.6.17. // POLLRDHUP / EPOLLRDHUP are only defined starting with Linux 2.6.17.
#if !defined(POLLRDHUP) #if !defined(POLLRDHUP)
#define POLLRDHUP 0x2000 #define POLLRDHUP 0x2000
#endif #endif // !defined(POLLRDHUP)
#if !defined(EPOLLRDHUP) #if !defined(EPOLLRDHUP)
#define EPOLLRDHUP 0x2000 #define EPOLLRDHUP 0x2000
#endif #endif // !defined(EPOLLRDHUP)
#endif #endif // defined(WEBRTC_LINUX)
namespace { namespace {
@ -1489,7 +1489,15 @@ static void ProcessEvents(Dispatcher* dispatcher,
static void ProcessPollEvents(Dispatcher* dispatcher, const pollfd& pfd) { static void ProcessPollEvents(Dispatcher* dispatcher, const pollfd& pfd) {
bool readable = (pfd.revents & (POLLIN | POLLPRI)); bool readable = (pfd.revents & (POLLIN | POLLPRI));
bool writable = (pfd.revents & POLLOUT); bool writable = (pfd.revents & POLLOUT);
bool error = (pfd.revents & (POLLRDHUP | POLLERR | POLLHUP));
// Linux and Fuchsia define POLLRDHUP, which is set when the peer has
// disconnected. On other platforms, we only check for POLLHUP.
#if defined(WEBRTC_LINUX) || defined(WEBRTC_FUCHSIA)
constexpr short kEvents = POLLRDHUP | POLLERR | POLLHUP;
#else
constexpr short kEvents = POLLERR | POLLHUP;
#endif
bool error = (pfd.revents & kEvents);
ProcessEvents(dispatcher, readable, writable, error, error); ProcessEvents(dispatcher, readable, writable, error, error);
} }

View File

@ -23,7 +23,7 @@
#include <sys/epoll.h> #include <sys/epoll.h>
#define WEBRTC_USE_EPOLL 1 #define WEBRTC_USE_EPOLL 1
#elif defined(WEBRTC_FUCHSIA) #elif defined(WEBRTC_FUCHSIA) || defined(WEBRTC_MAC)
// Fuchsia implements select and poll but not epoll, and testing shows that poll // Fuchsia implements select and poll but not epoll, and testing shows that poll
// is faster than select. // is faster than select.
#include <poll.h> #include <poll.h>
@ -31,7 +31,7 @@
#define WEBRTC_USE_POLL 1 #define WEBRTC_USE_POLL 1
#else #else
// On other POSIX systems, use select by default. // On other POSIX systems, use select by default.
#endif // WEBRTC_LINUX, WEBRTC_FUCHSIA #endif // WEBRTC_LINUX, WEBRTC_FUCHSIA, WEBRTC_MAC
#endif // WEBRTC_POSIX #endif // WEBRTC_POSIX
#include <array> #include <array>
@ -125,9 +125,6 @@ class RTC_EXPORT PhysicalSocketServer : public SocketServer {
const int epoll_fd_ = INVALID_SOCKET; const int epoll_fd_ = INVALID_SOCKET;
#elif defined(WEBRTC_USE_POLL) #elif defined(WEBRTC_USE_POLL)
void AddPoll(Dispatcher* dispatcher, uint64_t key);
void RemovePoll(Dispatcher* dispatcher);
void UpdatePoll(Dispatcher* dispatcher, uint64_t key);
bool WaitPoll(int cmsWait, bool process_io); bool WaitPoll(int cmsWait, bool process_io);
#endif // WEBRTC_USE_EPOLL, WEBRTC_USE_POLL #endif // WEBRTC_USE_EPOLL, WEBRTC_USE_POLL