OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <mstcpip.h> | 7 #include <mstcpip.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 core_ = new Core(this); | 324 core_ = new Core(this); |
325 | 325 |
326 // WSACreateEvent creates a manual-reset event object. | 326 // WSACreateEvent creates a manual-reset event object. |
327 core_->read_overlapped_.hEvent = WSACreateEvent(); | 327 core_->read_overlapped_.hEvent = WSACreateEvent(); |
328 // WSAEventSelect sets the socket to non-blocking mode as a side effect. | 328 // WSAEventSelect sets the socket to non-blocking mode as a side effect. |
329 // Our connect() and recv() calls require that the socket be non-blocking. | 329 // Our connect() and recv() calls require that the socket be non-blocking. |
330 WSAEventSelect(socket_, core_->read_overlapped_.hEvent, FD_CONNECT); | 330 WSAEventSelect(socket_, core_->read_overlapped_.hEvent, FD_CONNECT); |
331 | 331 |
332 core_->write_overlapped_.hEvent = WSACreateEvent(); | 332 core_->write_overlapped_.hEvent = WSACreateEvent(); |
333 | 333 |
| 334 connect_start_time_ = base::Time::Now(); |
334 if (!connect(socket_, ai->ai_addr, static_cast<int>(ai->ai_addrlen))) { | 335 if (!connect(socket_, ai->ai_addr, static_cast<int>(ai->ai_addrlen))) { |
335 // Connected without waiting! | 336 // Connected without waiting! |
336 // | 337 // |
337 // The MSDN page for connect says: | 338 // The MSDN page for connect says: |
338 // With a nonblocking socket, the connection attempt cannot be completed | 339 // With a nonblocking socket, the connection attempt cannot be completed |
339 // immediately. In this case, connect will return SOCKET_ERROR, and | 340 // immediately. In this case, connect will return SOCKET_ERROR, and |
340 // WSAGetLastError will return WSAEWOULDBLOCK. | 341 // WSAGetLastError will return WSAEWOULDBLOCK. |
341 // which implies that for a nonblocking socket, connect never returns 0. | 342 // which implies that for a nonblocking socket, connect never returns 0. |
342 // It's not documented whether the event object will be signaled or not | 343 // It's not documented whether the event object will be signaled or not |
343 // if connect does return 0. So the code below is essentially dead code | 344 // if connect does return 0. So the code below is essentially dead code |
(...skipping 18 matching lines...) Expand all Loading... |
362 int TCPClientSocketWin::DoConnectComplete(int result) { | 363 int TCPClientSocketWin::DoConnectComplete(int result) { |
363 // Log the end of this attempt (and any OS error it threw). | 364 // Log the end of this attempt (and any OS error it threw). |
364 int os_error = connect_os_error_; | 365 int os_error = connect_os_error_; |
365 connect_os_error_ = 0; | 366 connect_os_error_ = 0; |
366 scoped_refptr<NetLog::EventParameters> params; | 367 scoped_refptr<NetLog::EventParameters> params; |
367 if (result != OK) | 368 if (result != OK) |
368 params = new NetLogIntegerParameter("os_error", os_error); | 369 params = new NetLogIntegerParameter("os_error", os_error); |
369 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, params); | 370 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, params); |
370 | 371 |
371 if (result == OK) { | 372 if (result == OK) { |
| 373 rtt_ms_ = static_cast<double>((base::Time::Now() - |
| 374 connect_start_time_).InMicroseconds()) |
| 375 / 1000.0; |
372 use_history_.set_was_ever_connected(); | 376 use_history_.set_was_ever_connected(); |
373 return OK; // Done! | 377 return OK; // Done! |
374 } | 378 } |
375 | 379 |
376 // Close whatever partially connected socket we currently have. | 380 // Close whatever partially connected socket we currently have. |
377 DoDisconnect(); | 381 DoDisconnect(); |
378 | 382 |
379 // Try to fall back to the next address in the list. | 383 // Try to fall back to the next address in the list. |
380 if (current_ai_->ai_next) { | 384 if (current_ai_->ai_next) { |
381 next_connect_state_ = CONNECT_STATE_CONNECT; | 385 next_connect_state_ = CONNECT_STATE_CONNECT; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 if (ResetEventIfSignaled(core_->read_overlapped_.hEvent)) { | 532 if (ResetEventIfSignaled(core_->read_overlapped_.hEvent)) { |
529 // Because of how WSARecv fills memory when used asynchronously, Purify | 533 // Because of how WSARecv fills memory when used asynchronously, Purify |
530 // isn't able to detect that it's been initialized, so it scans for 0xcd | 534 // isn't able to detect that it's been initialized, so it scans for 0xcd |
531 // in the buffer and reports UMRs (uninitialized memory reads) for those | 535 // in the buffer and reports UMRs (uninitialized memory reads) for those |
532 // individual bytes. We override that in PURIFY builds to avoid the | 536 // individual bytes. We override that in PURIFY builds to avoid the |
533 // false error reports. | 537 // false error reports. |
534 // See bug 5297. | 538 // See bug 5297. |
535 base::MemoryDebug::MarkAsInitialized(core_->read_buffer_.buf, num); | 539 base::MemoryDebug::MarkAsInitialized(core_->read_buffer_.buf, num); |
536 base::StatsCounter read_bytes("tcp.read_bytes"); | 540 base::StatsCounter read_bytes("tcp.read_bytes"); |
537 read_bytes.Add(num); | 541 read_bytes.Add(num); |
| 542 num_bytes_read_ += num; |
538 if (num > 0) | 543 if (num > 0) |
539 use_history_.set_was_used_to_convey_data(); | 544 use_history_.set_was_used_to_convey_data(); |
540 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, num, | 545 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, num, |
541 core_->read_buffer_.buf); | 546 core_->read_buffer_.buf); |
542 return static_cast<int>(num); | 547 return static_cast<int>(num); |
543 } | 548 } |
544 } else { | 549 } else { |
545 int os_error = WSAGetLastError(); | 550 int os_error = WSAGetLastError(); |
546 if (os_error != WSA_IO_PENDING) | 551 if (os_error != WSA_IO_PENDING) |
547 return MapSystemError(os_error); | 552 return MapSystemError(os_error); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 use_history_.set_was_used_to_convey_data(); | 829 use_history_.set_was_used_to_convey_data(); |
825 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, | 830 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, |
826 core_->write_buffer_.buf); | 831 core_->write_buffer_.buf); |
827 } | 832 } |
828 } | 833 } |
829 core_->write_iobuffer_ = NULL; | 834 core_->write_iobuffer_ = NULL; |
830 DoWriteCallback(rv); | 835 DoWriteCallback(rv); |
831 } | 836 } |
832 | 837 |
833 } // namespace net | 838 } // namespace net |
OLD | NEW |