naiveproxy/services/network/public/mojom/tcp_socket.mojom
2018-12-09 21:59:24 -05:00

92 lines
4.5 KiB
Plaintext

// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module network.mojom;
import "net/interfaces/ip_endpoint.mojom";
import "services/network/public/mojom/ssl_config.mojom";
import "services/network/public/mojom/tls_socket.mojom";
import "services/network/public/mojom/network_param.mojom";
import "services/network/public/mojom/mutable_network_traffic_annotation_tag.mojom";
// Represents a connected TCP socket. Writes and Reads are through the data
// pipes supplied upon construction. Consumer should use
// SocketObserver interface to get notified about any error occurred
// during reading or writing to data pipes. Consumer can close the socket by
// destroying the interface pointer.
interface TCPConnectedSocket {
// Upgrades a TCP socket to a TLS client socket. Caller can optionally specify
// a TLSClientSocketOptions to configure the connection.
// IMPORTANT: Caller needs close the previous send and receive pipes before
// this method can complete asynchronously.
//
// On success, |net_error| is net::OK. Caller is to use |send_stream| to send
// data and |receive_stream| to receive data over the connection. On failure,
// |result| is a network error code.
// |ssl_info| is only returned if |options::skip_cert_verification| is true.
UpgradeToTLS(HostPortPair host_port_pair,
TLSClientSocketOptions? options,
MutableNetworkTrafficAnnotationTag traffic_annotation,
TLSClientSocket& request,
SocketObserver? observer)
=> (int32 net_error,
handle<data_pipe_consumer>? receive_stream,
handle<data_pipe_producer>? send_stream,
SSLInfo? ssl_info);
// Socket options:
// Note that an implementation can apply default socket options suitable for
// the platform. Consumers do not need to set these themselves unless they
// want to change the default settings.
// This function enables/disables buffering in the kernel. By default, on
// Linux, TCP sockets will wait up to 200ms for more data to complete a packet
// before transmitting. After calling this function, the kernel will not wait.
// See TCP_NODELAY in `man 7 tcp`. On Windows, the Nagle implementation is
// governed by RFC 896. SetTCPNoDelay() sets the TCP_NODELAY option. Use
// |no_delay| to enable or disable it.
// Returns whether the operation is successful.
SetNoDelay(bool no_delay) => (bool success);
// Enables or disables TCP Keep-Alive. This sets SO_KEEPALIVE on the socket.
// |delay_secs| specifies the amount of time to delay in seconds.
// Returns whether the operation is successful.
SetKeepAlive(bool enable, int32 delay_secs) => (bool success);
};
// Interface to listen for network connection error on a TCPConnectedSocket or
// a TLSClientSocket. Because data pipe doesn't surface any network connection
// error, if a network error happens during a read or a write, consumer can find
// out about it by implementing this interface.
interface SocketObserver {
// Called when an error occurs during reading from the network. The producer
// side of |receive_stream| will be closed.
OnReadError(int32 net_error);
// Called when an error occurs during sending to the network. The consumer
// side of |send_stream| will be closed.
OnWriteError(int32 net_error);
};
// Represents a TCP server socket that has been successfully bound to a local
// address. Caller can close the socket by destroying the interface pointer.
interface TCPServerSocket {
// Waits for an incoming connection request. |observer| if non-null will be
// used to listen for any network connection error on the newly established
// connection. On success, returns net::OK, |remote_addr| represents the peer
// address, |connected_socket| is the new connection established. Caller uses
// |send_stream| to send data and |receive_stream| for receiving data over the
// new connection. On failure, |net_error| is a net error code and other
// fields are null. Up to |backlog| Accept()s can be pending at a time.
// |backlog| is a number that is specified when requesting TCPServerSocket. If
// more than |backlog| number of Accept()s are outstanding,
// net::ERR_INSUFFICIENT_RESOUCES will be returned.
Accept(SocketObserver? observer)
=> (int32 net_error,
net.interfaces.IPEndPoint? remote_addr,
TCPConnectedSocket? connected_socket,
handle<data_pipe_consumer>? send_stream,
handle<data_pipe_producer>? receive_stream);
};