Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: net/socket/tcp_client_socket_win.cc

Issue 848006: Generalize the net module's LoadLog facility from a passive container, to an event stream (NetLog). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Split up RequestTracker into ConnectJobTracker+RequestTracker+RequestTrackerBase, address comments Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/socket/tcp_client_socket_win.h ('k') | net/socket_stream/socket_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/socket/tcp_client_socket_win.h" 5 #include "net/socket/tcp_client_socket_win.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory_debug.h" 9 #include "base/memory_debug.h"
10 #include "base/stats_counters.h" 10 #include "base/stats_counters.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/sys_info.h" 12 #include "base/sys_info.h"
13 #include "base/trace_event.h" 13 #include "base/trace_event.h"
14 #include "net/base/connection_type_histograms.h" 14 #include "net/base/connection_type_histograms.h"
15 #include "net/base/io_buffer.h" 15 #include "net/base/io_buffer.h"
16 #include "net/base/load_log.h" 16 #include "net/base/net_log.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "net/base/sys_addrinfo.h" 18 #include "net/base/sys_addrinfo.h"
19 #include "net/base/winsock_init.h" 19 #include "net/base/winsock_init.h"
20 20
21 namespace net { 21 namespace net {
22 22
23 namespace { 23 namespace {
24 24
25 // If the (manual-reset) event object is signaled, resets it and returns true. 25 // If the (manual-reset) event object is signaled, resets it and returns true.
26 // Otherwise, does nothing and returns false. Called after a Winsock function 26 // Otherwise, does nothing and returns false. Called after a Winsock function
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 read_callback_(NULL), 281 read_callback_(NULL),
282 write_callback_(NULL) { 282 write_callback_(NULL) {
283 EnsureWinsockInit(); 283 EnsureWinsockInit();
284 } 284 }
285 285
286 TCPClientSocketWin::~TCPClientSocketWin() { 286 TCPClientSocketWin::~TCPClientSocketWin() {
287 Disconnect(); 287 Disconnect();
288 } 288 }
289 289
290 int TCPClientSocketWin::Connect(CompletionCallback* callback, 290 int TCPClientSocketWin::Connect(CompletionCallback* callback,
291 LoadLog* load_log) { 291 const BoundNetLog& net_log) {
292 // If already connected, then just return OK. 292 // If already connected, then just return OK.
293 if (socket_ != INVALID_SOCKET) 293 if (socket_ != INVALID_SOCKET)
294 return OK; 294 return OK;
295 295
296 DCHECK(!load_log_); 296 DCHECK(!net_log_.net_log());
297 297
298 static StatsCounter connects("tcp.connect"); 298 static StatsCounter connects("tcp.connect");
299 connects.Increment(); 299 connects.Increment();
300 300
301 TRACE_EVENT_BEGIN("socket.connect", this, ""); 301 TRACE_EVENT_BEGIN("socket.connect", this, "");
302 302
303 LoadLog::BeginEvent(load_log, LoadLog::TYPE_TCP_CONNECT); 303 net_log.BeginEvent(NetLog::TYPE_TCP_CONNECT);
304 304
305 int rv = DoConnect(); 305 int rv = DoConnect();
306 306
307 if (rv == ERR_IO_PENDING) { 307 if (rv == ERR_IO_PENDING) {
308 // Synchronous operation not supported. 308 // Synchronous operation not supported.
309 DCHECK(callback); 309 DCHECK(callback);
310 310
311 load_log_ = load_log; 311 net_log_ = net_log;
312 waiting_connect_ = true; 312 waiting_connect_ = true;
313 read_callback_ = callback; 313 read_callback_ = callback;
314 } else { 314 } else {
315 TRACE_EVENT_END("socket.connect", this, ""); 315 TRACE_EVENT_END("socket.connect", this, "");
316 LoadLog::EndEvent(load_log, LoadLog::TYPE_TCP_CONNECT); 316 net_log.EndEvent(NetLog::TYPE_TCP_CONNECT);
317 if (rv == OK) 317 if (rv == OK)
318 UpdateConnectionTypeHistograms(CONNECTION_ANY); 318 UpdateConnectionTypeHistograms(CONNECTION_ANY);
319 } 319 }
320 320
321 return rv; 321 return rv;
322 } 322 }
323 323
324 int TCPClientSocketWin::DoConnect() { 324 int TCPClientSocketWin::DoConnect() {
325 const struct addrinfo* ai = current_ai_; 325 const struct addrinfo* ai = current_ai_;
326 DCHECK(ai); 326 DCHECK(ai);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 if (rv == SOCKET_ERROR) { 651 if (rv == SOCKET_ERROR) {
652 NOTREACHED(); 652 NOTREACHED();
653 result = MapWinsockError(WSAGetLastError()); 653 result = MapWinsockError(WSAGetLastError());
654 } else if (events.lNetworkEvents & FD_CONNECT) { 654 } else if (events.lNetworkEvents & FD_CONNECT) {
655 int os_error = events.iErrorCode[FD_CONNECT_BIT]; 655 int os_error = events.iErrorCode[FD_CONNECT_BIT];
656 if (current_ai_->ai_next && ShouldTryNextAddress(os_error)) { 656 if (current_ai_->ai_next && ShouldTryNextAddress(os_error)) {
657 // Try using the next address. 657 // Try using the next address.
658 const struct addrinfo* next = current_ai_->ai_next; 658 const struct addrinfo* next = current_ai_->ai_next;
659 Disconnect(); 659 Disconnect();
660 current_ai_ = next; 660 current_ai_ = next;
661 scoped_refptr<LoadLog> load_log; 661 BoundNetLog net_log(net_log_);
662 load_log.swap(load_log_); 662 net_log_ = BoundNetLog();
663 TRACE_EVENT_END("socket.connect", this, ""); 663 TRACE_EVENT_END("socket.connect", this, "");
664 LoadLog::EndEvent(load_log, LoadLog::TYPE_TCP_CONNECT); 664 net_log.EndEvent(NetLog::TYPE_TCP_CONNECT);
665 result = Connect(read_callback_, load_log); 665 result = Connect(read_callback_, net_log);
666 } else { 666 } else {
667 result = MapConnectError(os_error); 667 result = MapConnectError(os_error);
668 TRACE_EVENT_END("socket.connect", this, ""); 668 TRACE_EVENT_END("socket.connect", this, "");
669 LoadLog::EndEvent(load_log_, LoadLog::TYPE_TCP_CONNECT); 669 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT);
670 load_log_ = NULL; 670 net_log_ = BoundNetLog();
671 } 671 }
672 } else { 672 } else {
673 NOTREACHED(); 673 NOTREACHED();
674 result = ERR_UNEXPECTED; 674 result = ERR_UNEXPECTED;
675 TRACE_EVENT_END("socket.connect", this, ""); 675 TRACE_EVENT_END("socket.connect", this, "");
676 LoadLog::EndEvent(load_log_, LoadLog::TYPE_TCP_CONNECT); 676 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT);
677 load_log_ = NULL; 677 net_log_ = BoundNetLog();
678 } 678 }
679 679
680 if (result != ERR_IO_PENDING) { 680 if (result != ERR_IO_PENDING) {
681 if (result == OK) 681 if (result == OK)
682 UpdateConnectionTypeHistograms(CONNECTION_ANY); 682 UpdateConnectionTypeHistograms(CONNECTION_ANY);
683 DoReadCallback(result); 683 DoReadCallback(result);
684 } 684 }
685 } 685 }
686 686
687 void TCPClientSocketWin::DidCompleteRead() { 687 void TCPClientSocketWin::DidCompleteRead() {
(...skipping 29 matching lines...) Expand all
717 << core_->write_buffer_length_ << " bytes, but " << rv 717 << core_->write_buffer_length_ << " bytes, but " << rv
718 << " bytes reported."; 718 << " bytes reported.";
719 rv = ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; 719 rv = ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES;
720 } 720 }
721 } 721 }
722 core_->write_iobuffer_ = NULL; 722 core_->write_iobuffer_ = NULL;
723 DoWriteCallback(rv); 723 DoWriteCallback(rv);
724 } 724 }
725 725
726 } // namespace net 726 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/tcp_client_socket_win.h ('k') | net/socket_stream/socket_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698