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