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

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

Issue 2734933002: Release SpdySession socket read buffer (Closed)
Patch Set: self 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
« no previous file with comments | « net/spdy/spdy_session.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 const SettingsMap& initial_settings, 733 const SettingsMap& initial_settings,
734 TimeFunc time_func, 734 TimeFunc time_func,
735 ServerPushDelegate* push_delegate, 735 ServerPushDelegate* push_delegate,
736 ProxyDelegate* proxy_delegate, 736 ProxyDelegate* proxy_delegate,
737 NetLog* net_log) 737 NetLog* net_log)
738 : in_io_loop_(false), 738 : in_io_loop_(false),
739 spdy_session_key_(spdy_session_key), 739 spdy_session_key_(spdy_session_key),
740 pool_(NULL), 740 pool_(NULL),
741 http_server_properties_(http_server_properties), 741 http_server_properties_(http_server_properties),
742 transport_security_state_(transport_security_state), 742 transport_security_state_(transport_security_state),
743 read_buffer_(new IOBuffer(kReadBufferSize)),
744 stream_hi_water_mark_(kFirstStreamId), 743 stream_hi_water_mark_(kFirstStreamId),
745 last_accepted_push_stream_id_(0), 744 last_accepted_push_stream_id_(0),
746 unclaimed_pushed_streams_(this), 745 unclaimed_pushed_streams_(this),
747 push_delegate_(push_delegate), 746 push_delegate_(push_delegate),
748 num_pushed_streams_(0u), 747 num_pushed_streams_(0u),
749 num_active_pushed_streams_(0u), 748 num_active_pushed_streams_(0u),
750 bytes_pushed_count_(0u), 749 bytes_pushed_count_(0u),
751 bytes_pushed_and_unclaimed_count_(0u), 750 bytes_pushed_and_unclaimed_count_(0u),
752 in_flight_write_frame_type_(DATA), 751 in_flight_write_frame_type_(DATA),
753 in_flight_write_frame_size_(0), 752 in_flight_write_frame_size_(0),
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 } 1370 }
1372 1371
1373 size_t SpdySession::DumpMemoryStats(StreamSocket::SocketMemoryStats* stats, 1372 size_t SpdySession::DumpMemoryStats(StreamSocket::SocketMemoryStats* stats,
1374 bool* is_session_active) const { 1373 bool* is_session_active) const {
1375 // TODO(xunjieli): Include |pending_create_stream_queues_| when WeakPtr is 1374 // TODO(xunjieli): Include |pending_create_stream_queues_| when WeakPtr is
1376 // supported in memory_usage_estimator.h. 1375 // supported in memory_usage_estimator.h.
1377 *is_session_active = is_active(); 1376 *is_session_active = is_active();
1378 connection_->DumpMemoryStats(stats); 1377 connection_->DumpMemoryStats(stats);
1379 1378
1380 // |connection_| is estimated in stats->total_size. |read_buffer_| is 1379 // |connection_| is estimated in stats->total_size. |read_buffer_| is
1381 // estimated in kReadBufferSize. TODO(xunjieli): Make them use EMU(). 1380 // estimated in |read_buffer_size|. TODO(xunjieli): Make them use EMU().
1382 return stats->total_size + kReadBufferSize + 1381 size_t read_buffer_size = read_buffer_ ? kReadBufferSize : 0;
1382 return stats->total_size + read_buffer_size +
1383 SpdyEstimateMemoryUsage(spdy_session_key_) + 1383 SpdyEstimateMemoryUsage(spdy_session_key_) +
1384 SpdyEstimateMemoryUsage(pooled_aliases_) + 1384 SpdyEstimateMemoryUsage(pooled_aliases_) +
1385 SpdyEstimateMemoryUsage(active_streams_) + 1385 SpdyEstimateMemoryUsage(active_streams_) +
1386 SpdyEstimateMemoryUsage(unclaimed_pushed_streams_) + 1386 SpdyEstimateMemoryUsage(unclaimed_pushed_streams_) +
1387 SpdyEstimateMemoryUsage(created_streams_) + 1387 SpdyEstimateMemoryUsage(created_streams_) +
1388 SpdyEstimateMemoryUsage(write_queue_) + 1388 SpdyEstimateMemoryUsage(write_queue_) +
1389 SpdyEstimateMemoryUsage(in_flight_write_) + 1389 SpdyEstimateMemoryUsage(in_flight_write_) +
1390 SpdyEstimateMemoryUsage(buffered_spdy_framer_) + 1390 SpdyEstimateMemoryUsage(buffered_spdy_framer_) +
1391 SpdyEstimateMemoryUsage(initial_settings_) + 1391 SpdyEstimateMemoryUsage(initial_settings_) +
1392 SpdyEstimateMemoryUsage(stream_send_unstall_queue_) + 1392 SpdyEstimateMemoryUsage(stream_send_unstall_queue_) +
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 } 1862 }
1863 } 1863 }
1864 1864
1865 CHECK(in_io_loop_); 1865 CHECK(in_io_loop_);
1866 in_io_loop_ = false; 1866 in_io_loop_ = false;
1867 1867
1868 return result; 1868 return result;
1869 } 1869 }
1870 1870
1871 int SpdySession::DoRead() { 1871 int SpdySession::DoRead() {
1872 DCHECK(!read_buffer_);
1872 CHECK(in_io_loop_); 1873 CHECK(in_io_loop_);
1873 1874
1874 CHECK(connection_); 1875 CHECK(connection_);
1875 CHECK(connection_->socket()); 1876 CHECK(connection_->socket());
1876 read_state_ = READ_STATE_DO_READ_COMPLETE; 1877 read_state_ = READ_STATE_DO_READ_COMPLETE;
1877 int rv = ERR_READ_IF_READY_NOT_IMPLEMENTED; 1878 int rv = ERR_READ_IF_READY_NOT_IMPLEMENTED;
1879 read_buffer_ = new IOBuffer(kReadBufferSize);
1878 if (base::FeatureList::IsEnabled(Socket::kReadIfReadyExperiment)) { 1880 if (base::FeatureList::IsEnabled(Socket::kReadIfReadyExperiment)) {
1879 rv = connection_->socket()->ReadIfReady( 1881 rv = connection_->socket()->ReadIfReady(
1880 read_buffer_.get(), kReadBufferSize, 1882 read_buffer_.get(), kReadBufferSize,
1881 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), 1883 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(),
1882 READ_STATE_DO_READ)); 1884 READ_STATE_DO_READ));
1883 // TODO(xunjieli): Follow-up CL to release |read_buffer_|. 1885 if (rv == ERR_IO_PENDING)
1884 // https://crbug.com/690915. 1886 read_buffer_ = nullptr;
davidben 2017/03/07 22:53:21 This could be moved into the line 1895 check, righ
xunjieli 2017/03/07 23:09:30 No, in the case of a normal Read(), we can only re
davidben 2017/03/07 23:12:37 Right, but normal Read doesn't hit that code. A no
xunjieli 2017/03/07 23:39:53 Done. Oops.. You are right. I can't believe I mis
1885 } 1887 }
1886 if (rv == ERR_READ_IF_READY_NOT_IMPLEMENTED) { 1888 if (rv == ERR_READ_IF_READY_NOT_IMPLEMENTED) {
1887 // Fallback to regular Read(). 1889 // Fallback to regular Read().
1888 return connection_->socket()->Read( 1890 return connection_->socket()->Read(
1889 read_buffer_.get(), kReadBufferSize, 1891 read_buffer_.get(), kReadBufferSize,
1890 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), 1892 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(),
1891 READ_STATE_DO_READ_COMPLETE)); 1893 READ_STATE_DO_READ_COMPLETE));
1892 } 1894 }
1893 if (rv == ERR_IO_PENDING) 1895 if (rv == ERR_IO_PENDING)
1894 read_state_ = READ_STATE_DO_READ; 1896 read_state_ = READ_STATE_DO_READ;
1895 return rv; 1897 return rv;
1896 } 1898 }
1897 1899
1898 int SpdySession::DoReadComplete(int result) { 1900 int SpdySession::DoReadComplete(int result) {
1901 DCHECK(read_buffer_);
1899 CHECK(in_io_loop_); 1902 CHECK(in_io_loop_);
1900 1903
1901 // Parse a frame. For now this code requires that the frame fit into our 1904 // Parse a frame. For now this code requires that the frame fit into our
1902 // buffer (kReadBufferSize). 1905 // buffer (kReadBufferSize).
1903 // TODO(mbelshe): support arbitrarily large frames! 1906 // TODO(mbelshe): support arbitrarily large frames!
1904 1907
1905 if (result == 0) { 1908 if (result == 0) {
1906 DoDrainSession(ERR_CONNECTION_CLOSED, "Connection closed"); 1909 DoDrainSession(ERR_CONNECTION_CLOSED, "Connection closed");
1907 return ERR_CONNECTION_CLOSED; 1910 return ERR_CONNECTION_CLOSED;
1908 } 1911 }
(...skipping 17 matching lines...) Expand all
1926 data += bytes_processed; 1929 data += bytes_processed;
1927 1930
1928 if (availability_state_ == STATE_DRAINING) { 1931 if (availability_state_ == STATE_DRAINING) {
1929 return ERR_CONNECTION_CLOSED; 1932 return ERR_CONNECTION_CLOSED;
1930 } 1933 }
1931 1934
1932 DCHECK_EQ(buffered_spdy_framer_->spdy_framer_error(), 1935 DCHECK_EQ(buffered_spdy_framer_->spdy_framer_error(),
1933 SpdyFramer::SPDY_NO_ERROR); 1936 SpdyFramer::SPDY_NO_ERROR);
1934 } 1937 }
1935 1938
1939 read_buffer_ = nullptr;
1936 read_state_ = READ_STATE_DO_READ; 1940 read_state_ = READ_STATE_DO_READ;
1937 return OK; 1941 return OK;
1938 } 1942 }
1939 1943
1940 void SpdySession::PumpWriteLoop(WriteState expected_write_state, int result) { 1944 void SpdySession::PumpWriteLoop(WriteState expected_write_state, int result) {
1941 CHECK(!in_io_loop_); 1945 CHECK(!in_io_loop_);
1942 DCHECK_EQ(write_state_, expected_write_state); 1946 DCHECK_EQ(write_state_, expected_write_state);
1943 1947
1944 DoWriteLoop(expected_write_state, result); 1948 DoWriteLoop(expected_write_state, result);
1945 1949
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after
3184 if (!queue->empty()) { 3188 if (!queue->empty()) {
3185 SpdyStreamId stream_id = queue->front(); 3189 SpdyStreamId stream_id = queue->front();
3186 queue->pop_front(); 3190 queue->pop_front();
3187 return stream_id; 3191 return stream_id;
3188 } 3192 }
3189 } 3193 }
3190 return 0; 3194 return 0;
3191 } 3195 }
3192 3196
3193 } // namespace net 3197 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698