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

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

Issue 2734933002: Release SpdySession socket read buffer (Closed)
Patch Set: 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 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 const SettingsMap& initial_settings, 730 const SettingsMap& initial_settings,
731 TimeFunc time_func, 731 TimeFunc time_func,
732 ServerPushDelegate* push_delegate, 732 ServerPushDelegate* push_delegate,
733 ProxyDelegate* proxy_delegate, 733 ProxyDelegate* proxy_delegate,
734 NetLog* net_log) 734 NetLog* net_log)
735 : in_io_loop_(false), 735 : in_io_loop_(false),
736 spdy_session_key_(spdy_session_key), 736 spdy_session_key_(spdy_session_key),
737 pool_(NULL), 737 pool_(NULL),
738 http_server_properties_(http_server_properties), 738 http_server_properties_(http_server_properties),
739 transport_security_state_(transport_security_state), 739 transport_security_state_(transport_security_state),
740 read_buffer_(new IOBuffer(kReadBufferSize)), 740 // read_buffer_(new IOBuffer(kReadBufferSize)),
741 stream_hi_water_mark_(kFirstStreamId), 741 stream_hi_water_mark_(kFirstStreamId),
742 last_accepted_push_stream_id_(0), 742 last_accepted_push_stream_id_(0),
743 unclaimed_pushed_streams_(this), 743 unclaimed_pushed_streams_(this),
744 push_delegate_(push_delegate), 744 push_delegate_(push_delegate),
745 num_pushed_streams_(0u), 745 num_pushed_streams_(0u),
746 num_active_pushed_streams_(0u), 746 num_active_pushed_streams_(0u),
747 bytes_pushed_count_(0u), 747 bytes_pushed_count_(0u),
748 bytes_pushed_and_unclaimed_count_(0u), 748 bytes_pushed_and_unclaimed_count_(0u),
749 in_flight_write_frame_type_(DATA), 749 in_flight_write_frame_type_(DATA),
750 in_flight_write_frame_size_(0), 750 in_flight_write_frame_size_(0),
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 } 1362 }
1363 1363
1364 size_t SpdySession::DumpMemoryStats(StreamSocket::SocketMemoryStats* stats, 1364 size_t SpdySession::DumpMemoryStats(StreamSocket::SocketMemoryStats* stats,
1365 bool* is_session_active) const { 1365 bool* is_session_active) const {
1366 // TODO(xunjieli): Include |pending_create_stream_queues_| when WeakPtr is 1366 // TODO(xunjieli): Include |pending_create_stream_queues_| when WeakPtr is
1367 // supported in memory_usage_estimator.h. 1367 // supported in memory_usage_estimator.h.
1368 *is_session_active = is_active(); 1368 *is_session_active = is_active();
1369 connection_->DumpMemoryStats(stats); 1369 connection_->DumpMemoryStats(stats);
1370 1370
1371 // |connection_| is estimated in stats->total_size. |read_buffer_| is 1371 // |connection_| is estimated in stats->total_size. |read_buffer_| is
1372 // estimated in kReadBufferSize. TODO(xunjieli): Make them use EMU(). 1372 // estimated in |read_buffer_size|. TODO(xunjieli): Make them use EMU().
1373 return stats->total_size + kReadBufferSize + 1373 size_t read_buffer_size = read_buffer_ ? kReadBufferSize : 0;
1374 return stats->total_size + read_buffer_size +
1374 SpdyEstimateMemoryUsage(spdy_session_key_) + 1375 SpdyEstimateMemoryUsage(spdy_session_key_) +
1375 SpdyEstimateMemoryUsage(pooled_aliases_) + 1376 SpdyEstimateMemoryUsage(pooled_aliases_) +
1376 SpdyEstimateMemoryUsage(active_streams_) + 1377 SpdyEstimateMemoryUsage(active_streams_) +
1377 SpdyEstimateMemoryUsage(unclaimed_pushed_streams_) + 1378 SpdyEstimateMemoryUsage(unclaimed_pushed_streams_) +
1378 SpdyEstimateMemoryUsage(created_streams_) + 1379 SpdyEstimateMemoryUsage(created_streams_) +
1379 SpdyEstimateMemoryUsage(write_queue_) + 1380 SpdyEstimateMemoryUsage(write_queue_) +
1380 SpdyEstimateMemoryUsage(in_flight_write_) + 1381 SpdyEstimateMemoryUsage(in_flight_write_) +
1381 SpdyEstimateMemoryUsage(buffered_spdy_framer_) + 1382 SpdyEstimateMemoryUsage(buffered_spdy_framer_) +
1382 SpdyEstimateMemoryUsage(initial_settings_) + 1383 SpdyEstimateMemoryUsage(initial_settings_) +
1383 SpdyEstimateMemoryUsage(stream_send_unstall_queue_) + 1384 SpdyEstimateMemoryUsage(stream_send_unstall_queue_) +
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 } 1854 }
1854 } 1855 }
1855 1856
1856 CHECK(in_io_loop_); 1857 CHECK(in_io_loop_);
1857 in_io_loop_ = false; 1858 in_io_loop_ = false;
1858 1859
1859 return result; 1860 return result;
1860 } 1861 }
1861 1862
1862 int SpdySession::DoRead() { 1863 int SpdySession::DoRead() {
1864 DCHECK(!read_buffer_);
1863 CHECK(in_io_loop_); 1865 CHECK(in_io_loop_);
1864 1866
1865 CHECK(connection_); 1867 CHECK(connection_);
1866 CHECK(connection_->socket()); 1868 CHECK(connection_->socket());
1867 read_state_ = READ_STATE_DO_READ_COMPLETE; 1869 read_state_ = READ_STATE_DO_READ_COMPLETE;
1868 int rv = ERR_READ_IF_READY_NOT_IMPLEMENTED; 1870 int rv = ERR_READ_IF_READY_NOT_IMPLEMENTED;
1871 read_buffer_ = new IOBuffer(kReadBufferSize);
1869 if (base::FeatureList::IsEnabled(Socket::kReadIfReadyExperiment)) { 1872 if (base::FeatureList::IsEnabled(Socket::kReadIfReadyExperiment)) {
1870 rv = connection_->socket()->ReadIfReady( 1873 rv = connection_->socket()->ReadIfReady(
1871 read_buffer_.get(), kReadBufferSize, 1874 read_buffer_.get(), kReadBufferSize,
1872 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), 1875 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(),
1873 READ_STATE_DO_READ)); 1876 READ_STATE_DO_READ));
1874 // TODO(xunjieli): Follow-up CL to release |read_buffer_|. 1877 if (rv == ERR_IO_PENDING)
DmitrySkiba 2017/03/06 21:42:37 Are we killing buffer with read operation in progr
xunjieli 2017/03/06 21:58:59 Great question. The new ReadIfReady() method that
xunjieli 2017/03/06 22:00:51 Btw, if you apply the CL linked above and start Ch
1875 // https://crbug.com/690915. 1878 read_buffer_ = nullptr;
1876 } 1879 }
1877 if (rv == ERR_READ_IF_READY_NOT_IMPLEMENTED) { 1880 if (rv == ERR_READ_IF_READY_NOT_IMPLEMENTED) {
1878 // Fallback to regular Read(). 1881 // Fallback to regular Read().
1879 return connection_->socket()->Read( 1882 return connection_->socket()->Read(
1880 read_buffer_.get(), kReadBufferSize, 1883 read_buffer_.get(), kReadBufferSize,
1881 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), 1884 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(),
1882 READ_STATE_DO_READ_COMPLETE)); 1885 READ_STATE_DO_READ_COMPLETE));
1883 } 1886 }
1884 if (rv == ERR_IO_PENDING) 1887 if (rv == ERR_IO_PENDING) {
1885 read_state_ = READ_STATE_DO_READ; 1888 read_state_ = READ_STATE_DO_READ;
1889 return ERR_IO_PENDING;
1890 }
1886 return rv; 1891 return rv;
1887 } 1892 }
1888 1893
1889 int SpdySession::DoReadComplete(int result) { 1894 int SpdySession::DoReadComplete(int result) {
1895 DCHECK(read_buffer_);
1890 CHECK(in_io_loop_); 1896 CHECK(in_io_loop_);
1891 1897
1892 // Parse a frame. For now this code requires that the frame fit into our 1898 // Parse a frame. For now this code requires that the frame fit into our
1893 // buffer (kReadBufferSize). 1899 // buffer (kReadBufferSize).
1894 // TODO(mbelshe): support arbitrarily large frames! 1900 // TODO(mbelshe): support arbitrarily large frames!
1895 1901
1896 if (result == 0) { 1902 if (result == 0) {
1897 DoDrainSession(ERR_CONNECTION_CLOSED, "Connection closed"); 1903 DoDrainSession(ERR_CONNECTION_CLOSED, "Connection closed");
1898 return ERR_CONNECTION_CLOSED; 1904 return ERR_CONNECTION_CLOSED;
1899 } 1905 }
(...skipping 17 matching lines...) Expand all
1917 data += bytes_processed; 1923 data += bytes_processed;
1918 1924
1919 if (availability_state_ == STATE_DRAINING) { 1925 if (availability_state_ == STATE_DRAINING) {
1920 return ERR_CONNECTION_CLOSED; 1926 return ERR_CONNECTION_CLOSED;
1921 } 1927 }
1922 1928
1923 DCHECK_EQ(buffered_spdy_framer_->spdy_framer_error(), 1929 DCHECK_EQ(buffered_spdy_framer_->spdy_framer_error(),
1924 SpdyFramer::SPDY_NO_ERROR); 1930 SpdyFramer::SPDY_NO_ERROR);
1925 } 1931 }
1926 1932
1933 read_buffer_ = nullptr;
1927 read_state_ = READ_STATE_DO_READ; 1934 read_state_ = READ_STATE_DO_READ;
1928 return OK; 1935 return OK;
1929 } 1936 }
1930 1937
1931 void SpdySession::PumpWriteLoop(WriteState expected_write_state, int result) { 1938 void SpdySession::PumpWriteLoop(WriteState expected_write_state, int result) {
1932 CHECK(!in_io_loop_); 1939 CHECK(!in_io_loop_);
1933 DCHECK_EQ(write_state_, expected_write_state); 1940 DCHECK_EQ(write_state_, expected_write_state);
1934 1941
1935 DoWriteLoop(expected_write_state, result); 1942 DoWriteLoop(expected_write_state, result);
1936 1943
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after
3175 if (!queue->empty()) { 3182 if (!queue->empty()) {
3176 SpdyStreamId stream_id = queue->front(); 3183 SpdyStreamId stream_id = queue->front();
3177 queue->pop_front(); 3184 queue->pop_front();
3178 return stream_id; 3185 return stream_id;
3179 } 3186 }
3180 } 3187 }
3181 return 0; 3188 return 0;
3182 } 3189 }
3183 3190
3184 } // namespace net 3191 } // 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