| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/stats_counters.h" | 12 #include "base/metrics/stats_counters.h" |
| 13 #include "base/profiler/scoped_profile.h" | 13 #include "base/profiler/scoped_tracker.h" |
| 14 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
| 15 #include "net/base/address_list.h" | 15 #include "net/base/address_list.h" |
| 16 #include "net/base/connection_type_histograms.h" | 16 #include "net/base/connection_type_histograms.h" |
| 17 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
| 18 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
| 19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 20 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 21 #include "net/base/network_change_notifier.h" | 21 #include "net/base/network_change_notifier.h" |
| 22 #include "net/base/winsock_init.h" | 22 #include "net/base/winsock_init.h" |
| 23 #include "net/base/winsock_util.h" | 23 #include "net/base/winsock_util.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 239 } |
| 240 | 240 |
| 241 void TCPSocketWin::Core::WatchForWrite() { | 241 void TCPSocketWin::Core::WatchForWrite() { |
| 242 // We grab an extra reference because there is an IO operation in progress. | 242 // We grab an extra reference because there is an IO operation in progress. |
| 243 // Balanced in WriteDelegate::OnObjectSignaled(). | 243 // Balanced in WriteDelegate::OnObjectSignaled(). |
| 244 AddRef(); | 244 AddRef(); |
| 245 write_watcher_.StartWatching(write_overlapped_.hEvent, &writer_); | 245 write_watcher_.StartWatching(write_overlapped_.hEvent, &writer_); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void TCPSocketWin::Core::ReadDelegate::OnObjectSignaled(HANDLE object) { | 248 void TCPSocketWin::Core::ReadDelegate::OnObjectSignaled(HANDLE object) { |
| 249 // TODO(vadimt): Remove ScopedProfile below once crbug.com/418183 is fixed. | 249 // TODO(vadimt): Remove ScopedTracker below once crbug.com/418183 is fixed. |
| 250 tracked_objects::ScopedProfile tracking_profile( | 250 tracked_objects::ScopedTracker tracking_profile( |
| 251 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 251 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 252 "TCPSocketWin_Core_ReadDelegate_OnObjectSignaled")); | 252 "TCPSocketWin_Core_ReadDelegate_OnObjectSignaled")); |
| 253 | 253 |
| 254 DCHECK_EQ(object, core_->read_overlapped_.hEvent); | 254 DCHECK_EQ(object, core_->read_overlapped_.hEvent); |
| 255 if (core_->socket_) { | 255 if (core_->socket_) { |
| 256 if (core_->socket_->waiting_connect_) | 256 if (core_->socket_->waiting_connect_) |
| 257 core_->socket_->DidCompleteConnect(); | 257 core_->socket_->DidCompleteConnect(); |
| 258 else | 258 else |
| 259 core_->socket_->DidSignalRead(); | 259 core_->socket_->DidSignalRead(); |
| 260 } | 260 } |
| 261 | 261 |
| 262 core_->Release(); | 262 core_->Release(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void TCPSocketWin::Core::WriteDelegate::OnObjectSignaled( | 265 void TCPSocketWin::Core::WriteDelegate::OnObjectSignaled( |
| 266 HANDLE object) { | 266 HANDLE object) { |
| 267 // TODO(vadimt): Remove ScopedProfile below once crbug.com/418183 is fixed. | 267 // TODO(vadimt): Remove ScopedTracker below once crbug.com/418183 is fixed. |
| 268 tracked_objects::ScopedProfile tracking_profile( | 268 tracked_objects::ScopedTracker tracking_profile( |
| 269 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 269 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 270 "TCPSocketWin_Core_WriteDelegate_OnObjectSignaled")); | 270 "TCPSocketWin_Core_WriteDelegate_OnObjectSignaled")); |
| 271 | 271 |
| 272 DCHECK_EQ(object, core_->write_overlapped_.hEvent); | 272 DCHECK_EQ(object, core_->write_overlapped_.hEvent); |
| 273 if (core_->socket_) | 273 if (core_->socket_) |
| 274 core_->socket_->DidCompleteWrite(); | 274 core_->socket_->DidCompleteWrite(); |
| 275 | 275 |
| 276 core_->Release(); | 276 core_->Release(); |
| 277 } | 277 } |
| 278 | 278 |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 return adopt_result; | 759 return adopt_result; |
| 760 } | 760 } |
| 761 *socket = tcp_socket.Pass(); | 761 *socket = tcp_socket.Pass(); |
| 762 *address = ip_end_point; | 762 *address = ip_end_point; |
| 763 net_log_.EndEvent(NetLog::TYPE_TCP_ACCEPT, | 763 net_log_.EndEvent(NetLog::TYPE_TCP_ACCEPT, |
| 764 CreateNetLogIPEndPointCallback(&ip_end_point)); | 764 CreateNetLogIPEndPointCallback(&ip_end_point)); |
| 765 return OK; | 765 return OK; |
| 766 } | 766 } |
| 767 | 767 |
| 768 void TCPSocketWin::OnObjectSignaled(HANDLE object) { | 768 void TCPSocketWin::OnObjectSignaled(HANDLE object) { |
| 769 // TODO(vadimt): Remove ScopedProfile below once crbug.com/418183 is fixed. | 769 // TODO(vadimt): Remove ScopedTracker below once crbug.com/418183 is fixed. |
| 770 tracked_objects::ScopedProfile tracking_profile( | 770 tracked_objects::ScopedTracker tracking_profile( |
| 771 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 771 FROM_HERE_WITH_EXPLICIT_FUNCTION("TCPSocketWin_OnObjectSignaled")); |
| 772 "TCPSocketWin_OnObjectSignaled")); | |
| 773 | 772 |
| 774 WSANETWORKEVENTS ev; | 773 WSANETWORKEVENTS ev; |
| 775 if (WSAEnumNetworkEvents(socket_, accept_event_, &ev) == SOCKET_ERROR) { | 774 if (WSAEnumNetworkEvents(socket_, accept_event_, &ev) == SOCKET_ERROR) { |
| 776 PLOG(ERROR) << "WSAEnumNetworkEvents()"; | 775 PLOG(ERROR) << "WSAEnumNetworkEvents()"; |
| 777 return; | 776 return; |
| 778 } | 777 } |
| 779 | 778 |
| 780 if (ev.lNetworkEvents & FD_ACCEPT) { | 779 if (ev.lNetworkEvents & FD_ACCEPT) { |
| 781 int result = AcceptInternal(accept_socket_, accept_address_); | 780 int result = AcceptInternal(accept_socket_, accept_address_); |
| 782 if (result != ERR_IO_PENDING) { | 781 if (result != ERR_IO_PENDING) { |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 // consume all the received data without resetting the event object. | 1027 // consume all the received data without resetting the event object. |
| 1029 core_->WatchForRead(); | 1028 core_->WatchForRead(); |
| 1030 return; | 1029 return; |
| 1031 } | 1030 } |
| 1032 | 1031 |
| 1033 waiting_read_ = false; | 1032 waiting_read_ = false; |
| 1034 core_->read_iobuffer_ = NULL; | 1033 core_->read_iobuffer_ = NULL; |
| 1035 core_->read_buffer_length_ = 0; | 1034 core_->read_buffer_length_ = 0; |
| 1036 | 1035 |
| 1037 DCHECK_NE(rv, ERR_IO_PENDING); | 1036 DCHECK_NE(rv, ERR_IO_PENDING); |
| 1038 // TODO(vadimt): Remove ScopedProfile below once crbug.com/418183 is fixed. | 1037 // TODO(vadimt): Remove ScopedTracker below once crbug.com/418183 is fixed. |
| 1039 tracked_objects::ScopedProfile tracking_profile( | 1038 tracked_objects::ScopedTracker tracking_profile( |
| 1040 FROM_HERE_WITH_EXPLICIT_FUNCTION("TCPSocketWin::DidSignalRead")); | 1039 FROM_HERE_WITH_EXPLICIT_FUNCTION("TCPSocketWin::DidSignalRead")); |
| 1041 base::ResetAndReturn(&read_callback_).Run(rv); | 1040 base::ResetAndReturn(&read_callback_).Run(rv); |
| 1042 } | 1041 } |
| 1043 | 1042 |
| 1044 } // namespace net | 1043 } // namespace net |
| OLD | NEW |