chromium/third_party/grpc/src/src/core/lib/iomgr/ev_posix.cc

//
//
// Copyright 2015 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 <grpc/grpc.h>

#include "src/core/lib/iomgr/port.h"

#ifdef GRPC_POSIX_SOCKET_EV

#include <string.h>

#include "absl/strings/str_format.h"

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/global_config.h"
#include "src/core/lib/iomgr/ev_epoll1_linux.h"
#include "src/core/lib/iomgr/ev_poll_posix.h"
#include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/iomgr/internal_errqueue.h"

GPR_GLOBAL_CONFIG_DEFINE_STRING()

grpc_core::DebugOnlyTraceFlag grpc_polling_trace(
    false, "polling");  // Disabled by default

// Traces fd create/close operations
grpc_core::DebugOnlyTraceFlag grpc_fd_trace(false, "fd_trace");
grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount(false, "fd_refcount");
grpc_core::DebugOnlyTraceFlag grpc_polling_api_trace(false, "polling_api");

// Polling API trace only enabled in debug builds
#ifndef NDEBUG
#define GRPC_POLLING_API_TRACE(format, ...)
#else
#define GRPC_POLLING_API_TRACE
#endif  // NDEBUG

/// Default poll() function - a pointer so that it can be overridden by some
/// tests
#ifndef GPR_AIX
grpc_poll_function_type grpc_poll_function =;
#else
int aix_poll(struct pollfd fds[], nfds_t nfds, int timeout) {
  return poll(fds, nfds, timeout);
}
grpc_poll_function_type grpc_poll_function = aix_poll;
#endif  // GPR_AIX

grpc_wakeup_fd grpc_global_wakeup_fd;

static const grpc_event_engine_vtable* g_event_engine =;
static gpr_once g_choose_engine =;

// The global array of event-engine factories. Each entry is a pair with a name
// and an event-engine generator function (nullptr if there is no generator
// registered for this name). The middle entries are the engines predefined by
// open-source gRPC. The head entries represent an opportunity for specific
// high-priority custom pollers to be added by the initializer plugins of
// custom-built gRPC libraries. The tail entries represent the same, but for
// low-priority custom pollers. The actual poller selected is either the first
// available one in the list if no specific poller is requested, or the first
// specific poller that is requested by name in the GRPC_POLL_STRATEGY
// environment variable if that variable is set (which should be a
// comma-separated list of one or more event engine names)
static const grpc_event_engine_vtable* g_vtables[] =;

static void add(const char* beg, const char* end, char*** ss, size_t* ns) {}

static void split(const char* s, char*** ss, size_t* ns) {}

static bool is(const char* want, const char* have) {}

static void try_engine(const char* engine) {}

// Call this before calling grpc_event_engine_init()
void grpc_register_event_engine_factory(const grpc_event_engine_vtable* vtable,
                                        bool add_at_head) {}

// If grpc_event_engine_init() has been called, returns the poll_strategy_name.
//  Otherwise, returns nullptr.
const char* grpc_get_poll_strategy_name() {}

void grpc_event_engine_init(void) {}

void grpc_event_engine_shutdown(void) {}

bool grpc_event_engine_can_track_errors(void) {}

bool grpc_event_engine_run_in_background(void) {}

grpc_fd* grpc_fd_create(int fd, const char* name, bool track_err) {}

int grpc_fd_wrapped_fd(grpc_fd* fd) {}

void grpc_fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
                    const char* reason) {}

void grpc_fd_set_pre_allocated(grpc_fd* fd) {}

void grpc_fd_shutdown(grpc_fd* fd, grpc_error_handle why) {}

bool grpc_fd_is_shutdown(grpc_fd* fd) {}

void grpc_fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) {}

void grpc_fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) {}

void grpc_fd_notify_on_error(grpc_fd* fd, grpc_closure* closure) {}

void grpc_fd_set_readable(grpc_fd* fd) {}

void grpc_fd_set_writable(grpc_fd* fd) {}

void grpc_fd_set_error(grpc_fd* fd) {}

static size_t pollset_size(void) {}

static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) {}

static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) {}

static void pollset_destroy(grpc_pollset* pollset) {}

static grpc_error_handle pollset_work(grpc_pollset* pollset,
                                      grpc_pollset_worker** worker,
                                      grpc_core::Timestamp deadline) {}

static grpc_error_handle pollset_kick(grpc_pollset* pollset,
                                      grpc_pollset_worker* specific_worker) {}

void grpc_pollset_add_fd(grpc_pollset* pollset, struct grpc_fd* fd) {}

void pollset_global_init() {}
void pollset_global_shutdown() {}

grpc_pollset_vtable grpc_posix_pollset_vtable =;

static grpc_pollset_set* pollset_set_create(void) {}

static void pollset_set_destroy(grpc_pollset_set* pollset_set) {}

static void pollset_set_add_pollset(grpc_pollset_set* pollset_set,
                                    grpc_pollset* pollset) {}

static void pollset_set_del_pollset(grpc_pollset_set* pollset_set,
                                    grpc_pollset* pollset) {}

static void pollset_set_add_pollset_set(grpc_pollset_set* bag,
                                        grpc_pollset_set* item) {}

static void pollset_set_del_pollset_set(grpc_pollset_set* bag,
                                        grpc_pollset_set* item) {}

grpc_pollset_set_vtable grpc_posix_pollset_set_vtable =;

void grpc_pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) {}

void grpc_pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) {}

bool grpc_is_any_background_poller_thread(void) {}

bool grpc_add_closure_to_background_poller(grpc_closure* closure,
                                           grpc_error_handle error) {}

void grpc_shutdown_background_closure(void) {}

#endif  // GRPC_POSIX_SOCKET_EV