#include "services/network/tcp_connected_socket.h"
#include <algorithm>
#include <optional>
#include <utility>
#include "base/check_op.h"
#include "base/functional/bind.h"
#include "base/numerics/safe_conversions.h"
#include "net/base/net_errors.h"
#include "net/log/net_log.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/client_socket_handle.h"
#include "services/network/public/mojom/tcp_socket.mojom.h"
#include "services/network/tls_client_socket.h"
namespace network {
namespace {
int ClampTCPBufferSize(int requested_buffer_size) { … }
int ConfigureSocket(
net::TransportClientSocket* socket,
const mojom::TCPConnectedSocketOptions* tcp_connected_socket_options) { … }
}
const int TCPConnectedSocket::kMaxBufferSize = …;
TCPConnectedSocket::TCPConnectedSocket(
mojo::PendingRemote<mojom::SocketObserver> observer,
net::NetLog* net_log,
TLSSocketFactory* tls_socket_factory,
net::ClientSocketFactory* client_socket_factory,
const net::NetworkTrafficAnnotationTag& traffic_annotation)
: … { … }
TCPConnectedSocket::TCPConnectedSocket(
mojo::PendingRemote<mojom::SocketObserver> observer,
std::unique_ptr<net::TransportClientSocket> socket,
mojo::ScopedDataPipeProducerHandle receive_pipe_handle,
mojo::ScopedDataPipeConsumerHandle send_pipe_handle,
const net::NetworkTrafficAnnotationTag& traffic_annotation)
: … { … }
TCPConnectedSocket::~TCPConnectedSocket() { … }
void TCPConnectedSocket::Connect(
const std::optional<net::IPEndPoint>& local_addr,
const net::AddressList& remote_addr_list,
mojom::TCPConnectedSocketOptionsPtr tcp_connected_socket_options,
mojom::NetworkContext::CreateTCPConnectedSocketCallback callback) { … }
void TCPConnectedSocket::ConnectWithSocket(
std::unique_ptr<net::TransportClientSocket> socket,
mojom::TCPConnectedSocketOptionsPtr tcp_connected_socket_options,
mojom::NetworkContext::CreateTCPConnectedSocketCallback callback) { … }
void TCPConnectedSocket::UpgradeToTLS(
const net::HostPortPair& host_port_pair,
mojom::TLSClientSocketOptionsPtr socket_options,
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
mojo::PendingReceiver<mojom::TLSClientSocket> receiver,
mojo::PendingRemote<mojom::SocketObserver> observer,
mojom::TCPConnectedSocket::UpgradeToTLSCallback callback) { … }
void TCPConnectedSocket::SetSendBufferSize(int send_buffer_size,
SetSendBufferSizeCallback callback) { … }
void TCPConnectedSocket::SetReceiveBufferSize(
int send_buffer_size,
SetSendBufferSizeCallback callback) { … }
void TCPConnectedSocket::SetNoDelay(bool no_delay,
SetNoDelayCallback callback) { … }
void TCPConnectedSocket::SetKeepAlive(bool enable,
int32_t delay_secs,
SetKeepAliveCallback callback) { … }
void TCPConnectedSocket::OnConnectCompleted(int result) { … }
void TCPConnectedSocket::OnNetworkReadError(int net_error) { … }
void TCPConnectedSocket::OnNetworkWriteError(int net_error) { … }
void TCPConnectedSocket::OnShutdown() { … }
const net::StreamSocket* TCPConnectedSocket::BorrowSocket() { … }
std::unique_ptr<net::StreamSocket> TCPConnectedSocket::TakeSocket() { … }
}