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 <mstcpip.h> | 8 #include <mstcpip.h> |
9 | 9 |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 return ERR_ADDRESS_INVALID; | 794 return ERR_ADDRESS_INVALID; |
795 | 795 |
796 int result; | 796 int result; |
797 { | 797 { |
798 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. | 798 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. |
799 tracked_objects::ScopedTracker tracking_profile( | 799 tracked_objects::ScopedTracker tracking_profile( |
800 FROM_HERE_WITH_EXPLICIT_FUNCTION("436634 connect()")); | 800 FROM_HERE_WITH_EXPLICIT_FUNCTION("436634 connect()")); |
801 result = connect(socket_, storage.addr, storage.addr_len); | 801 result = connect(socket_, storage.addr, storage.addr_len); |
802 } | 802 } |
803 | 803 |
804 // The MSDN page for connect says: | 804 if (!result) { |
805 // With a nonblocking socket, the connection attempt cannot be completed | 805 // Connected without waiting! |
806 // immediately. In this case, connect will return SOCKET_ERROR, and | 806 // |
807 // WSAGetLastError will return WSAEWOULDBLOCK. | 807 // The MSDN page for connect says: |
808 // which implies that for a nonblocking socket, connect never returns 0. | 808 // With a nonblocking socket, the connection attempt cannot be completed |
809 // It's not clear what the correct thing to do is if connect() | 809 // immediately. In this case, connect will return SOCKET_ERROR, and |
810 // returns 0. It's not clear whether this ever happens in practice. | 810 // WSAGetLastError will return WSAEWOULDBLOCK. |
811 // This CHECK() is here to verify that it doesn't. | 811 // which implies that for a nonblocking socket, connect never returns 0. |
812 // TODO(ricea): If the CHECK() fires in canary or dev, revert this | 812 // It's not documented whether the event object will be signaled or not |
813 // CL. If it doesn't, reconsider what we want to do here long-term. | 813 // if connect does return 0. So the code below is essentially dead code |
814 CHECK(result); | 814 // and we don't know if it's correct. |
| 815 NOTREACHED(); |
815 | 816 |
816 int os_error = WSAGetLastError(); | 817 if (ResetEventIfSignaled(core_->read_overlapped_.hEvent)) |
817 if (os_error != WSAEWOULDBLOCK) { | 818 return OK; |
818 LOG(ERROR) << "connect failed: " << os_error; | 819 } else { |
819 connect_os_error_ = os_error; | 820 int os_error = WSAGetLastError(); |
820 int rv = MapConnectError(os_error); | 821 if (os_error != WSAEWOULDBLOCK) { |
821 CHECK_NE(ERR_IO_PENDING, rv); | 822 LOG(ERROR) << "connect failed: " << os_error; |
822 return rv; | 823 connect_os_error_ = os_error; |
| 824 int rv = MapConnectError(os_error); |
| 825 CHECK_NE(ERR_IO_PENDING, rv); |
| 826 return rv; |
| 827 } |
823 } | 828 } |
824 | 829 |
825 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. | 830 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. |
826 tracked_objects::ScopedTracker tracking_profile( | 831 tracked_objects::ScopedTracker tracking_profile( |
827 FROM_HERE_WITH_EXPLICIT_FUNCTION("436634 WatchForRead()")); | 832 FROM_HERE_WITH_EXPLICIT_FUNCTION("436634 WatchForRead()")); |
828 | 833 |
829 core_->WatchForRead(); | 834 core_->WatchForRead(); |
830 return ERR_IO_PENDING; | 835 return ERR_IO_PENDING; |
831 } | 836 } |
832 | 837 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 | 1037 |
1033 waiting_read_ = false; | 1038 waiting_read_ = false; |
1034 core_->read_iobuffer_ = NULL; | 1039 core_->read_iobuffer_ = NULL; |
1035 core_->read_buffer_length_ = 0; | 1040 core_->read_buffer_length_ = 0; |
1036 | 1041 |
1037 DCHECK_NE(rv, ERR_IO_PENDING); | 1042 DCHECK_NE(rv, ERR_IO_PENDING); |
1038 base::ResetAndReturn(&read_callback_).Run(rv); | 1043 base::ResetAndReturn(&read_callback_).Run(rv); |
1039 } | 1044 } |
1040 | 1045 |
1041 } // namespace net | 1046 } // namespace net |
OLD | NEW |