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

Unified Diff: net/tools/quic/quic_simple_client.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/tools/quic/quic_simple_client.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/quic/quic_simple_client.cc
diff --git a/net/tools/quic/quic_simple_client.cc b/net/tools/quic/quic_simple_client.cc
index 74fa541d4a832b4264734f1d37ced8c0589c71b5..f1bfda171c473293cc5dc8798394d1e563732622 100644
--- a/net/tools/quic/quic_simple_client.cc
+++ b/net/tools/quic/quic_simple_client.cc
@@ -21,13 +21,6 @@ using std::vector;
namespace net {
namespace tools {
-namespace {
-
-// Allocate some extra space so we can send an error if the server goes over
-// the limit.
-const int kReadBufferSize = 2 * kMaxPacketSize;
-
-} // namespace
QuicSimpleClient::QuicSimpleClient(IPEndPoint server_address,
const QuicServerId& server_id,
@@ -38,9 +31,6 @@ QuicSimpleClient::QuicSimpleClient(IPEndPoint server_address,
helper_(CreateQuicConnectionHelper()),
initialized_(false),
supported_versions_(supported_versions),
- read_pending_(false),
- synchronous_read_count_(0),
- read_buffer_(new IOBufferWithSize(kReadBufferSize)),
weak_factory_(this) {
}
@@ -55,9 +45,6 @@ QuicSimpleClient::QuicSimpleClient(IPEndPoint server_address,
helper_(CreateQuicConnectionHelper()),
initialized_(false),
supported_versions_(supported_versions),
- read_pending_(false),
- synchronous_read_count_(0),
- read_buffer_(new IOBufferWithSize(kReadBufferSize)),
weak_factory_(this) {
}
@@ -135,8 +122,8 @@ bool QuicSimpleClient::CreateUDPSocket() {
}
socket_.swap(socket);
-
- read_pending_ = false;
+ packet_reader_.reset(new QuicPacketReader(socket_.get(), this,
+ BoundNetLog()));
if (socket != nullptr) {
socket->Close();
@@ -147,7 +134,7 @@ bool QuicSimpleClient::CreateUDPSocket() {
bool QuicSimpleClient::Connect() {
StartConnect();
- StartReading();
+ packet_reader_->StartReading();
while (EncryptionBeingEstablished()) {
WaitForEvents();
}
@@ -185,8 +172,7 @@ void QuicSimpleClient::Disconnect() {
}
writer_.reset();
-
- read_pending_ = false;
+ packet_reader_.reset();
initialized_ = false;
}
@@ -309,58 +295,20 @@ QuicPacketWriter* QuicSimpleClient::CreateQuicPacketWriter() {
return new QuicDefaultPacketWriter(socket_.get());
}
-void QuicSimpleClient::StartReading() {
- if (read_pending_) {
- return;
- }
- read_pending_ = true;
-
- int result = socket_->Read(
- read_buffer_.get(),
- read_buffer_->size(),
- base::Bind(&QuicSimpleClient::OnReadComplete,
- weak_factory_.GetWeakPtr()));
-
- if (result == ERR_IO_PENDING) {
- synchronous_read_count_ = 0;
- return;
- }
-
- if (++synchronous_read_count_ > 32) {
- synchronous_read_count_ = 0;
- // Schedule the processing through the message loop to 1) prevent infinite
- // recursion and 2) avoid blocking the thread for too long.
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&QuicSimpleClient::OnReadComplete,
- weak_factory_.GetWeakPtr(), result));
- } else {
- OnReadComplete(result);
- }
+void QuicSimpleClient::OnReadError(int result) {
+ LOG(ERROR) << "QuicSimpleClient read failed: " << ErrorToString(result);
+ Disconnect();
}
-void QuicSimpleClient::OnReadComplete(int result) {
- read_pending_ = false;
- if (result == 0)
- result = ERR_CONNECTION_CLOSED;
-
- if (result < 0) {
- LOG(ERROR) << "QuicSimpleClient read failed: " << ErrorToString(result);
- Disconnect();
- return;
- }
-
- QuicEncryptedPacket packet(read_buffer_->data(), result);
- IPEndPoint local_address;
- IPEndPoint peer_address;
- socket_->GetLocalAddress(&local_address);
- socket_->GetPeerAddress(&peer_address);
+bool QuicSimpleClient::OnPacket(const QuicEncryptedPacket& packet,
+ IPEndPoint local_address,
+ IPEndPoint peer_address) {
session_->connection()->ProcessUdpPacket(local_address, peer_address, packet);
if (!session_->connection()->connected()) {
- return;
+ return false;
}
- StartReading();
+ return true;
}
} // namespace tools
« no previous file with comments | « net/tools/quic/quic_simple_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698