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

Side by Side Diff: net/quic/quic_client_session.cc

Issue 1009803003: Factor out the QUIC socket reading code into a stand alone QuicPacketReader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more export Created 5 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/quic/quic_client_session.h ('k') | net/quic/quic_packet_reader.h » ('j') | 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/quic/quic_client_session.h" 5 #include "net/quic/quic_client_session.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/metrics/sparse_histogram.h" 10 #include "base/metrics/sparse_histogram.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 scoped_ptr<QuicServerInfo> server_info, 159 scoped_ptr<QuicServerInfo> server_info,
160 const QuicConfig& config, 160 const QuicConfig& config,
161 const char* const connection_description, 161 const char* const connection_description,
162 base::TimeTicks dns_resolution_end_time, 162 base::TimeTicks dns_resolution_end_time,
163 base::TaskRunner* task_runner, 163 base::TaskRunner* task_runner,
164 NetLog* net_log) 164 NetLog* net_log)
165 : QuicClientSessionBase(connection, config), 165 : QuicClientSessionBase(connection, config),
166 require_confirmation_(false), 166 require_confirmation_(false),
167 stream_factory_(stream_factory), 167 stream_factory_(stream_factory),
168 socket_(socket.Pass()), 168 socket_(socket.Pass()),
169 read_buffer_(new IOBufferWithSize(kMaxPacketSize)),
170 transport_security_state_(transport_security_state), 169 transport_security_state_(transport_security_state),
171 server_info_(server_info.Pass()), 170 server_info_(server_info.Pass()),
172 read_pending_(false),
173 num_total_streams_(0), 171 num_total_streams_(0),
174 task_runner_(task_runner), 172 task_runner_(task_runner),
175 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), 173 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)),
174 packet_reader_(socket_.get(), this, net_log_),
176 dns_resolution_end_time_(dns_resolution_end_time), 175 dns_resolution_end_time_(dns_resolution_end_time),
177 logger_(new QuicConnectionLogger(this, connection_description, net_log_)), 176 logger_(new QuicConnectionLogger(this, connection_description, net_log_)),
178 num_packets_read_(0),
179 going_away_(false), 177 going_away_(false),
180 weak_factory_(this) { 178 weak_factory_(this) {
181 connection->set_debug_visitor(logger_.get()); 179 connection->set_debug_visitor(logger_.get());
182 IPEndPoint address; 180 IPEndPoint address;
183 if (socket && socket->GetLocalAddress(&address) == OK && 181 if (socket && socket->GetLocalAddress(&address) == OK &&
184 address.GetFamily() == ADDRESS_FAMILY_IPV6) { 182 address.GetFamily() == ADDRESS_FAMILY_IPV6) {
185 connection->set_max_packet_length( 183 connection->set_max_packet_length(
186 connection->max_packet_length() - kAdditionalOverheadForIPv6); 184 connection->max_packet_length() - kAdditionalOverheadForIPv6);
187 } 185 }
188 } 186 }
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 const ProofVerifyDetailsChromium* verify_details_chromium = 758 const ProofVerifyDetailsChromium* verify_details_chromium =
761 reinterpret_cast<const ProofVerifyDetailsChromium*>(&verify_details); 759 reinterpret_cast<const ProofVerifyDetailsChromium*>(&verify_details);
762 CertVerifyResult* result_copy = new CertVerifyResult; 760 CertVerifyResult* result_copy = new CertVerifyResult;
763 result_copy->CopyFrom(verify_details_chromium->cert_verify_result); 761 result_copy->CopyFrom(verify_details_chromium->cert_verify_result);
764 cert_verify_result_.reset(result_copy); 762 cert_verify_result_.reset(result_copy);
765 pinning_failure_log_ = verify_details_chromium->pinning_failure_log; 763 pinning_failure_log_ = verify_details_chromium->pinning_failure_log;
766 logger_->OnCertificateVerified(*cert_verify_result_); 764 logger_->OnCertificateVerified(*cert_verify_result_);
767 } 765 }
768 766
769 void QuicClientSession::StartReading() { 767 void QuicClientSession::StartReading() {
770 if (read_pending_) { 768 packet_reader_.StartReading();
771 return;
772 }
773 read_pending_ = true;
774 int rv = socket_->Read(read_buffer_.get(),
775 read_buffer_->size(),
776 base::Bind(&QuicClientSession::OnReadComplete,
777 weak_factory_.GetWeakPtr()));
778 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.AsyncRead", rv == ERR_IO_PENDING);
779 if (rv == ERR_IO_PENDING) {
780 num_packets_read_ = 0;
781 return;
782 }
783
784 if (++num_packets_read_ > 32) {
785 num_packets_read_ = 0;
786 // Data was read, process it.
787 // Schedule the work through the message loop to 1) prevent infinite
788 // recursion and 2) avoid blocking the thread for too long.
789 base::MessageLoop::current()->PostTask(
790 FROM_HERE,
791 base::Bind(&QuicClientSession::OnReadComplete,
792 weak_factory_.GetWeakPtr(), rv));
793 } else {
794 OnReadComplete(rv);
795 }
796 } 769 }
797 770
798 void QuicClientSession::CloseSessionOnError(int error) { 771 void QuicClientSession::CloseSessionOnError(int error) {
799 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.CloseSessionOnError", -error); 772 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.CloseSessionOnError", -error);
800 CloseSessionOnErrorInner(error, QUIC_INTERNAL_ERROR); 773 CloseSessionOnErrorInner(error, QUIC_INTERNAL_ERROR);
801 NotifyFactoryOfSessionClosed(); 774 NotifyFactoryOfSessionClosed();
802 } 775 }
803 776
804 void QuicClientSession::CloseSessionOnErrorInner(int net_error, 777 void QuicClientSession::CloseSessionOnErrorInner(int net_error,
805 QuicErrorCode quic_error) { 778 QuicErrorCode quic_error) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 } 840 }
868 dict->Set("aliases", alias_list); 841 dict->Set("aliases", alias_list);
869 842
870 return dict; 843 return dict;
871 } 844 }
872 845
873 base::WeakPtr<QuicClientSession> QuicClientSession::GetWeakPtr() { 846 base::WeakPtr<QuicClientSession> QuicClientSession::GetWeakPtr() {
874 return weak_factory_.GetWeakPtr(); 847 return weak_factory_.GetWeakPtr();
875 } 848 }
876 849
877 void QuicClientSession::OnReadComplete(int result) { 850 void QuicClientSession::OnReadError(int result) {
878 read_pending_ = false; 851 DVLOG(1) << "Closing session on read error: " << result;
879 if (result == 0) 852 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.ReadError", -result);
880 result = ERR_CONNECTION_CLOSED; 853 NotifyFactoryOfSessionGoingAway();
854 CloseSessionOnErrorInner(result, QUIC_PACKET_READ_ERROR);
855 NotifyFactoryOfSessionClosedLater();
856 }
881 857
882 if (result < 0) { 858 bool QuicClientSession::OnPacket(const QuicEncryptedPacket& packet,
883 DVLOG(1) << "Closing session on read error: " << result; 859 IPEndPoint local_address,
884 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.ReadError", -result); 860 IPEndPoint peer_address) {
885 NotifyFactoryOfSessionGoingAway();
886 CloseSessionOnErrorInner(result, QUIC_PACKET_READ_ERROR);
887 NotifyFactoryOfSessionClosedLater();
888 return;
889 }
890
891 QuicEncryptedPacket packet(read_buffer_->data(), result);
892 IPEndPoint local_address;
893 IPEndPoint peer_address;
894 socket_->GetLocalAddress(&local_address);
895 socket_->GetPeerAddress(&peer_address);
896 // ProcessUdpPacket might result in |this| being deleted, so we
897 // use a weak pointer to be safe.
898 connection()->ProcessUdpPacket(local_address, peer_address, packet); 861 connection()->ProcessUdpPacket(local_address, peer_address, packet);
899 if (!connection()->connected()) { 862 if (!connection()->connected()) {
900 NotifyFactoryOfSessionClosedLater(); 863 NotifyFactoryOfSessionClosedLater();
901 return; 864 return false;
902 } 865 }
903 StartReading(); 866 return true;
904 } 867 }
905 868
906 void QuicClientSession::NotifyFactoryOfSessionGoingAway() { 869 void QuicClientSession::NotifyFactoryOfSessionGoingAway() {
907 going_away_ = true; 870 going_away_ = true;
908 if (stream_factory_) 871 if (stream_factory_)
909 stream_factory_->OnSessionGoingAway(this); 872 stream_factory_->OnSessionGoingAway(this);
910 } 873 }
911 874
912 void QuicClientSession::NotifyFactoryOfSessionClosedLater() { 875 void QuicClientSession::NotifyFactoryOfSessionClosedLater() {
913 if (!streams()->empty()) 876 if (!streams()->empty())
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 return; 910 return;
948 911
949 // TODO(rch): re-enable this code once beta is cut. 912 // TODO(rch): re-enable this code once beta is cut.
950 // if (stream_factory_) 913 // if (stream_factory_)
951 // stream_factory_->OnSessionConnectTimeout(this); 914 // stream_factory_->OnSessionConnectTimeout(this);
952 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); 915 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED);
953 // DCHECK_EQ(0u, GetNumOpenStreams()); 916 // DCHECK_EQ(0u, GetNumOpenStreams());
954 } 917 }
955 918
956 } // namespace net 919 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_client_session.h ('k') | net/quic/quic_packet_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698