Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Side by Side Diff: net/spdy/spdy_session.cc

Issue 2593063003: Add Socket::ReadIfReady() (Closed)
Patch Set: Address bnc comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/spdy/spdy_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/feature_list.h"
14 #include "base/location.h" 15 #include "base/location.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h" 18 #include "base/metrics/histogram_macros.h"
18 #include "base/metrics/sparse_histogram.h" 19 #include "base/metrics/sparse_histogram.h"
19 #include "base/profiler/scoped_tracker.h" 20 #include "base/profiler/scoped_tracker.h"
20 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
21 #include "base/stl_util.h" 22 #include "base/stl_util.h"
22 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
(...skipping 14 matching lines...) Expand all
38 #include "net/http/http_server_properties.h" 39 #include "net/http/http_server_properties.h"
39 #include "net/http/http_util.h" 40 #include "net/http/http_util.h"
40 #include "net/http/transport_security_state.h" 41 #include "net/http/transport_security_state.h"
41 #include "net/log/net_log.h" 42 #include "net/log/net_log.h"
42 #include "net/log/net_log_capture_mode.h" 43 #include "net/log/net_log_capture_mode.h"
43 #include "net/log/net_log_event_type.h" 44 #include "net/log/net_log_event_type.h"
44 #include "net/log/net_log_source.h" 45 #include "net/log/net_log_source.h"
45 #include "net/log/net_log_source_type.h" 46 #include "net/log/net_log_source_type.h"
46 #include "net/log/net_log_with_source.h" 47 #include "net/log/net_log_with_source.h"
47 #include "net/proxy/proxy_server.h" 48 #include "net/proxy/proxy_server.h"
49 #include "net/socket/socket.h"
48 #include "net/socket/ssl_client_socket.h" 50 #include "net/socket/ssl_client_socket.h"
49 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" 51 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h"
50 #include "net/spdy/spdy_buffer_producer.h" 52 #include "net/spdy/spdy_buffer_producer.h"
51 #include "net/spdy/spdy_frame_builder.h" 53 #include "net/spdy/spdy_frame_builder.h"
52 #include "net/spdy/spdy_http_utils.h" 54 #include "net/spdy/spdy_http_utils.h"
53 #include "net/spdy/spdy_protocol.h" 55 #include "net/spdy/spdy_protocol.h"
54 #include "net/spdy/spdy_session_pool.h" 56 #include "net/spdy/spdy_session_pool.h"
55 #include "net/spdy/spdy_stream.h" 57 #include "net/spdy/spdy_stream.h"
56 #include "net/ssl/channel_id_service.h" 58 #include "net/ssl/channel_id_service.h"
57 #include "net/ssl/ssl_cipher_suite_names.h" 59 #include "net/ssl/ssl_cipher_suite_names.h"
(...skipping 1798 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 1858
1857 return result; 1859 return result;
1858 } 1860 }
1859 1861
1860 int SpdySession::DoRead() { 1862 int SpdySession::DoRead() {
1861 CHECK(in_io_loop_); 1863 CHECK(in_io_loop_);
1862 1864
1863 CHECK(connection_); 1865 CHECK(connection_);
1864 CHECK(connection_->socket()); 1866 CHECK(connection_->socket());
1865 read_state_ = READ_STATE_DO_READ_COMPLETE; 1867 read_state_ = READ_STATE_DO_READ_COMPLETE;
1866 return connection_->socket()->Read( 1868 int rv = ERR_READ_IF_READY_NOT_IMPLEMENTED;
1867 read_buffer_.get(), kReadBufferSize, 1869 if (base::FeatureList::IsEnabled(Socket::kReadIfReadyExperiment)) {
1868 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), 1870 rv = connection_->socket()->ReadIfReady(
1869 READ_STATE_DO_READ_COMPLETE)); 1871 read_buffer_.get(), kReadBufferSize,
1872 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(),
1873 READ_STATE_DO_READ));
1874 // TODO(xunjieli): Follow-up CL to release |read_buffer_|.
1875 // https://crbug.com/690915.
1876 }
1877 if (rv == ERR_READ_IF_READY_NOT_IMPLEMENTED) {
1878 // Fallback to regular Read().
1879 return connection_->socket()->Read(
1880 read_buffer_.get(), kReadBufferSize,
1881 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(),
1882 READ_STATE_DO_READ_COMPLETE));
1883 }
1884 if (rv == ERR_IO_PENDING)
1885 read_state_ = READ_STATE_DO_READ;
1886 return rv;
1870 } 1887 }
1871 1888
1872 int SpdySession::DoReadComplete(int result) { 1889 int SpdySession::DoReadComplete(int result) {
1873 CHECK(in_io_loop_); 1890 CHECK(in_io_loop_);
1874 1891
1875 // Parse a frame. For now this code requires that the frame fit into our 1892 // Parse a frame. For now this code requires that the frame fit into our
1876 // buffer (kReadBufferSize). 1893 // buffer (kReadBufferSize).
1877 // TODO(mbelshe): support arbitrarily large frames! 1894 // TODO(mbelshe): support arbitrarily large frames!
1878 1895
1879 if (result == 0) { 1896 if (result == 0) {
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
3158 if (!queue->empty()) { 3175 if (!queue->empty()) {
3159 SpdyStreamId stream_id = queue->front(); 3176 SpdyStreamId stream_id = queue->front();
3160 queue->pop_front(); 3177 queue->pop_front();
3161 return stream_id; 3178 return stream_id;
3162 } 3179 }
3163 } 3180 }
3164 return 0; 3181 return 0;
3165 } 3182 }
3166 3183
3167 } // namespace net 3184 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698