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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 core_ = new Core(this); | 480 core_ = new Core(this); |
481 | 481 |
482 // WSACreateEvent creates a manual-reset event object. | 482 // WSACreateEvent creates a manual-reset event object. |
483 core_->read_overlapped_.hEvent = WSACreateEvent(); | 483 core_->read_overlapped_.hEvent = WSACreateEvent(); |
484 // WSAEventSelect sets the socket to non-blocking mode as a side effect. | 484 // WSAEventSelect sets the socket to non-blocking mode as a side effect. |
485 // Our connect() and recv() calls require that the socket be non-blocking. | 485 // Our connect() and recv() calls require that the socket be non-blocking. |
486 WSAEventSelect(socket_, core_->read_overlapped_.hEvent, FD_CONNECT); | 486 WSAEventSelect(socket_, core_->read_overlapped_.hEvent, FD_CONNECT); |
487 | 487 |
488 core_->write_overlapped_.hEvent = WSACreateEvent(); | 488 core_->write_overlapped_.hEvent = WSACreateEvent(); |
489 | 489 |
490 connect_start_time_ = base::Time::Now(); | |
490 if (!connect(socket_, ai->ai_addr, static_cast<int>(ai->ai_addrlen))) { | 491 if (!connect(socket_, ai->ai_addr, static_cast<int>(ai->ai_addrlen))) { |
491 // Connected without waiting! | 492 // Connected without waiting! |
492 // | 493 // |
493 // The MSDN page for connect says: | 494 // The MSDN page for connect says: |
494 // With a nonblocking socket, the connection attempt cannot be completed | 495 // With a nonblocking socket, the connection attempt cannot be completed |
495 // immediately. In this case, connect will return SOCKET_ERROR, and | 496 // immediately. In this case, connect will return SOCKET_ERROR, and |
496 // WSAGetLastError will return WSAEWOULDBLOCK. | 497 // WSAGetLastError will return WSAEWOULDBLOCK. |
497 // which implies that for a nonblocking socket, connect never returns 0. | 498 // which implies that for a nonblocking socket, connect never returns 0. |
498 // It's not documented whether the event object will be signaled or not | 499 // It's not documented whether the event object will be signaled or not |
499 // if connect does return 0. So the code below is essentially dead code | 500 // if connect does return 0. So the code below is essentially dead code |
(...skipping 18 matching lines...) Expand all Loading... | |
518 int TCPClientSocketWin::DoConnectComplete(int result) { | 519 int TCPClientSocketWin::DoConnectComplete(int result) { |
519 // Log the end of this attempt (and any OS error it threw). | 520 // Log the end of this attempt (and any OS error it threw). |
520 int os_error = connect_os_error_; | 521 int os_error = connect_os_error_; |
521 connect_os_error_ = 0; | 522 connect_os_error_ = 0; |
522 scoped_refptr<NetLog::EventParameters> params; | 523 scoped_refptr<NetLog::EventParameters> params; |
523 if (result != OK) | 524 if (result != OK) |
524 params = new NetLogIntegerParameter("os_error", os_error); | 525 params = new NetLogIntegerParameter("os_error", os_error); |
525 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, params); | 526 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, params); |
526 | 527 |
527 if (result == OK) { | 528 if (result == OK) { |
529 rtt_ms_ = static_cast<double>((base::Time::Now() - | |
530 connect_start_time_).InMicroseconds()) | |
531 / 1000.0; | |
willchan no longer on Chromium
2011/06/09 15:08:54
same comments as in the libevent socket
Gagan
2011/06/09 19:49:26
please let me know if you prefer rtt in microsecon
willchan no longer on Chromium
2011/06/10 15:05:55
milliseconds makes sense to me.
Gagan
2011/06/10 17:44:17
I changed it to micros in the last patch. It allow
| |
528 use_history_.set_was_ever_connected(); | 532 use_history_.set_was_ever_connected(); |
529 return OK; // Done! | 533 return OK; // Done! |
530 } | 534 } |
531 | 535 |
532 // Close whatever partially connected socket we currently have. | 536 // Close whatever partially connected socket we currently have. |
533 DoDisconnect(); | 537 DoDisconnect(); |
534 | 538 |
535 // Try to fall back to the next address in the list. | 539 // Try to fall back to the next address in the list. |
536 if (current_ai_->ai_next) { | 540 if (current_ai_->ai_next) { |
537 next_connect_state_ = CONNECT_STATE_CONNECT; | 541 next_connect_state_ = CONNECT_STATE_CONNECT; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 if (ResetEventIfSignaled(core_->read_overlapped_.hEvent)) { | 688 if (ResetEventIfSignaled(core_->read_overlapped_.hEvent)) { |
685 // Because of how WSARecv fills memory when used asynchronously, Purify | 689 // Because of how WSARecv fills memory when used asynchronously, Purify |
686 // isn't able to detect that it's been initialized, so it scans for 0xcd | 690 // isn't able to detect that it's been initialized, so it scans for 0xcd |
687 // in the buffer and reports UMRs (uninitialized memory reads) for those | 691 // in the buffer and reports UMRs (uninitialized memory reads) for those |
688 // individual bytes. We override that in PURIFY builds to avoid the | 692 // individual bytes. We override that in PURIFY builds to avoid the |
689 // false error reports. | 693 // false error reports. |
690 // See bug 5297. | 694 // See bug 5297. |
691 base::MemoryDebug::MarkAsInitialized(core_->read_buffer_.buf, num); | 695 base::MemoryDebug::MarkAsInitialized(core_->read_buffer_.buf, num); |
692 base::StatsCounter read_bytes("tcp.read_bytes"); | 696 base::StatsCounter read_bytes("tcp.read_bytes"); |
693 read_bytes.Add(num); | 697 read_bytes.Add(num); |
698 num_bytes_read_ += num; | |
694 if (num > 0) | 699 if (num > 0) |
695 use_history_.set_was_used_to_convey_data(); | 700 use_history_.set_was_used_to_convey_data(); |
696 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, num, | 701 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, num, |
697 core_->read_buffer_.buf); | 702 core_->read_buffer_.buf); |
698 return static_cast<int>(num); | 703 return static_cast<int>(num); |
699 } | 704 } |
700 } else { | 705 } else { |
701 int os_error = WSAGetLastError(); | 706 int os_error = WSAGetLastError(); |
702 if (os_error != WSA_IO_PENDING) | 707 if (os_error != WSA_IO_PENDING) |
703 return MapSystemError(os_error); | 708 return MapSystemError(os_error); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
854 DCHECK(waiting_read_); | 859 DCHECK(waiting_read_); |
855 DWORD num_bytes, flags; | 860 DWORD num_bytes, flags; |
856 BOOL ok = WSAGetOverlappedResult(socket_, &core_->read_overlapped_, | 861 BOOL ok = WSAGetOverlappedResult(socket_, &core_->read_overlapped_, |
857 &num_bytes, FALSE, &flags); | 862 &num_bytes, FALSE, &flags); |
858 WSAResetEvent(core_->read_overlapped_.hEvent); | 863 WSAResetEvent(core_->read_overlapped_.hEvent); |
859 waiting_read_ = false; | 864 waiting_read_ = false; |
860 core_->read_iobuffer_ = NULL; | 865 core_->read_iobuffer_ = NULL; |
861 if (ok) { | 866 if (ok) { |
862 base::StatsCounter read_bytes("tcp.read_bytes"); | 867 base::StatsCounter read_bytes("tcp.read_bytes"); |
863 read_bytes.Add(num_bytes); | 868 read_bytes.Add(num_bytes); |
869 num_bytes_read_ += num_bytes; | |
864 if (num_bytes > 0) | 870 if (num_bytes > 0) |
865 use_history_.set_was_used_to_convey_data(); | 871 use_history_.set_was_used_to_convey_data(); |
866 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, | 872 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, |
867 num_bytes, core_->read_buffer_.buf); | 873 num_bytes, core_->read_buffer_.buf); |
868 } | 874 } |
869 DoReadCallback(ok ? num_bytes : MapSystemError(WSAGetLastError())); | 875 DoReadCallback(ok ? num_bytes : MapSystemError(WSAGetLastError())); |
870 } | 876 } |
871 | 877 |
872 void TCPClientSocketWin::DidCompleteWrite() { | 878 void TCPClientSocketWin::DidCompleteWrite() { |
873 DCHECK(waiting_write_); | 879 DCHECK(waiting_write_); |
(...skipping 22 matching lines...) Expand all Loading... | |
896 use_history_.set_was_used_to_convey_data(); | 902 use_history_.set_was_used_to_convey_data(); |
897 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, | 903 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, |
898 core_->write_buffer_.buf); | 904 core_->write_buffer_.buf); |
899 } | 905 } |
900 } | 906 } |
901 core_->write_iobuffer_ = NULL; | 907 core_->write_iobuffer_ = NULL; |
902 DoWriteCallback(rv); | 908 DoWriteCallback(rv); |
903 } | 909 } |
904 | 910 |
905 } // namespace net | 911 } // namespace net |
OLD | NEW |