#include "net/socket/tcp_socket.h"
#include <errno.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <algorithm>
#include <memory>
#include "base/atomicops.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "net/base/address_list.h"
#include "net/base/io_buffer.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/base/network_activity_monitor.h"
#include "net/base/network_change_notifier.h"
#include "net/base/sockaddr_storage.h"
#include "net/base/sys_addrinfo.h"
#include "net/base/tracing.h"
#include "net/http/http_util.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_source.h"
#include "net/log/net_log_source_type.h"
#include "net/log/net_log_values.h"
#include "net/socket/socket_net_log_params.h"
#include "net/socket/socket_options.h"
#include "net/socket/socket_posix.h"
#include "net/socket/socket_tag.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#if BUILDFLAG(IS_ANDROID)
#include "net/android/network_library.h"
#endif
#if !defined(TCPI_OPT_SYN_DATA)
#define TCPI_OPT_SYN_DATA …
#endif
#if defined(TCP_INFO) && !BUILDFLAG(IS_FUCHSIA)
#define HAVE_TCP_INFO
#endif
namespace net {
namespace {
bool SetTCPKeepAlive(int fd, bool enable, int delay) { … }
#if defined(HAVE_TCP_INFO)
base::TimeDelta GetTransportRtt(SocketDescriptor fd) { … }
#endif
}
TCPSocketPosix::TCPSocketPosix(
std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,
NetLog* net_log,
const NetLogSource& source)
: … { … }
TCPSocketPosix::TCPSocketPosix(
std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,
NetLogWithSource net_log_source)
: … { … }
TCPSocketPosix::~TCPSocketPosix() { … }
int TCPSocketPosix::Open(AddressFamily family) { … }
int TCPSocketPosix::BindToNetwork(handles::NetworkHandle network) { … }
int TCPSocketPosix::AdoptConnectedSocket(SocketDescriptor socket,
const IPEndPoint& peer_address) { … }
int TCPSocketPosix::AdoptUnconnectedSocket(SocketDescriptor socket) { … }
int TCPSocketPosix::Bind(const IPEndPoint& address) { … }
int TCPSocketPosix::Listen(int backlog) { … }
int TCPSocketPosix::Accept(std::unique_ptr<TCPSocketPosix>* tcp_socket,
IPEndPoint* address,
CompletionOnceCallback callback) { … }
int TCPSocketPosix::Connect(const IPEndPoint& address,
CompletionOnceCallback callback) { … }
bool TCPSocketPosix::IsConnected() const { … }
bool TCPSocketPosix::IsConnectedAndIdle() const { … }
int TCPSocketPosix::Read(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback) { … }
int TCPSocketPosix::ReadIfReady(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback) { … }
int TCPSocketPosix::CancelReadIfReady() { … }
int TCPSocketPosix::Write(
IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback,
const NetworkTrafficAnnotationTag& traffic_annotation) { … }
int TCPSocketPosix::GetLocalAddress(IPEndPoint* address) const { … }
int TCPSocketPosix::GetPeerAddress(IPEndPoint* address) const { … }
int TCPSocketPosix::SetDefaultOptionsForServer() { … }
void TCPSocketPosix::SetDefaultOptionsForClient() { … }
int TCPSocketPosix::AllowAddressReuse() { … }
int TCPSocketPosix::SetReceiveBufferSize(int32_t size) { … }
int TCPSocketPosix::SetSendBufferSize(int32_t size) { … }
bool TCPSocketPosix::SetKeepAlive(bool enable, int delay) { … }
bool TCPSocketPosix::SetNoDelay(bool no_delay) { … }
int TCPSocketPosix::SetIPv6Only(bool ipv6_only) { … }
void TCPSocketPosix::Close() { … }
bool TCPSocketPosix::IsValid() const { … }
void TCPSocketPosix::DetachFromThread() { … }
void TCPSocketPosix::StartLoggingMultipleConnectAttempts(
const AddressList& addresses) { … }
void TCPSocketPosix::EndLoggingMultipleConnectAttempts(int net_error) { … }
SocketDescriptor TCPSocketPosix::ReleaseSocketDescriptorForTesting() { … }
SocketDescriptor TCPSocketPosix::SocketDescriptorForTesting() const { … }
void TCPSocketPosix::ApplySocketTag(const SocketTag& tag) { … }
void TCPSocketPosix::AcceptCompleted(
std::unique_ptr<TCPSocketPosix>* tcp_socket,
IPEndPoint* address,
CompletionOnceCallback callback,
int rv) { … }
int TCPSocketPosix::HandleAcceptCompleted(
std::unique_ptr<TCPSocketPosix>* tcp_socket,
IPEndPoint* address,
int rv) { … }
int TCPSocketPosix::BuildTcpSocketPosix(
std::unique_ptr<TCPSocketPosix>* tcp_socket,
IPEndPoint* address) { … }
void TCPSocketPosix::ConnectCompleted(CompletionOnceCallback callback, int rv) { … }
int TCPSocketPosix::HandleConnectCompleted(int rv) { … }
void TCPSocketPosix::LogConnectBegin(const AddressList& addresses) const { … }
void TCPSocketPosix::LogConnectEnd(int net_error) const { … }
void TCPSocketPosix::ReadCompleted(const scoped_refptr<IOBuffer>& buf,
CompletionOnceCallback callback,
int rv) { … }
void TCPSocketPosix::ReadIfReadyCompleted(CompletionOnceCallback callback,
int rv) { … }
int TCPSocketPosix::HandleReadCompleted(IOBuffer* buf, int rv) { … }
void TCPSocketPosix::HandleReadCompletedHelper(int rv) { … }
void TCPSocketPosix::WriteCompleted(const scoped_refptr<IOBuffer>& buf,
CompletionOnceCallback callback,
int rv) { … }
int TCPSocketPosix::HandleWriteCompleted(IOBuffer* buf, int rv) { … }
void TCPSocketPosix::NotifySocketPerformanceWatcher() { … }
bool TCPSocketPosix::GetEstimatedRoundTripTime(base::TimeDelta* out_rtt) const { … }
}