#include "base/files/file_descriptor_watcher_posix.h"
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ref.h"
#include "base/message_loop/message_pump_for_io.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/current_thread.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread_checker.h"
#include "base/threading/thread_restrictions.h"
#include "third_party/abseil-cpp/absl/base/attributes.h"
namespace base {
namespace {
ABSL_CONST_INIT thread_local FileDescriptorWatcher* fd_watcher = …;
}
class FileDescriptorWatcher::Controller::Watcher
: public MessagePumpForIO::FdWatcher,
public CurrentThread::DestructionObserver { … };
FileDescriptorWatcher::Controller::Watcher::Watcher(
WeakPtr<Controller> controller,
base::WaitableEvent& on_destroyed,
MessagePumpForIO::Mode mode,
int fd)
: … { … }
FileDescriptorWatcher::Controller::Watcher::~Watcher() { … }
void FileDescriptorWatcher::Controller::Watcher::StartWatching() { … }
void FileDescriptorWatcher::Controller::Watcher::OnFileCanReadWithoutBlocking(
int fd) { … }
void FileDescriptorWatcher::Controller::Watcher::OnFileCanWriteWithoutBlocking(
int fd) { … }
void FileDescriptorWatcher::Controller::Watcher::
WillDestroyCurrentMessageLoop() { … }
FileDescriptorWatcher::Controller::Controller(MessagePumpForIO::Mode mode,
int fd,
const RepeatingClosure& callback)
: … { … }
FileDescriptorWatcher::Controller::~Controller() { … }
void FileDescriptorWatcher::Controller::StartWatching() { … }
void FileDescriptorWatcher::Controller::RunCallback() { … }
FileDescriptorWatcher::FileDescriptorWatcher(
scoped_refptr<SingleThreadTaskRunner> io_thread_task_runner)
: … { … }
FileDescriptorWatcher::~FileDescriptorWatcher() = default;
std::unique_ptr<FileDescriptorWatcher::Controller>
FileDescriptorWatcher::WatchReadable(int fd, const RepeatingClosure& callback) { … }
std::unique_ptr<FileDescriptorWatcher::Controller>
FileDescriptorWatcher::WatchWritable(int fd, const RepeatingClosure& callback) { … }
#if DCHECK_IS_ON()
void FileDescriptorWatcher::AssertAllowed() { … }
#endif
}