#include <fcntl.h>
#include <sys/socket.h>
#include <unistd.h>
#include <cerrno>
#include <climits>
#include "absl/base/attributes.h"
#include "absl/container/flat_hash_set.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "quiche/quic/core/io/socket.h"
#include "quiche/quic/core/io/socket_internal.h"
#include "quiche/quic/core/quic_types.h"
#include "quiche/quic/platform/api/quic_ip_address_family.h"
#include "quiche/quic/platform/api/quic_socket_address.h"
#include "quiche/common/platform/api/quiche_bug_tracker.h"
#include "quiche/common/platform/api/quiche_logging.h"
#if defined(__linux__) && defined(_GNU_SOURCE) && defined(__GLIBC_PREREQ)
#if __GLIBC_PREREQ(2, 10)
#define HAS_ACCEPT4
#endif
#endif
namespace quic::socket_api {
namespace {
PlatformSocklen;
PlatformSsizeT;
template <typename Result, typename... Args>
Result SyscallWrapper(Result (*syscall)(Args...), Args... args) { … }
int SyscallGetsockopt(int sockfd, int level, int optname, void* optval,
socklen_t* optlen) { … }
int SyscallSetsockopt(int sockfd, int level, int optname, const void* optval,
socklen_t optlen) { … }
int SyscallGetsockname(int sockfd, sockaddr* addr, socklen_t* addrlen) { … }
int SyscallAccept(int sockfd, sockaddr* addr, socklen_t* addrlen) { … }
int SyscallConnect(int sockfd, const sockaddr* addr, socklen_t addrlen) { … }
int SyscallBind(int sockfd, const sockaddr* addr, socklen_t addrlen) { … }
int SyscallListen(int sockfd, int backlog) { … }
ssize_t SyscallRecv(int sockfd, void* buf, size_t len, int flags) { … }
ssize_t SyscallSend(int sockfd, const void* buf, size_t len, int flags) { … }
ssize_t SyscallSendTo(int sockfd, const void* buf, size_t len, int flags,
const sockaddr* addr, socklen_t addrlen) { … }
absl::Status ToStatus(int error_number, absl::string_view method_name,
absl::flat_hash_set<int> unavailable_error_numbers = { … }
absl::Status LastSocketOperationError(
absl::string_view method_name,
absl::flat_hash_set<int> unavailable_error_numbers = { … }
absl::Status SetSocketFlags(SocketFd fd, int to_add, int to_remove) { … }
absl::StatusOr<SocketFd> CreateSocketWithFlags(IpAddressFamily address_family,
SocketProtocol protocol,
int flags) { … }
#if defined(HAS_ACCEPT4)
absl::StatusOr<AcceptResult> AcceptWithFlags(SocketFd fd, int flags) { … }
#endif
}
absl::Status SetSocketBlocking(SocketFd fd, bool blocking) { … }
absl::Status SetIpHeaderIncluded(SocketFd fd, IpAddressFamily address_family,
bool ip_header_included) { … }
absl::StatusOr<SocketFd> CreateSocket(IpAddressFamily address_family,
SocketProtocol protocol, bool blocking) { … }
absl::Status Close(SocketFd fd) { … }
}