chromium/third_party/grpc/src/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc

// Copyright 2022 The gRPC Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <grpc/support/port_platform.h>

#include "src/core/lib/event_engine/posix_engine/ev_poll_posix.h"

#include <stdint.h>

#include <atomic>
#include <initializer_list>
#include <list>
#include <memory>
#include <utility>

#include "absl/container/inlined_vector.h"
#include "absl/functional/any_invocable.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_format.h"

#include <grpc/event_engine/event_engine.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>

#include "src/core/lib/event_engine/poller.h"
#include "src/core/lib/event_engine/posix_engine/event_poller.h"
#include "src/core/lib/event_engine/posix_engine/posix_engine_closure.h"
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/port.h"

#ifdef GRPC_POSIX_SOCKET_EV_POLL

#include <errno.h>
#include <limits.h>
#include <poll.h>
#include <sys/socket.h>
#include <unistd.h>

#include <grpc/support/alloc.h>

#include "src/core/lib/event_engine/common_closures.h"
#include "src/core/lib/event_engine/posix_engine/wakeup_fd_posix.h"
#include "src/core/lib/event_engine/posix_engine/wakeup_fd_posix_default.h"
#include "src/core/lib/event_engine/time_util.h"
#include "src/core/lib/gprpp/fork.h"
#include "src/core/lib/gprpp/global_config.h"
#include "src/core/lib/gprpp/status_helper.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/gprpp/time.h"

GPR_GLOBAL_CONFIG_DECLARE_STRING(grpc_poll_strategy);

static const intptr_t kClosureNotReady =;
static const intptr_t kClosureReady =;
static const int kPollinCheck =;
static const int kPolloutCheck =;

namespace grpc_event_engine {
namespace experimental {

Events;

class PollEventHandle : public EventHandle {};

namespace {
// Only used when GRPC_ENABLE_FORK_SUPPORT=1
std::list<PollPoller*> fork_poller_list;

// Only used when GRPC_ENABLE_FORK_SUPPORT=1
PollEventHandle* fork_fd_list_head =;
gpr_mu fork_fd_list_mu;

void ForkFdListAddHandle(PollEventHandle* handle) {}

void ForkFdListRemoveHandle(PollEventHandle* handle) {}

void ForkPollerListAddPoller(PollPoller* poller) {}

void ForkPollerListRemovePoller(PollPoller* poller) {}

// Returns the number of milliseconds elapsed between now and start timestamp.
int PollElapsedTimeToMillis(grpc_core::Timestamp start) {}

bool InitPollPollerPosix();

// Called by the child process's post-fork handler to close open fds,
// including the global epoll fd of each poller. This allows gRPC to shutdown
// in the child process without interfering with connections or RPCs ongoing
// in the parent.
void ResetEventManagerOnFork() {}

// It is possible that GLIBC has epoll but the underlying kernel doesn't.
// Create epoll_fd to make sure epoll support is available
bool InitPollPollerPosix() {}

}  // namespace

EventHandle* PollPoller::CreateHandle(int fd, absl::string_view /*name*/,
                                      bool track_err) {}

void PollEventHandle::OrphanHandle(PosixEngineClosure* on_done, int* release_fd,
                                   absl::string_view /*reason*/) {}

int PollEventHandle::NotifyOnLocked(PosixEngineClosure** st,
                                    PosixEngineClosure* closure) {}

// returns 1 if state becomes not ready
int PollEventHandle::SetReadyLocked(PosixEngineClosure** st) {}

void PollEventHandle::ShutdownHandle(absl::Status why) {}

void PollEventHandle::NotifyOnRead(PosixEngineClosure* on_read) {}

void PollEventHandle::NotifyOnWrite(PosixEngineClosure* on_write) {}

void PollEventHandle::NotifyOnError(PosixEngineClosure* on_error) {}

void PollEventHandle::SetReadable() {}

void PollEventHandle::SetWritable() {}

void PollEventHandle::SetHasError() {}

uint32_t PollEventHandle::BeginPollLocked(uint32_t read_mask,
                                          uint32_t write_mask) {}

bool PollEventHandle::EndPollLocked(bool got_read, bool got_write) {}

void PollPoller::KickExternal(bool ext) {}

void PollPoller::Kick() {}

void PollPoller::PollerHandlesListAddHandle(PollEventHandle* handle) {}

void PollPoller::PollerHandlesListRemoveHandle(PollEventHandle* handle) {}

PollPoller::PollPoller(Scheduler* scheduler)
    :{}

PollPoller::PollPoller(Scheduler* scheduler, bool use_phony_poll)
    :{}

PollPoller::~PollPoller() {}

Poller::WorkResult PollPoller::Work(
    EventEngine::Duration timeout,
    absl::FunctionRef<void()> schedule_poll_again) {}

void PollPoller::Shutdown() {}

PollPoller* MakePollPoller(Scheduler* scheduler, bool use_phony_poll) {}

}  // namespace experimental
}  // namespace grpc_event_engine

#else  // GRPC_POSIX_SOCKET_EV_POLL

#include "src/core/lib/gprpp/crash.h"

namespace grpc_event_engine {
namespace experimental {

PollPoller::PollPoller(Scheduler* /* engine */) {
  grpc_core::Crash("unimplemented");
}

void PollPoller::Shutdown() { grpc_core::Crash("unimplemented"); }

PollPoller::~PollPoller() { grpc_core::Crash("unimplemented"); }

EventHandle* PollPoller::CreateHandle(int /*fd*/, absl::string_view /*name*/,
                                      bool /*track_err*/) {
  grpc_core::Crash("unimplemented");
}

Poller::WorkResult PollPoller::Work(
    EventEngine::Duration /*timeout*/,
    absl::FunctionRef<void()> /*schedule_poll_again*/) {
  grpc_core::Crash("unimplemented");
}

void PollPoller::Kick() { grpc_core::Crash("unimplemented"); }

// If GRPC_LINUX_EPOLL is not defined, it means epoll is not available. Return
// nullptr.
PollPoller* MakePollPoller(Scheduler* /*scheduler*/,
                           bool /* use_phony_poll */) {
  return nullptr;
}

void PollPoller::KickExternal(bool /*ext*/) {
  grpc_core::Crash("unimplemented");
}

void PollPoller::PollerHandlesListAddHandle(PollEventHandle* /*handle*/) {
  grpc_core::Crash("unimplemented");
}

void PollPoller::PollerHandlesListRemoveHandle(PollEventHandle* /*handle*/) {
  grpc_core::Crash("unimplemented");
}

}  // namespace experimental
}  // namespace grpc_event_engine

#endif  // GRPC_POSIX_SOCKET_EV_POLL