diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-07 22:01:13 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-07 22:01:13 +0000 |
commit | c87282692f04571330a9b06cccf8f22b52af8568 (patch) | |
tree | 688a6cf4c30d1aabb1cd4bde9a73e3244d41c61c /net | |
parent | 8902dacf5d97ab2de28d3f1de093fd0783d396ac (diff) | |
download | chromium_src-c87282692f04571330a9b06cccf8f22b52af8568.zip chromium_src-c87282692f04571330a9b06cccf8f22b52af8568.tar.gz chromium_src-c87282692f04571330a9b06cccf8f22b52af8568.tar.bz2 |
Add the SOCKET_READ_ERROR and SOCKET_WRITE_ERROR events to NetLog
to log TCPClientSocket::Read and TCPClientSocket::Write errors.
R=eroman@chromium.org,mmenke@chromium.org
BUG=130829
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10546012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141092 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/net_log_event_type_list.h | 9 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_libevent.cc | 28 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_win.cc | 31 |
3 files changed, 57 insertions, 11 deletions
diff --git a/net/base/net_log_event_type_list.h b/net/base/net_log_event_type_list.h index f30013b..70c4a90 100644 --- a/net/base/net_log_event_type_list.h +++ b/net/base/net_log_event_type_list.h @@ -532,6 +532,15 @@ EVENT_TYPE(SSL_SOCKET_BYTES_SENT) EVENT_TYPE(SOCKET_BYTES_RECEIVED) EVENT_TYPE(SSL_SOCKET_BYTES_RECEIVED) +// A socket error occurred while trying to do the indicated activity. +// The following parameters are attached to the event: +// { +// "net_error": <Integer code for the specific error type>, +// "os_error": <Integer error code the operating system returned> +// } +EVENT_TYPE(SOCKET_READ_ERROR) +EVENT_TYPE(SOCKET_WRITE_ERROR) + // Certificates were received from the SSL server (during a handshake or // renegotiation). This event is only present when logging at LOG_ALL. // The following parameters are attached to the event: diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc index 5254c1f..2bb0e02 100644 --- a/net/socket/tcp_client_socket_libevent.cc +++ b/net/socket/tcp_client_socket_libevent.cc @@ -26,6 +26,7 @@ #include "net/base/net_log.h" #include "net/base/net_util.h" #include "net/base/network_change_notifier.h" +#include "net/socket/socket_error_params.h" namespace net { @@ -452,8 +453,10 @@ int TCPClientSocketLibevent::Read(IOBuffer* buf, return nread; } if (errno != EAGAIN && errno != EWOULDBLOCK) { - DVLOG(1) << "read failed, errno " << errno; - return MapSystemError(errno); + int net_error = MapSystemError(errno); + net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, + make_scoped_refptr(new SocketErrorParams(net_error, errno))); + return net_error; } if (!MessageLoopForIO::current()->WatchFileDescriptor( @@ -490,8 +493,12 @@ int TCPClientSocketLibevent::Write(IOBuffer* buf, buf->data()); return nwrite; } - if (errno != EAGAIN && errno != EWOULDBLOCK) - return MapSystemError(errno); + if (errno != EAGAIN && errno != EWOULDBLOCK) { + int net_error = MapSystemError(errno); + net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR, + make_scoped_refptr(new SocketErrorParams(net_error, errno))); + return net_error; + } if (!MessageLoopForIO::current()->WatchFileDescriptor( socket_, true, MessageLoopForIO::WATCH_WRITE, @@ -512,7 +519,8 @@ int TCPClientSocketLibevent::InternalWrite(IOBuffer* buf, int buf_len) { SockaddrStorage storage; if (!addresses_[current_address_index_].ToSockAddr(storage.addr, &storage.addr_len)) { - return ERR_INVALID_ARGUMENT; + errno = EINVAL; + return -1; } // We have a limited amount of data to send in the SYN packet. @@ -536,6 +544,8 @@ int TCPClientSocketLibevent::InternalWrite(IOBuffer* buf, int buf_len) { // Unlike "normal" nonblocking sockets, the data is already queued, // so tell the app that we've consumed it. + // TODO(wtc): should we test if errno is EAGAIN or EWOULDBLOCK? + // Otherwise, returning buf_len here will mask a real error. return buf_len; } } else { @@ -658,6 +668,10 @@ void TCPClientSocketLibevent::DidCompleteRead() { read_buf_->data()); } else { result = MapSystemError(errno); + if (result != ERR_IO_PENDING) { + net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, + make_scoped_refptr(new SocketErrorParams(result, errno))); + } } if (result != ERR_IO_PENDING) { @@ -685,6 +699,10 @@ void TCPClientSocketLibevent::DidCompleteWrite() { write_buf_->data()); } else { result = MapSystemError(errno); + if (result != ERR_IO_PENDING) { + net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR, + make_scoped_refptr(new SocketErrorParams(result, errno))); + } } if (result != ERR_IO_PENDING) { diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc index 6ffd821..05578b0 100644 --- a/net/socket/tcp_client_socket_win.cc +++ b/net/socket/tcp_client_socket_win.cc @@ -22,6 +22,7 @@ #include "net/base/network_change_notifier.h" #include "net/base/winsock_init.h" #include "net/base/winsock_util.h" +#include "net/socket/socket_error_params.h" namespace net { @@ -721,8 +722,12 @@ int TCPClientSocketWin::Read(IOBuffer* buf, } } else { int os_error = WSAGetLastError(); - if (os_error != WSA_IO_PENDING) - return MapSystemError(os_error); + if (os_error != WSA_IO_PENDING) { + int net_error = MapSystemError(os_error); + net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, + make_scoped_refptr(new SocketErrorParams(net_error, os_error))); + return net_error; + } } core_->WatchForRead(); waiting_read_ = true; @@ -773,8 +778,12 @@ int TCPClientSocketWin::Write(IOBuffer* buf, } } else { int os_error = WSAGetLastError(); - if (os_error != WSA_IO_PENDING) - return MapSystemError(os_error); + if (os_error != WSA_IO_PENDING) { + int net_error = MapSystemError(os_error); + net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR, + make_scoped_refptr(new SocketErrorParams(net_error, os_error))); + return net_error; + } } core_->WatchForWrite(); waiting_write_ = true; @@ -888,6 +897,7 @@ void TCPClientSocketWin::DidCompleteRead() { WSAResetEvent(core_->read_overlapped_.hEvent); waiting_read_ = false; core_->read_iobuffer_ = NULL; + int rv; if (ok) { base::StatsCounter read_bytes("tcp.read_bytes"); read_bytes.Add(num_bytes); @@ -896,8 +906,14 @@ void TCPClientSocketWin::DidCompleteRead() { use_history_.set_was_used_to_convey_data(); net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, num_bytes, core_->read_buffer_.buf); + rv = static_cast<int>(num_bytes); + } else { + int os_error = WSAGetLastError(); + rv = MapSystemError(os_error); + net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, + make_scoped_refptr(new SocketErrorParams(rv, os_error))); } - DoReadCallback(ok ? num_bytes : MapSystemError(WSAGetLastError())); + DoReadCallback(rv); } void TCPClientSocketWin::DidCompleteWrite() { @@ -910,7 +926,10 @@ void TCPClientSocketWin::DidCompleteWrite() { waiting_write_ = false; int rv; if (!ok) { - rv = MapSystemError(WSAGetLastError()); + int os_error = WSAGetLastError(); + rv = MapSystemError(os_error); + net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR, + make_scoped_refptr(new SocketErrorParams(rv, os_error))); } else { rv = static_cast<int>(num_bytes); if (rv > core_->write_buffer_length_ || rv < 0) { |