chromium/third_party/grpc/src/src/core/lib/iomgr/socket_utils_common_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 "src/core/lib/iomgr/port.h"

#ifdef GRPC_POSIX_SOCKET_UTILS_COMMON

#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <netinet/in.h>

#include "src/core/lib/iomgr/socket_utils.h"
#include "src/core/lib/iomgr/socket_utils_posix.h"
#ifdef GRPC_LINUX_TCP_H
#include <linux/tcp.h>
#else
#include <netinet/tcp.h>
#endif
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

#include <string>

#include <grpc/event_engine/endpoint_config.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>

#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/iomgr/sockaddr.h"

// set a socket to use zerocopy
grpc_error_handle grpc_set_socket_zerocopy(int fd) {}

// set a socket to non blocking mode
grpc_error_handle grpc_set_socket_nonblocking(int fd, int non_blocking) {}

grpc_error_handle grpc_set_socket_no_sigpipe_if_possible(int fd) {}

grpc_error_handle grpc_set_socket_ip_pktinfo_if_possible(int fd) {}

grpc_error_handle grpc_set_socket_ipv6_recvpktinfo_if_possible(int fd) {}

grpc_error_handle grpc_set_socket_sndbuf(int fd, int buffer_size_bytes) {}

grpc_error_handle grpc_set_socket_rcvbuf(int fd, int buffer_size_bytes) {}

// set a socket to close on exec
grpc_error_handle grpc_set_socket_cloexec(int fd, int close_on_exec) {}

// set a socket to reuse old addresses
grpc_error_handle grpc_set_socket_reuse_addr(int fd, int reuse) {}

// set a socket to reuse old addresses
grpc_error_handle grpc_set_socket_reuse_port(int fd, int reuse) {}

static gpr_once g_probe_so_reuesport_once =;
static int g_support_so_reuseport =;

void probe_so_reuseport_once(void) {}

bool grpc_is_socket_reuse_port_supported() {}

// disable nagle
grpc_error_handle grpc_set_socket_low_latency(int fd, int low_latency) {}

// The default values for TCP_USER_TIMEOUT are currently configured to be in
// line with the default values of KEEPALIVE_TIMEOUT as proposed in
// https://github.com/grpc/proposal/blob/master/A18-tcp-user-timeout.md
#define DEFAULT_CLIENT_TCP_USER_TIMEOUT_MS
#define DEFAULT_SERVER_TCP_USER_TIMEOUT_MS

static int g_default_client_tcp_user_timeout_ms =;
static int g_default_server_tcp_user_timeout_ms =;
static bool g_default_client_tcp_user_timeout_enabled =;
static bool g_default_server_tcp_user_timeout_enabled =;

#if GPR_LINUX == 1
// For Linux, it will be detected to support TCP_USER_TIMEOUT
#ifndef TCP_USER_TIMEOUT
#define TCP_USER_TIMEOUT
#endif
#define SOCKET_SUPPORTS_TCP_USER_TIMEOUT_DEFAULT
#else
// For non-Linux, TCP_USER_TIMEOUT will be used if TCP_USER_TIMEOUT is defined.
#ifdef TCP_USER_TIMEOUT
#define SOCKET_SUPPORTS_TCP_USER_TIMEOUT_DEFAULT
#else
#define TCP_USER_TIMEOUT
#define SOCKET_SUPPORTS_TCP_USER_TIMEOUT_DEFAULT
#endif  // TCP_USER_TIMEOUT
#endif  // GPR_LINUX == 1

// Whether the socket supports TCP_USER_TIMEOUT option.
// (0: don't know, 1: support, -1: not support)
static std::atomic<int> g_socket_supports_tcp_user_timeout(
    SOCKET_SUPPORTS_TCP_USER_TIMEOUT_DEFAULT);

void config_default_tcp_user_timeout(bool enable, int timeout, bool is_client) {}

// Set TCP_USER_TIMEOUT
grpc_error_handle grpc_set_socket_tcp_user_timeout(
    int fd, const grpc_core::PosixTcpOptions& options, bool is_client) {}

// set a socket using a grpc_socket_mutator
grpc_error_handle grpc_set_socket_with_mutator(int fd, grpc_fd_usage usage,
                                               grpc_socket_mutator* mutator) {}

grpc_error_handle grpc_apply_socket_mutator_in_args(
    int fd, grpc_fd_usage usage, const grpc_core::PosixTcpOptions& options) {}

static gpr_once g_probe_ipv6_once =;
static int g_ipv6_loopback_available;

static void probe_ipv6_once(void) {}

int grpc_ipv6_loopback_available(void) {}

static grpc_error_handle error_for_fd(int fd,
                                      const grpc_resolved_address* addr) {}

grpc_error_handle grpc_create_dualstack_socket(
    const grpc_resolved_address* resolved_addr, int type, int protocol,
    grpc_dualstack_mode* dsmode, int* newfd) {}

static int create_socket(grpc_socket_factory* factory, int domain, int type,
                         int protocol) {}

grpc_error_handle grpc_create_dualstack_socket_using_factory(
    grpc_socket_factory* factory, const grpc_resolved_address* resolved_addr,
    int type, int protocol, grpc_dualstack_mode* dsmode, int* newfd) {}

#endif