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 {
TCPServerSocket& socket)
=> (int32 result, net.interfaces.IPEndPoint? local_addr_out);
// Creates a TCP socket connected to |remote_addr|. |observer| will be used
// to listen for any network connection error on the newly established
// connection. The socket created can only be used for the purpose specified
// in |traffic_annotation|, and cannot be re-used for other purposes.
// |local_addr| should be set to null unless the caller wants to bind the
// socket to a specific address and port. On success, |result| 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.
// Creates a TCP socket connected to |remote_addr|. |observer| if non-null
// will be used to listen for any network connection error on the newly
// established connection. The socket created can only be used for the purpose
// specified in |traffic_annotation|, and cannot be re-used for other
// purposes. |local_addr| should be set to null unless the caller wants to
// bind the socket to a specific address and port. On success, |result| 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.
//
// Any sockets that are created but are yet to be destroyed will be destroyed
// when NetworkContext goes away.
......@@ -229,7 +230,7 @@ interface NetworkContext {
net.interfaces.AddressList remote_addr_list,
MutableNetworkTrafficAnnotationTag traffic_annotation,
TCPConnectedSocket& socket,
TCPConnectedSocketObserver observer)
TCPConnectedSocketObserver? observer)
=> (int32 result,
handle<data_pipe_consumer>? receive_stream,
handle<data_pipe_producer>? send_stream);
......
......@@ -35,16 +35,17 @@ interface TCPConnectedSocketObserver {
// 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. 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,
// 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(TCPConnectedSocketObserver observer)
Accept(TCPConnectedSocketObserver? observer)
=> (int32 net_error,
net.interfaces.IPEndPoint? remote_addr,
TCPConnectedSocket? connected_socket,
......
......@@ -27,9 +27,6 @@ TCPConnectedSocket::TCPConnectedSocket(
writable_handle_watcher_(FROM_HERE,
mojo::SimpleWatcher::ArmingPolicy::MANUAL),
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(
......@@ -165,7 +162,7 @@ void TCPConnectedSocket::OnReceiveStreamWritable(MojoResult result) {
void TCPConnectedSocket::OnNetworkReadCompleted(int bytes_read) {
DCHECK(pending_receive_);
if (bytes_read < 0)
if (bytes_read < 0 && observer_)
observer_->OnReadError(bytes_read);
if (bytes_read <= 0) {
......@@ -225,7 +222,7 @@ void TCPConnectedSocket::OnSendStreamReadable(MojoResult result) {
void TCPConnectedSocket::OnNetworkWriteCompleted(int bytes_written) {
DCHECK(pending_send_);
if (bytes_written < 0)
if (bytes_written < 0 && observer_)
observer_->OnWriteError(bytes_written);
if (bytes_written <= 0) {
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