Skip to content

Commit

Permalink
make SetReceiveBufferSize and SetSendBufferSize return net error code…
Browse files Browse the repository at this point in the history
…s (instead of bools)

TBR=sergeyu,yzshen
R=wtc
BUG=355222

Review URL: https://codereview.chromium.org/217573002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261966 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jar@chromium.org committed Apr 5, 2014
1 parent 41b64e8 commit 27f82f4
Show file tree
Hide file tree
Showing 67 changed files with 281 additions and 245 deletions.
10 changes: 5 additions & 5 deletions chrome/browser/devtools/adb/android_usb_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ int AndroidUsbSocket::Write(net::IOBuffer* buffer,
return net::ERR_IO_PENDING;
}

bool AndroidUsbSocket::SetReceiveBufferSize(int32 size) {
int AndroidUsbSocket::SetReceiveBufferSize(int32 size) {
NOTIMPLEMENTED();
return false;
return net::ERR_NOT_IMPLEMENTED;
}

bool AndroidUsbSocket::SetSendBufferSize(int32 size) {
int AndroidUsbSocket::SetSendBufferSize(int32 size) {
NOTIMPLEMENTED();
return false;
return net::ERR_NOT_IMPLEMENTED;
}

int AndroidUsbSocket::Connect(const net::CompletionCallback& callback) {
Expand Down Expand Up @@ -180,7 +180,7 @@ int AndroidUsbSocket::GetPeerAddress(net::IPEndPoint* address) const {

int AndroidUsbSocket::GetLocalAddress(net::IPEndPoint* address) const {
NOTIMPLEMENTED();
return net::ERR_FAILED;
return net::ERR_NOT_IMPLEMENTED;
}

const net::BoundNetLog& AndroidUsbSocket::NetLog() const {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/devtools/adb/android_usb_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class AndroidUsbSocket : public net::StreamSocket,
const net::CompletionCallback& callback) OVERRIDE;
virtual int Write(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) OVERRIDE;
virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
virtual bool SetSendBufferSize(int32 size) OVERRIDE;
virtual int SetReceiveBufferSize(int32 size) OVERRIDE;
virtual int SetSendBufferSize(int32 size) OVERRIDE;
virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
virtual void Disconnect() OVERRIDE;
virtual bool IsConnected() const OVERRIDE;
Expand Down
4 changes: 2 additions & 2 deletions content/browser/renderer_host/p2p/socket_host_tcp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ bool P2PSocketHostTcpBase::SetOption(P2PSocketOption option, int value) {
DCHECK_EQ(STATE_OPEN, state_);
switch (option) {
case P2P_SOCKET_OPT_RCVBUF:
return socket_->SetReceiveBufferSize(value);
return socket_->SetReceiveBufferSize(value) == net::OK;
case P2P_SOCKET_OPT_SNDBUF:
return socket_->SetSendBufferSize(value);
return socket_->SetSendBufferSize(value) == net::OK;
case P2P_SOCKET_OPT_DSCP:
return false; // For TCP sockets DSCP setting is not available.
default:
Expand Down
9 changes: 5 additions & 4 deletions content/browser/renderer_host/p2p/socket_host_test_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ void FakeSocket::DoAsyncWrite(scoped_refptr<net::IOBuffer> buf, int buf_len,
callback.Run(buf_len);
}

bool FakeSocket::SetReceiveBufferSize(int32 size) {
int FakeSocket::SetReceiveBufferSize(int32 size) {
NOTIMPLEMENTED();
return false;
return net::ERR_NOT_IMPLEMENTED;
}
bool FakeSocket::SetSendBufferSize(int32 size) {

int FakeSocket::SetSendBufferSize(int32 size) {
NOTIMPLEMENTED();
return false;
return net::ERR_NOT_IMPLEMENTED;
}

int FakeSocket::Connect(const net::CompletionCallback& callback) {
Expand Down
4 changes: 2 additions & 2 deletions content/browser/renderer_host/p2p/socket_host_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class FakeSocket : public net::StreamSocket {
const net::CompletionCallback& callback) OVERRIDE;
virtual int Write(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) OVERRIDE;
virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
virtual bool SetSendBufferSize(int32 size) OVERRIDE;
virtual int SetReceiveBufferSize(int32 size) OVERRIDE;
virtual int SetSendBufferSize(int32 size) OVERRIDE;
virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
virtual void Disconnect() OVERRIDE;
virtual bool IsConnected() const OVERRIDE;
Expand Down
6 changes: 3 additions & 3 deletions content/browser/renderer_host/p2p/socket_host_udp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bool P2PSocketHostUdp::Init(const net::IPEndPoint& local_address,
}

// Setting recv socket buffer size.
if (!socket_->SetReceiveBufferSize(kRecvSocketBufferSize)) {
if (socket_->SetReceiveBufferSize(kRecvSocketBufferSize) != net::OK) {
LOG(WARNING) << "Failed to set socket receive buffer size to "
<< kRecvSocketBufferSize;
}
Expand Down Expand Up @@ -302,9 +302,9 @@ bool P2PSocketHostUdp::SetOption(P2PSocketOption option, int value) {
DCHECK_EQ(STATE_OPEN, state_);
switch (option) {
case P2P_SOCKET_OPT_RCVBUF:
return socket_->SetReceiveBufferSize(value);
return socket_->SetReceiveBufferSize(value) == net::OK;
case P2P_SOCKET_OPT_SNDBUF:
return socket_->SetSendBufferSize(value);
return socket_->SetSendBufferSize(value) == net::OK;
case P2P_SOCKET_OPT_DSCP:
return (net::OK == socket_->SetDiffServCodePoint(
static_cast<net::DiffServCodePoint>(value))) ? true : false;
Expand Down
8 changes: 4 additions & 4 deletions content/browser/renderer_host/p2p/socket_host_udp_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ class FakeDatagramServerSocket : public net::DatagramServerSocket {
return buf_len;
}

virtual bool SetReceiveBufferSize(int32 size) OVERRIDE {
return true;
virtual int SetReceiveBufferSize(int32 size) OVERRIDE {
return net::OK;
}

virtual bool SetSendBufferSize(int32 size) OVERRIDE {
return true;
virtual int SetSendBufferSize(int32 size) OVERRIDE {
return net::OK;
}

void ReceivePacket(const net::IPEndPoint& address, std::vector<char> data) {
Expand Down
9 changes: 5 additions & 4 deletions content/browser/renderer_host/pepper/pepper_tcp_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,22 @@ void PepperTCPSocket::SetOption(PP_TCPSocket_Option name,
return;
}

bool result = false;
int net_result = net::OK;
if (name == PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE) {
if (integer_value > ppapi::TCPSocketShared::kMaxSendBufferSize) {
SendSetOptionACK(PP_ERROR_BADARGUMENT);
return;
}
result = tcp_socket->SetSendBufferSize(integer_value);
net_result = tcp_socket->SetSendBufferSize(integer_value);
} else {
if (integer_value > ppapi::TCPSocketShared::kMaxReceiveBufferSize) {
SendSetOptionACK(PP_ERROR_BADARGUMENT);
return;
}
result = tcp_socket->SetReceiveBufferSize(integer_value);
net_result = tcp_socket->SetReceiveBufferSize(integer_value);
}
SendSetOptionACK(result ? PP_OK : PP_ERROR_FAILED);
// TODO(wtc): Add error mapping.
SendSetOptionACK((net_result == net::OK) ? PP_OK : PP_ERROR_FAILED);
return;
}
default: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,18 @@ int32_t PepperTCPSocketMessageFilter::OnMsgSetOption(
if (!value.GetInt32(&integer_value) || integer_value <= 0)
return PP_ERROR_BADARGUMENT;

bool result = false;
int net_result = net::OK;
if (name == PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE) {
if (integer_value > TCPSocketResourceBase::kMaxSendBufferSize)
return PP_ERROR_BADARGUMENT;
result = socket_->SetSendBufferSize(integer_value);
net_result = socket_->SetSendBufferSize(integer_value);
} else {
if (integer_value > TCPSocketResourceBase::kMaxReceiveBufferSize)
return PP_ERROR_BADARGUMENT;
result = socket_->SetReceiveBufferSize(integer_value);
net_result = socket_->SetReceiveBufferSize(integer_value);
}
return result ? PP_OK : PP_ERROR_FAILED;
// TODO(wtc): Add error mapping code.
return (net_result == net::OK) ? PP_OK : PP_ERROR_FAILED;
}
default: {
NOTREACHED();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,22 @@ int32_t PepperUDPSocketMessageFilter::OnMsgSetOption(
if (!value.GetInt32(&integer_value) || integer_value <= 0)
return PP_ERROR_BADARGUMENT;

bool result = false;
int net_result = net::OK;
if (name == PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE) {
if (integer_value >
ppapi::proxy::UDPSocketResourceBase::kMaxSendBufferSize) {
return PP_ERROR_BADARGUMENT;
}
result = socket_->SetSendBufferSize(integer_value);
net_result = socket_->SetSendBufferSize(integer_value);
} else {
if (integer_value >
ppapi::proxy::UDPSocketResourceBase::kMaxReceiveBufferSize) {
return PP_ERROR_BADARGUMENT;
}
result = socket_->SetReceiveBufferSize(integer_value);
net_result = socket_->SetReceiveBufferSize(integer_value);
}
return result ? PP_OK : PP_ERROR_FAILED;
// TODO(wtc): Add error mapping code.
return (net_result == net::OK) ? PP_OK : PP_ERROR_FAILED;
}
default: {
NOTREACHED();
Expand Down
10 changes: 6 additions & 4 deletions jingle/glue/channel_socket_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ int TransportChannelSocketAdapter::Write(
return result;
}

bool TransportChannelSocketAdapter::SetReceiveBufferSize(int32 size) {
int TransportChannelSocketAdapter::SetReceiveBufferSize(int32 size) {
DCHECK_EQ(base::MessageLoop::current(), message_loop_);
return channel_->SetOption(talk_base::Socket::OPT_RCVBUF, size) == 0;
return (channel_->SetOption(talk_base::Socket::OPT_RCVBUF, size) == 0) ?
net::OK : net::ERR_SOCKET_SET_RECEIVE_BUFFER_SIZE_ERROR;
}

bool TransportChannelSocketAdapter::SetSendBufferSize(int32 size) {
int TransportChannelSocketAdapter::SetSendBufferSize(int32 size) {
DCHECK_EQ(base::MessageLoop::current(), message_loop_);
return channel_->SetOption(talk_base::Socket::OPT_SNDBUF, size) == 0;
return (channel_->SetOption(talk_base::Socket::OPT_SNDBUF, size) == 0) ?
net::OK : net::ERR_SOCKET_SET_SEND_BUFFER_SIZE_ERROR;
}

void TransportChannelSocketAdapter::Close(int error_code) {
Expand Down
4 changes: 2 additions & 2 deletions jingle/glue/channel_socket_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class TransportChannelSocketAdapter : public net::Socket,
virtual int Write(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) OVERRIDE;

virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
virtual bool SetSendBufferSize(int32 size) OVERRIDE;
virtual int SetReceiveBufferSize(int32 size) OVERRIDE;
virtual int SetSendBufferSize(int32 size) OVERRIDE;

private:
void OnNewPacket(cricket::TransportChannel* channel,
Expand Down
4 changes: 2 additions & 2 deletions jingle/glue/fake_ssl_client_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ int FakeSSLClientSocket::Write(net::IOBuffer* buf, int buf_len,
return transport_socket_->Write(buf, buf_len, callback);
}

bool FakeSSLClientSocket::SetReceiveBufferSize(int32 size) {
int FakeSSLClientSocket::SetReceiveBufferSize(int32 size) {
return transport_socket_->SetReceiveBufferSize(size);
}

bool FakeSSLClientSocket::SetSendBufferSize(int32 size) {
int FakeSSLClientSocket::SetSendBufferSize(int32 size) {
return transport_socket_->SetSendBufferSize(size);
}

Expand Down
4 changes: 2 additions & 2 deletions jingle/glue/fake_ssl_client_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class FakeSSLClientSocket : public net::StreamSocket {
const net::CompletionCallback& callback) OVERRIDE;
virtual int Write(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) OVERRIDE;
virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
virtual bool SetSendBufferSize(int32 size) OVERRIDE;
virtual int SetReceiveBufferSize(int32 size) OVERRIDE;
virtual int SetSendBufferSize(int32 size) OVERRIDE;
virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
virtual void Disconnect() OVERRIDE;
virtual bool IsConnected() const OVERRIDE;
Expand Down
4 changes: 2 additions & 2 deletions jingle/glue/fake_ssl_client_socket_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class MockClientSocket : public net::StreamSocket {
const net::CompletionCallback&));
MOCK_METHOD3(Write, int(net::IOBuffer*, int,
const net::CompletionCallback&));
MOCK_METHOD1(SetReceiveBufferSize, bool(int32));
MOCK_METHOD1(SetSendBufferSize, bool(int32));
MOCK_METHOD1(SetReceiveBufferSize, int(int32));
MOCK_METHOD1(SetSendBufferSize, int(int32));
MOCK_METHOD1(Connect, int(const net::CompletionCallback&));
MOCK_METHOD0(Disconnect, void());
MOCK_CONST_METHOD0(IsConnected, bool());
Expand Down
8 changes: 4 additions & 4 deletions jingle/glue/proxy_resolving_client_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ int ProxyResolvingClientSocket::Write(
return net::ERR_SOCKET_NOT_CONNECTED;
}

bool ProxyResolvingClientSocket::SetReceiveBufferSize(int32 size) {
int ProxyResolvingClientSocket::SetReceiveBufferSize(int32 size) {
if (transport_.get() && transport_->socket())
return transport_->socket()->SetReceiveBufferSize(size);
NOTREACHED();
return false;
return net::ERR_SOCKET_NOT_CONNECTED;
}

bool ProxyResolvingClientSocket::SetSendBufferSize(int32 size) {
int ProxyResolvingClientSocket::SetSendBufferSize(int32 size) {
if (transport_.get() && transport_->socket())
return transport_->socket()->SetSendBufferSize(size);
NOTREACHED();
return false;
return net::ERR_SOCKET_NOT_CONNECTED;
}

int ProxyResolvingClientSocket::Connect(
Expand Down
4 changes: 2 additions & 2 deletions jingle/glue/proxy_resolving_client_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class ProxyResolvingClientSocket : public net::StreamSocket {
const net::CompletionCallback& callback) OVERRIDE;
virtual int Write(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) OVERRIDE;
virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
virtual bool SetSendBufferSize(int32 size) OVERRIDE;
virtual int SetReceiveBufferSize(int32 size) OVERRIDE;
virtual int SetSendBufferSize(int32 size) OVERRIDE;
virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
virtual void Disconnect() OVERRIDE;
virtual bool IsConnected() const OVERRIDE;
Expand Down
8 changes: 4 additions & 4 deletions jingle/glue/pseudotcp_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -484,18 +484,18 @@ int PseudoTcpAdapter::Write(net::IOBuffer* buffer, int buffer_size,
return core_->Write(buffer, buffer_size, callback);
}

bool PseudoTcpAdapter::SetReceiveBufferSize(int32 size) {
int PseudoTcpAdapter::SetReceiveBufferSize(int32 size) {
DCHECK(CalledOnValidThread());

core_->SetReceiveBufferSize(size);
return false;
return net::OK;
}

bool PseudoTcpAdapter::SetSendBufferSize(int32 size) {
int PseudoTcpAdapter::SetSendBufferSize(int32 size) {
DCHECK(CalledOnValidThread());

core_->SetSendBufferSize(size);
return false;
return net::OK;
}

int PseudoTcpAdapter::Connect(const net::CompletionCallback& callback) {
Expand Down
4 changes: 2 additions & 2 deletions jingle/glue/pseudotcp_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class PseudoTcpAdapter : public net::StreamSocket, base::NonThreadSafe {
const net::CompletionCallback& callback) OVERRIDE;
virtual int Write(net::IOBuffer* buffer, int buffer_size,
const net::CompletionCallback& callback) OVERRIDE;
virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
virtual bool SetSendBufferSize(int32 size) OVERRIDE;
virtual int SetReceiveBufferSize(int32 size) OVERRIDE;
virtual int SetSendBufferSize(int32 size) OVERRIDE;

// net::StreamSocket implementation.
virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
Expand Down
8 changes: 4 additions & 4 deletions jingle/glue/pseudotcp_adapter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ class FakeSocket : public net::Socket {
return buf_len;
}

virtual bool SetReceiveBufferSize(int32 size) OVERRIDE {
virtual int SetReceiveBufferSize(int32 size) OVERRIDE {
NOTIMPLEMENTED();
return false;
return net::ERR_NOT_IMPLEMENTED;
}
virtual bool SetSendBufferSize(int32 size) OVERRIDE {
virtual int SetSendBufferSize(int32 size) OVERRIDE {
NOTIMPLEMENTED();
return false;
return net::ERR_NOT_IMPLEMENTED;
}

private:
Expand Down
12 changes: 10 additions & 2 deletions net/base/net_error_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,20 @@ NET_ERROR(CT_NO_SCTS_VERIFIED_OK, -158)
// The SSL server sent us a fatal unrecognized_name alert.
NET_ERROR(SSL_UNRECOGNIZED_NAME_ALERT, -159)

// Failed to set or change the socket's receive buffer size as requested
// Failed to set the socket's receive buffer size as requested.
NET_ERROR(SOCKET_SET_RECEIVE_BUFFER_SIZE_ERROR, -160)

// Failed to set or change the socket's send buffer size as requested.
// Failed to set the socket's send buffer size as requested.
NET_ERROR(SOCKET_SET_SEND_BUFFER_SIZE_ERROR, -161)

// Failed to set the socket's receive buffer size as requested, despite success
// return code from setsockopt.
NET_ERROR(SOCKET_RECEIVE_BUFFER_SIZE_UNCHANGEABLE, -162)

// Failed to set the socket's send buffer size as requested, despite success
// return code from setsockopt.
NET_ERROR(SOCKET_SEND_BUFFER_SIZE_UNCHANGEABLE, -163)

// Certificate error codes
//
// The values of certificate error codes must be consecutive.
Expand Down
8 changes: 4 additions & 4 deletions net/dns/address_sorter_posix_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class TestUDPClientSocket : public DatagramClientSocket {
NOTIMPLEMENTED();
return OK;
}
virtual bool SetReceiveBufferSize(int32) OVERRIDE {
return true;
virtual int SetReceiveBufferSize(int32) OVERRIDE {
return OK;
}
virtual bool SetSendBufferSize(int32) OVERRIDE {
return true;
virtual int SetSendBufferSize(int32) OVERRIDE {
return OK;
}

virtual void Close() OVERRIDE {}
Expand Down
4 changes: 2 additions & 2 deletions net/dns/mock_mdns_socket_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class MockMDnsDatagramServerSocket : public DatagramServerSocket {
const std::string address,
const CompletionCallback& callback));

MOCK_METHOD1(SetReceiveBufferSize, bool(int32 size));
MOCK_METHOD1(SetSendBufferSize, bool(int32 size));
MOCK_METHOD1(SetReceiveBufferSize, int(int32 size));
MOCK_METHOD1(SetSendBufferSize, int(int32 size));

MOCK_METHOD0(Close, void());

Expand Down
Loading

0 comments on commit 27f82f4

Please sign in to comment.