OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_socket.h" | 5 #include "net/socket/tcp_socket.h" |
6 #include "net/socket/tcp_socket_win.h" | 6 #include "net/socket/tcp_socket_win.h" |
7 | 7 |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <mstcpip.h> | 9 #include <mstcpip.h> |
10 | 10 |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 core_ = new Core(this); | 807 core_ = new Core(this); |
808 | 808 |
809 // WSAEventSelect sets the socket to non-blocking mode as a side effect. | 809 // WSAEventSelect sets the socket to non-blocking mode as a side effect. |
810 // Our connect() and recv() calls require that the socket be non-blocking. | 810 // Our connect() and recv() calls require that the socket be non-blocking. |
811 WSAEventSelect(socket_, core_->read_overlapped_.hEvent, FD_CONNECT); | 811 WSAEventSelect(socket_, core_->read_overlapped_.hEvent, FD_CONNECT); |
812 | 812 |
813 SockaddrStorage storage; | 813 SockaddrStorage storage; |
814 if (!peer_address_->ToSockAddr(storage.addr, &storage.addr_len)) | 814 if (!peer_address_->ToSockAddr(storage.addr, &storage.addr_len)) |
815 return ERR_ADDRESS_INVALID; | 815 return ERR_ADDRESS_INVALID; |
816 | 816 |
817 int result; | 817 if (!connect(socket_, storage.addr, storage.addr_len)) { |
818 int os_error; | |
819 { | |
820 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. | |
821 tracked_objects::ScopedTracker tracking_profile( | |
822 FROM_HERE_WITH_EXPLICIT_FUNCTION("436634 connect()")); | |
823 result = connect(socket_, storage.addr, storage.addr_len); | |
824 os_error = WSAGetLastError(); | |
825 } | |
826 | |
827 if (!result) { | |
828 // Connected without waiting! | 818 // Connected without waiting! |
829 // | 819 // |
830 // The MSDN page for connect says: | 820 // The MSDN page for connect says: |
831 // With a nonblocking socket, the connection attempt cannot be completed | 821 // With a nonblocking socket, the connection attempt cannot be completed |
832 // immediately. In this case, connect will return SOCKET_ERROR, and | 822 // immediately. In this case, connect will return SOCKET_ERROR, and |
833 // WSAGetLastError will return WSAEWOULDBLOCK. | 823 // WSAGetLastError will return WSAEWOULDBLOCK. |
834 // which implies that for a nonblocking socket, connect never returns 0. | 824 // which implies that for a nonblocking socket, connect never returns 0. |
835 // It's not documented whether the event object will be signaled or not | 825 // It's not documented whether the event object will be signaled or not |
836 // if connect does return 0. So the code below is essentially dead code | 826 // if connect does return 0. So the code below is essentially dead code |
837 // and we don't know if it's correct. | 827 // and we don't know if it's correct. |
838 NOTREACHED(); | 828 NOTREACHED(); |
839 | 829 |
840 if (ResetEventIfSignaled(core_->read_overlapped_.hEvent)) | 830 if (ResetEventIfSignaled(core_->read_overlapped_.hEvent)) |
841 return OK; | 831 return OK; |
842 } else { | 832 } else { |
| 833 int os_error = WSAGetLastError(); |
843 if (os_error != WSAEWOULDBLOCK) { | 834 if (os_error != WSAEWOULDBLOCK) { |
844 LOG(ERROR) << "connect failed: " << os_error; | 835 LOG(ERROR) << "connect failed: " << os_error; |
845 connect_os_error_ = os_error; | 836 connect_os_error_ = os_error; |
846 int rv = MapConnectError(os_error); | 837 int rv = MapConnectError(os_error); |
847 CHECK_NE(ERR_IO_PENDING, rv); | 838 CHECK_NE(ERR_IO_PENDING, rv); |
848 return rv; | 839 return rv; |
849 } | 840 } |
850 } | 841 } |
851 | 842 |
852 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. | |
853 tracked_objects::ScopedTracker tracking_profile( | |
854 FROM_HERE_WITH_EXPLICIT_FUNCTION("436634 WatchForRead()")); | |
855 | |
856 core_->WatchForRead(); | 843 core_->WatchForRead(); |
857 return ERR_IO_PENDING; | 844 return ERR_IO_PENDING; |
858 } | 845 } |
859 | 846 |
860 void TCPSocketWin::DoConnectComplete(int result) { | 847 void TCPSocketWin::DoConnectComplete(int result) { |
861 // Log the end of this attempt (and any OS error it threw). | 848 // Log the end of this attempt (and any OS error it threw). |
862 int os_error = connect_os_error_; | 849 int os_error = connect_os_error_; |
863 connect_os_error_ = 0; | 850 connect_os_error_ = 0; |
864 if (result != OK) { | 851 if (result != OK) { |
865 net_log_.EndEvent(NetLogEventType::TCP_CONNECT_ATTEMPT, | 852 net_log_.EndEvent(NetLogEventType::TCP_CONNECT_ATTEMPT, |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 } | 1030 } |
1044 | 1031 |
1045 bool TCPSocketWin::GetEstimatedRoundTripTime(base::TimeDelta* out_rtt) const { | 1032 bool TCPSocketWin::GetEstimatedRoundTripTime(base::TimeDelta* out_rtt) const { |
1046 DCHECK(out_rtt); | 1033 DCHECK(out_rtt); |
1047 // TODO(bmcquade): Consider implementing using | 1034 // TODO(bmcquade): Consider implementing using |
1048 // GetPerTcpConnectionEStats/GetPerTcp6ConnectionEStats. | 1035 // GetPerTcpConnectionEStats/GetPerTcp6ConnectionEStats. |
1049 return false; | 1036 return false; |
1050 } | 1037 } |
1051 | 1038 |
1052 } // namespace net | 1039 } // namespace net |
OLD | NEW |