| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory_debug.h" | 9 #include "base/memory_debug.h" |
| 10 #include "base/metrics/stats_counters.h" | 10 #include "base/metrics/stats_counters.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 13 #include "base/win/object_watcher.h" |
| 13 #include "net/base/address_list_net_log_param.h" | 14 #include "net/base/address_list_net_log_param.h" |
| 14 #include "net/base/connection_type_histograms.h" | 15 #include "net/base/connection_type_histograms.h" |
| 15 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 17 #include "net/base/net_log.h" | 18 #include "net/base/net_log.h" |
| 18 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 19 #include "net/base/network_change_notifier.h" | 20 #include "net/base/network_change_notifier.h" |
| 20 #include "net/base/sys_addrinfo.h" | 21 #include "net/base/sys_addrinfo.h" |
| 21 #include "net/base/winsock_init.h" | 22 #include "net/base/winsock_init.h" |
| 22 | 23 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 if (slow_start_throttle_ < kMaxSlowStartThrottle) { | 164 if (slow_start_throttle_ < kMaxSlowStartThrottle) { |
| 164 size = std::min(size, slow_start_throttle_); | 165 size = std::min(size, slow_start_throttle_); |
| 165 slow_start_throttle_ *= 2; | 166 slow_start_throttle_ *= 2; |
| 166 } | 167 } |
| 167 return size; | 168 return size; |
| 168 } | 169 } |
| 169 | 170 |
| 170 private: | 171 private: |
| 171 friend class base::RefCounted<Core>; | 172 friend class base::RefCounted<Core>; |
| 172 | 173 |
| 173 class ReadDelegate : public base::ObjectWatcher::Delegate { | 174 class ReadDelegate : public base::win::ObjectWatcher::Delegate { |
| 174 public: | 175 public: |
| 175 explicit ReadDelegate(Core* core) : core_(core) {} | 176 explicit ReadDelegate(Core* core) : core_(core) {} |
| 176 virtual ~ReadDelegate() {} | 177 virtual ~ReadDelegate() {} |
| 177 | 178 |
| 178 // base::ObjectWatcher::Delegate methods: | 179 // base::ObjectWatcher::Delegate methods: |
| 179 virtual void OnObjectSignaled(HANDLE object); | 180 virtual void OnObjectSignaled(HANDLE object); |
| 180 | 181 |
| 181 private: | 182 private: |
| 182 Core* const core_; | 183 Core* const core_; |
| 183 }; | 184 }; |
| 184 | 185 |
| 185 class WriteDelegate : public base::ObjectWatcher::Delegate { | 186 class WriteDelegate : public base::win::ObjectWatcher::Delegate { |
| 186 public: | 187 public: |
| 187 explicit WriteDelegate(Core* core) : core_(core) {} | 188 explicit WriteDelegate(Core* core) : core_(core) {} |
| 188 virtual ~WriteDelegate() {} | 189 virtual ~WriteDelegate() {} |
| 189 | 190 |
| 190 // base::ObjectWatcher::Delegate methods: | 191 // base::ObjectWatcher::Delegate methods: |
| 191 virtual void OnObjectSignaled(HANDLE object); | 192 virtual void OnObjectSignaled(HANDLE object); |
| 192 | 193 |
| 193 private: | 194 private: |
| 194 Core* const core_; | 195 Core* const core_; |
| 195 }; | 196 }; |
| 196 | 197 |
| 197 ~Core(); | 198 ~Core(); |
| 198 | 199 |
| 199 // The socket that created this object. | 200 // The socket that created this object. |
| 200 TCPClientSocketWin* socket_; | 201 TCPClientSocketWin* socket_; |
| 201 | 202 |
| 202 // |reader_| handles the signals from |read_watcher_|. | 203 // |reader_| handles the signals from |read_watcher_|. |
| 203 ReadDelegate reader_; | 204 ReadDelegate reader_; |
| 204 // |writer_| handles the signals from |write_watcher_|. | 205 // |writer_| handles the signals from |write_watcher_|. |
| 205 WriteDelegate writer_; | 206 WriteDelegate writer_; |
| 206 | 207 |
| 207 // |read_watcher_| watches for events from Connect() and Read(). | 208 // |read_watcher_| watches for events from Connect() and Read(). |
| 208 base::ObjectWatcher read_watcher_; | 209 base::win::ObjectWatcher read_watcher_; |
| 209 // |write_watcher_| watches for events from Write(); | 210 // |write_watcher_| watches for events from Write(); |
| 210 base::ObjectWatcher write_watcher_; | 211 base::win::ObjectWatcher write_watcher_; |
| 211 | 212 |
| 212 // When doing reads from the socket, we try to mirror TCP's slow start. | 213 // When doing reads from the socket, we try to mirror TCP's slow start. |
| 213 // We do this because otherwise the async IO subsystem artifically delays | 214 // We do this because otherwise the async IO subsystem artifically delays |
| 214 // returning data to the application. | 215 // returning data to the application. |
| 215 static const int kInitialSlowStartThrottle = 1 * 1024; | 216 static const int kInitialSlowStartThrottle = 1 * 1024; |
| 216 static const int kMaxSlowStartThrottle = 32 * kInitialSlowStartThrottle; | 217 static const int kMaxSlowStartThrottle = 32 * kInitialSlowStartThrottle; |
| 217 int slow_start_throttle_; | 218 int slow_start_throttle_; |
| 218 | 219 |
| 219 DISALLOW_COPY_AND_ASSIGN(Core); | 220 DISALLOW_COPY_AND_ASSIGN(Core); |
| 220 }; | 221 }; |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 use_history_.set_was_used_to_convey_data(); | 841 use_history_.set_was_used_to_convey_data(); |
| 841 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, | 842 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, |
| 842 core_->write_buffer_.buf); | 843 core_->write_buffer_.buf); |
| 843 } | 844 } |
| 844 } | 845 } |
| 845 core_->write_iobuffer_ = NULL; | 846 core_->write_iobuffer_ = NULL; |
| 846 DoWriteCallback(rv); | 847 DoWriteCallback(rv); |
| 847 } | 848 } |
| 848 | 849 |
| 849 } // namespace net | 850 } // namespace net |
| OLD | NEW |