diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/base/address_list_net_log_param.cc | 30 | ||||
-rw-r--r-- | net/base/address_list_net_log_param.h | 28 | ||||
-rw-r--r-- | net/base/net_log_event_type_list.h | 2 | ||||
-rw-r--r-- | net/net.gyp | 2 | ||||
-rw-r--r-- | net/socket/ssl_client_socket_unittest.cc | 21 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_libevent.cc | 28 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_win.cc | 46 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_win.h | 4 |
8 files changed, 109 insertions, 52 deletions
diff --git a/net/base/address_list_net_log_param.cc b/net/base/address_list_net_log_param.cc new file mode 100644 index 0000000..9143ae9 --- /dev/null +++ b/net/base/address_list_net_log_param.cc @@ -0,0 +1,30 @@ +// Copyright (c) 2010 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. + +#include "net/base/address_list_net_log_param.h" + +#include "base/values.h" +#include "net/base/net_util.h" +#include "net/base/sys_addrinfo.h" + +namespace net { + +AddressListNetLogParam::AddressListNetLogParam(const AddressList& address_list) + : address_list_(address_list) { +} + +Value* AddressListNetLogParam::ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + ListValue* list = new ListValue(); + + for (const addrinfo* head = address_list_.head(); + head != NULL ; head = head->ai_next) { + list->Append(Value::CreateStringValue(NetAddressToString(head))); + } + + dict->Set(L"address_list", list); + return dict; +} + +} // namespace diff --git a/net/base/address_list_net_log_param.h b/net/base/address_list_net_log_param.h new file mode 100644 index 0000000..2a56961 --- /dev/null +++ b/net/base/address_list_net_log_param.h @@ -0,0 +1,28 @@ +// Copyright (c) 2010 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. + +#ifndef NET_BASE_ADDRESS_LIST_NET_LOG_PARAM_H_ +#define NET_BASE_ADDRESS_LIST_NET_LOG_PARAM_H_ + +#include "net/base/address_list.h" +#include "net/base/net_log.h" + +namespace net { + +// NetLog parameter to describe an address list. +// Note that AddressList uses ref-counted data, so this doesn't introduce +// much of a memory overhead. +class AddressListNetLogParam : public NetLog::EventParameters { + public: + explicit AddressListNetLogParam(const AddressList& address_list); + + virtual Value* ToValue() const; + + private: + AddressList address_list_; +}; + +} // namespace net + +#endif // NET_BASE_ADDRESS_LIST_NET_LOG_PARAM_H_ diff --git a/net/base/net_log_event_type_list.h b/net/base/net_log_event_type_list.h index 1c0aedf..30faee9 100644 --- a/net/base/net_log_event_type_list.h +++ b/net/base/net_log_event_type_list.h @@ -129,7 +129,7 @@ EVENT_TYPE(WAITING_FOR_SINGLE_PROXY_RESOLVER_THREAD) // The START event contains these parameters: // // { -// "addresses": <List of network address strings> +// "address_list": <List of network address strings> // } // // And the END event will contain the following parameters on failure: diff --git a/net/net.gyp b/net/net.gyp index e978135..85daf0c 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -24,6 +24,8 @@ 'base/address_family.h', 'base/address_list.cc', 'base/address_list.h', + 'base/address_list_net_log_param.cc', + 'base/address_list_net_log_param.h', 'base/auth.h', 'base/cache_type.h', 'base/capturing_net_log.cc', diff --git a/net/socket/ssl_client_socket_unittest.cc b/net/socket/ssl_client_socket_unittest.cc index 9a46c4a..415cb83 100644 --- a/net/socket/ssl_client_socket_unittest.cc +++ b/net/socket/ssl_client_socket_unittest.cc @@ -83,11 +83,8 @@ TEST_F(SSLClientSocketTest, Connect) { EXPECT_FALSE(sock->IsConnected()); rv = sock->Connect(&callback); - // TODO(eroman): re-enable this once the logging for - // TCPClientSocketLibevent is in sync with TCPClientSocketWin. - // http://crbug.com/44488 - // EXPECT_TRUE(net::LogContainsBeginEvent( - // log.entries(), 2, net::NetLog::TYPE_SSL_CONNECT)); + EXPECT_TRUE(net::LogContainsBeginEvent( + log.entries(), 4, net::NetLog::TYPE_SSL_CONNECT)); if (rv != net::OK) { ASSERT_EQ(net::ERR_IO_PENDING, rv); EXPECT_FALSE(sock->IsConnected()); @@ -130,11 +127,8 @@ TEST_F(SSLClientSocketTest, ConnectExpired) { EXPECT_FALSE(sock->IsConnected()); rv = sock->Connect(&callback); - // TODO(eroman): re-enable this once the logging for - // TCPClientSocketLibevent is in sync with TCPClientSocketWin. - // http://crbug.com/44488 - // EXPECT_TRUE(net::LogContainsBeginEvent( - // log.entries(), 2, net::NetLog::TYPE_SSL_CONNECT)); + EXPECT_TRUE(net::LogContainsBeginEvent( + log.entries(), 4, net::NetLog::TYPE_SSL_CONNECT)); if (rv != net::OK) { ASSERT_EQ(net::ERR_IO_PENDING, rv); EXPECT_FALSE(sock->IsConnected()); @@ -179,11 +173,8 @@ TEST_F(SSLClientSocketTest, ConnectMismatched) { rv = sock->Connect(&callback); - // TODO(eroman): re-enable this once the logging for - // TCPClientSocketLibevent is in sync with TCPClientSocketWin. - // http://crbug.com/44488 - // EXPECT_TRUE(net::LogContainsBeginEvent( - // log.entries(), 2, net::NetLog::TYPE_SSL_CONNECT)); + EXPECT_TRUE(net::LogContainsBeginEvent( + log.entries(), 4, net::NetLog::TYPE_SSL_CONNECT)); if (rv != net::ERR_CERT_COMMON_NAME_INVALID) { ASSERT_EQ(net::ERR_IO_PENDING, rv); EXPECT_FALSE(sock->IsConnected()); diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc index 74ab2b7..93f2333 100644 --- a/net/socket/tcp_client_socket_libevent.cc +++ b/net/socket/tcp_client_socket_libevent.cc @@ -17,7 +17,7 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/string_util.h" -#include "base/values.h" +#include "net/base/address_list_net_log_param.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/base/net_log.h" @@ -32,30 +32,6 @@ namespace net { namespace { -// TODO(eroman): Move this to shared location, so it can be used by -// TCPClientSocketWin. -class AddressListNetLogParam : public NetLog::EventParameters { - public: - explicit AddressListNetLogParam(const AddressList& addresses) - : addresses_(addresses) {} - - virtual Value* ToValue() const { - DictionaryValue* dict = new DictionaryValue(); - ListValue* list = new ListValue(); - - for (const addrinfo* head = addresses_.head(); - head != NULL ; head = head->ai_next) { - list->Append(Value::CreateStringValue(NetAddressToString(head))); - } - - dict->Set(L"addresses", list); - return dict; - } - - private: - AddressList addresses_; -}; - const int kInvalidSocket = -1; // DisableNagle turns off buffering in the kernel. By default, TCP sockets will @@ -237,9 +213,9 @@ int TCPClientSocketLibevent::DoConnect() { } int TCPClientSocketLibevent::DoConnectComplete(int result) { + // Log the end of this attempt (and any OS error it threw). int os_error = connect_os_error_; connect_os_error_ = 0; - scoped_refptr<NetLog::EventParameters> params; if (result != OK) params = new NetLogIntegerParameter("os_error", os_error); diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc index f1a1602..7c6f41d 100644 --- a/net/socket/tcp_client_socket_win.cc +++ b/net/socket/tcp_client_socket_win.cc @@ -10,10 +10,12 @@ #include "base/stats_counters.h" #include "base/string_util.h" #include "base/sys_info.h" +#include "net/base/address_list_net_log_param.h" #include "net/base/connection_type_histograms.h" #include "net/base/io_buffer.h" -#include "net/base/net_log.h" #include "net/base/net_errors.h" +#include "net/base/net_log.h" +#include "net/base/net_util.h" #include "net/base/sys_addrinfo.h" #include "net/base/winsock_init.h" @@ -263,6 +265,7 @@ TCPClientSocketWin::TCPClientSocketWin(const AddressList& addresses, read_callback_(NULL), write_callback_(NULL), next_connect_state_(CONNECT_STATE_NONE), + connect_os_error_(0), net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { EnsureWinsockInit(); } @@ -282,7 +285,8 @@ int TCPClientSocketWin::Connect(CompletionCallback* callback) { static StatsCounter connects("tcp.connect"); connects.Increment(); - net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT, NULL); + net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT, + new AddressListNetLogParam(addresses_)); // We will try to connect to each address in addresses_. Start with the // first one in the list. @@ -329,12 +333,17 @@ int TCPClientSocketWin::DoConnectLoop(int result) { int TCPClientSocketWin::DoConnect() { const struct addrinfo* ai = current_ai_; DCHECK(ai); + DCHECK_EQ(0, connect_os_error_); + + net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, + new NetLogStringParameter( + "address", NetAddressToString(current_ai_))); next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE; - int rv = CreateSocket(ai); - if (rv != OK) - return rv; + connect_os_error_ = CreateSocket(ai); + if (connect_os_error_ != 0) + return MapWinsockError(connect_os_error_); DCHECK(!core_); core_ = new Core(this); @@ -366,6 +375,7 @@ int TCPClientSocketWin::DoConnect() { int os_error = WSAGetLastError(); if (os_error != WSAEWOULDBLOCK) { LOG(ERROR) << "connect failed: " << os_error; + connect_os_error_ = os_error; return MapConnectError(os_error); } } @@ -375,6 +385,14 @@ int TCPClientSocketWin::DoConnect() { } int TCPClientSocketWin::DoConnectComplete(int result) { + // Log the end of this attempt (and any OS error it threw). + int os_error = connect_os_error_; + connect_os_error_ = 0; + scoped_refptr<NetLog::EventParameters> params; + if (result != OK) + params = new NetLogIntegerParameter("os_error", os_error); + net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, params); + if (result == OK) return OK; // Done! @@ -595,7 +613,7 @@ int TCPClientSocketWin::CreateSocket(const struct addrinfo* ai) { if (socket_ == INVALID_SOCKET) { int os_error = WSAGetLastError(); LOG(ERROR) << "WSASocket failed: " << os_error; - return MapWinsockError(os_error); + return os_error; } // Increase the socket buffer sizes from the default sizes for WinXP. In @@ -644,11 +662,15 @@ int TCPClientSocketWin::CreateSocket(const struct addrinfo* ai) { reinterpret_cast<const char*>(&kDisableNagle), sizeof(kDisableNagle)); DCHECK(!rv) << "Could not disable nagle"; - return OK; + // Disregard any failure in disabling nagle. + return 0; } void TCPClientSocketWin::LogConnectCompletion(int net_error) { - net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT, NULL); + scoped_refptr<NetLog::EventParameters> params; + if (net_error != OK) + params = new NetLogIntegerParameter("net_error", net_error); + net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT, params); if (net_error == OK) UpdateConnectionTypeHistograms(CONNECTION_ANY); } @@ -686,16 +708,20 @@ void TCPClientSocketWin::DidCompleteConnect() { WSANETWORKEVENTS events; int rv = WSAEnumNetworkEvents(socket_, core_->read_overlapped_.hEvent, &events); + int os_error = 0; if (rv == SOCKET_ERROR) { NOTREACHED(); - result = MapWinsockError(WSAGetLastError()); + os_error = WSAGetLastError(); + result = MapWinsockError(os_error); } else if (events.lNetworkEvents & FD_CONNECT) { - result = MapConnectError(events.iErrorCode[FD_CONNECT_BIT]); + os_error = events.iErrorCode[FD_CONNECT_BIT]; + result = MapConnectError(os_error); } else { NOTREACHED(); result = ERR_UNEXPECTED; } + connect_os_error_ = os_error; rv = DoConnectLoop(result); if (rv != ERR_IO_PENDING) { LogConnectCompletion(rv); diff --git a/net/socket/tcp_client_socket_win.h b/net/socket/tcp_client_socket_win.h index a2b1fcf..4ac57a8 100644 --- a/net/socket/tcp_client_socket_win.h +++ b/net/socket/tcp_client_socket_win.h @@ -68,6 +68,7 @@ class TCPClientSocketWin : public ClientSocket, NonThreadSafe { return next_connect_state_ != CONNECT_STATE_NONE; } + // Returns the OS error code (or 0 on success). int CreateSocket(const struct addrinfo* ai); // Called after Connect() has completed with |net_error|. @@ -105,6 +106,9 @@ class TCPClientSocketWin : public ClientSocket, NonThreadSafe { // The next state for the Connect() state machine. ConnectState next_connect_state_; + // The OS error that CONNECT_STATE_CONNECT last completed with. + int connect_os_error_; + BoundNetLog net_log_; DISALLOW_COPY_AND_ASSIGN(TCPClientSocketWin); |