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

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

Issue 2593063003: Add Socket::ReadIfReady() (Closed)
Patch Set: Fix tests for real Created 3 years, 10 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/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/metrics/field_trial.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"
24 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
26 #include "base/threading/thread_task_runner_handle.h" 27 #include "base/threading/thread_task_runner_handle.h"
(...skipping 11 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/spdy_buffer_producer.h" 51 #include "net/spdy/spdy_buffer_producer.h"
50 #include "net/spdy/spdy_frame_builder.h" 52 #include "net/spdy/spdy_frame_builder.h"
51 #include "net/spdy/spdy_http_utils.h" 53 #include "net/spdy/spdy_http_utils.h"
52 #include "net/spdy/spdy_protocol.h" 54 #include "net/spdy/spdy_protocol.h"
53 #include "net/spdy/spdy_session_pool.h" 55 #include "net/spdy/spdy_session_pool.h"
54 #include "net/spdy/spdy_stream.h" 56 #include "net/spdy/spdy_stream.h"
55 #include "net/ssl/channel_id_service.h" 57 #include "net/ssl/channel_id_service.h"
56 #include "net/ssl/ssl_cipher_suite_names.h" 58 #include "net/ssl/ssl_cipher_suite_names.h"
57 #include "net/ssl/ssl_connection_status_flags.h" 59 #include "net/ssl/ssl_connection_status_flags.h"
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 1436
1435 return result; 1437 return result;
1436 } 1438 }
1437 1439
1438 int SpdySession::DoRead() { 1440 int SpdySession::DoRead() {
1439 CHECK(in_io_loop_); 1441 CHECK(in_io_loop_);
1440 1442
1441 CHECK(connection_); 1443 CHECK(connection_);
1442 CHECK(connection_->socket()); 1444 CHECK(connection_->socket());
1443 read_state_ = READ_STATE_DO_READ_COMPLETE; 1445 read_state_ = READ_STATE_DO_READ_COMPLETE;
1444 return connection_->socket()->Read( 1446 int rv = ERR_READ_IF_READY_NOT_IMPLEMENTED;
1445 read_buffer_.get(), 1447 if (base::FieldTrialList::FindFullName(Socket::kReadIfReadyTrialName) ==
1446 kReadBufferSize, 1448 "enable") {
1447 base::Bind(&SpdySession::PumpReadLoop, 1449 rv = connection_->socket()->ReadIfReady(
1448 weak_factory_.GetWeakPtr(), READ_STATE_DO_READ_COMPLETE)); 1450 read_buffer_.get(), kReadBufferSize,
1451 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(),
1452 READ_STATE_DO_READ));
davidben 2017/02/01 22:25:58 Hah. That's much simpler than I expected!
xunjieli 2017/02/03 16:35:33 Acknowledged :)
1453 // TODO(xunjieli): Follow-up CL to release |read_buffer_|.
1454 }
1455 if (rv == ERR_READ_IF_READY_NOT_IMPLEMENTED) {
1456 // Fallback to regular Read().
1457 return connection_->socket()->Read(
1458 read_buffer_.get(), kReadBufferSize,
1459 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(),
1460 READ_STATE_DO_READ_COMPLETE));
1461 }
1462 if (rv == ERR_IO_PENDING)
1463 read_state_ = READ_STATE_DO_READ;
1464 return rv;
1449 } 1465 }
1450 1466
1451 int SpdySession::DoReadComplete(int result) { 1467 int SpdySession::DoReadComplete(int result) {
1452 CHECK(in_io_loop_); 1468 CHECK(in_io_loop_);
1453 1469
1454 // Parse a frame. For now this code requires that the frame fit into our 1470 // Parse a frame. For now this code requires that the frame fit into our
1455 // buffer (kReadBufferSize). 1471 // buffer (kReadBufferSize).
1456 // TODO(mbelshe): support arbitrarily large frames! 1472 // TODO(mbelshe): support arbitrarily large frames!
1457 1473
1458 if (result == 0) { 1474 if (result == 0) {
(...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after
3118 if (!queue->empty()) { 3134 if (!queue->empty()) {
3119 SpdyStreamId stream_id = queue->front(); 3135 SpdyStreamId stream_id = queue->front();
3120 queue->pop_front(); 3136 queue->pop_front();
3121 return stream_id; 3137 return stream_id;
3122 } 3138 }
3123 } 3139 }
3124 return 0; 3140 return 0;
3125 } 3141 }
3126 3142
3127 } // namespace net 3143 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698