Commit f021980c authored by Helen Li's avatar Helen Li Committed by Commit Bot

Make TCPConnectedSocketObserver an optional param

There are users of TCP socket APIs who do not care about the specific read/write
errors. One example is net::HttpServer.
This CL makes the observer param optional.

Bug: 721401
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: I028a01b6b8e3dea87a3865b704cc15347a3f2793
Reviewed-on: https://chromium-review.googlesource.com/978033Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Helen Li <xunjieli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546095}
parent 9709668a
...@@ -213,14 +213,15 @@ interface NetworkContext { ...@@ -213,14 +213,15 @@ interface NetworkContext {
TCPServerSocket& socket) TCPServerSocket& socket)
=> (int32 result, net.interfaces.IPEndPoint? local_addr_out); => (int32 result, net.interfaces.IPEndPoint? local_addr_out);
// Creates a TCP socket connected to |remote_addr|. |observer| will be used // Creates a TCP socket connected to |remote_addr|. |observer| if non-null
// to listen for any network connection error on the newly established // will be used to listen for any network connection error on the newly
// connection. The socket created can only be used for the purpose specified // established connection. The socket created can only be used for the purpose
// in |traffic_annotation|, and cannot be re-used for other purposes. // specified in |traffic_annotation|, and cannot be re-used for other
// |local_addr| should be set to null unless the caller wants to bind the // purposes. |local_addr| should be set to null unless the caller wants to
// socket to a specific address and port. On success, |result| is net::OK. // bind the socket to a specific address and port. On success, |result| is
// Caller is to use |send_stream| to send data and |receive_stream| to receive // net::OK. Caller is to use |send_stream| to send data and |receive_stream|
// data over the connection. On failure, |result| is a network error code. // to receive data over the connection. On failure, |result| is a network
// error code.
// //
// Any sockets that are created but are yet to be destroyed will be destroyed // Any sockets that are created but are yet to be destroyed will be destroyed
// when NetworkContext goes away. // when NetworkContext goes away.
...@@ -229,7 +230,7 @@ interface NetworkContext { ...@@ -229,7 +230,7 @@ interface NetworkContext {
net.interfaces.AddressList remote_addr_list, net.interfaces.AddressList remote_addr_list,
MutableNetworkTrafficAnnotationTag traffic_annotation, MutableNetworkTrafficAnnotationTag traffic_annotation,
TCPConnectedSocket& socket, TCPConnectedSocket& socket,
TCPConnectedSocketObserver observer) TCPConnectedSocketObserver? observer)
=> (int32 result, => (int32 result,
handle<data_pipe_consumer>? receive_stream, handle<data_pipe_consumer>? receive_stream,
handle<data_pipe_producer>? send_stream); handle<data_pipe_producer>? send_stream);
......
...@@ -35,16 +35,17 @@ interface TCPConnectedSocketObserver { ...@@ -35,16 +35,17 @@ interface TCPConnectedSocketObserver {
// Represents a TCP server socket that has been successfully bound to a local // Represents a TCP server socket that has been successfully bound to a local
// address. Caller can close the socket by destroying the interface pointer. // address. Caller can close the socket by destroying the interface pointer.
interface TCPServerSocket { interface TCPServerSocket {
// Waits for an incoming connection request. On success, returns net::OK, // Waits for an incoming connection request. |observer| if non-null will be
// |remote_addr| represents the peer address, |connected_socket| is the new // used to listen for any network connection error on the newly established
// connection established. Caller uses |send_stream| to send data and // connection. On success, returns net::OK, |remote_addr| represents the peer
// |receive_stream| for receiving data over the new connection. On failure, // address, |connected_socket| is the new connection established. Caller uses
// |net_error| is a net error code and other fields are null. // |send_stream| to send data and |receive_stream| for receiving data over the
// Up to |backlog| Accept()s can be pending at a time. |backlog| is a // new connection. On failure, |net_error| is a net error code and other
// number that is specified when requesting TCPServerSocket. If more than // fields are null. Up to |backlog| Accept()s can be pending at a time.
// |backlog| number of Accept()s are outstanding, // |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. // net::ERR_INSUFFICIENT_RESOUCES will be returned.
Accept(TCPConnectedSocketObserver observer) Accept(TCPConnectedSocketObserver? observer)
=> (int32 net_error, => (int32 net_error,
net.interfaces.IPEndPoint? remote_addr, net.interfaces.IPEndPoint? remote_addr,
TCPConnectedSocket? connected_socket, TCPConnectedSocket? connected_socket,
......
...@@ -27,9 +27,6 @@ TCPConnectedSocket::TCPConnectedSocket( ...@@ -27,9 +27,6 @@ TCPConnectedSocket::TCPConnectedSocket(
writable_handle_watcher_(FROM_HERE, writable_handle_watcher_(FROM_HERE,
mojo::SimpleWatcher::ArmingPolicy::MANUAL), mojo::SimpleWatcher::ArmingPolicy::MANUAL),
traffic_annotation_(traffic_annotation) { traffic_annotation_(traffic_annotation) {
// TODO(xunjieli): Consider supporting null |observer_|, if there are
// consumers who do not care about read/write errors.
DCHECK(observer_);
} }
TCPConnectedSocket::TCPConnectedSocket( TCPConnectedSocket::TCPConnectedSocket(
...@@ -165,7 +162,7 @@ void TCPConnectedSocket::OnReceiveStreamWritable(MojoResult result) { ...@@ -165,7 +162,7 @@ void TCPConnectedSocket::OnReceiveStreamWritable(MojoResult result) {
void TCPConnectedSocket::OnNetworkReadCompleted(int bytes_read) { void TCPConnectedSocket::OnNetworkReadCompleted(int bytes_read) {
DCHECK(pending_receive_); DCHECK(pending_receive_);
if (bytes_read < 0) if (bytes_read < 0 && observer_)
observer_->OnReadError(bytes_read); observer_->OnReadError(bytes_read);
if (bytes_read <= 0) { if (bytes_read <= 0) {
...@@ -225,7 +222,7 @@ void TCPConnectedSocket::OnSendStreamReadable(MojoResult result) { ...@@ -225,7 +222,7 @@ void TCPConnectedSocket::OnSendStreamReadable(MojoResult result) {
void TCPConnectedSocket::OnNetworkWriteCompleted(int bytes_written) { void TCPConnectedSocket::OnNetworkWriteCompleted(int bytes_written) {
DCHECK(pending_send_); DCHECK(pending_send_);
if (bytes_written < 0) if (bytes_written < 0 && observer_)
observer_->OnWriteError(bytes_written); observer_->OnWriteError(bytes_written);
if (bytes_written <= 0) { if (bytes_written <= 0) {
ShutdownSend(); ShutdownSend();
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment