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

Side by Side Diff: net/socket/socket_test_util.cc

Issue 1494813002: Fix HttpStreamParser::CanReuseConnection(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add override Created 5 years 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
« net/socket/socket_test_util.h ('K') | « net/socket/socket_test_util.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/socket/socket_test_util.h" 5 #include "net/socket/socket_test_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 136 }
137 137
138 MockConnect::MockConnect(IoMode io_mode, int r, IPEndPoint addr) : 138 MockConnect::MockConnect(IoMode io_mode, int r, IPEndPoint addr) :
139 mode(io_mode), 139 mode(io_mode),
140 result(r), 140 result(r),
141 peer_addr(addr) { 141 peer_addr(addr) {
142 } 142 }
143 143
144 MockConnect::~MockConnect() {} 144 MockConnect::~MockConnect() {}
145 145
146 bool SocketDataProvider::IsIdle() const {
147 return true;
148 }
149
146 StaticSocketDataHelper::StaticSocketDataHelper(MockRead* reads, 150 StaticSocketDataHelper::StaticSocketDataHelper(MockRead* reads,
147 size_t reads_count, 151 size_t reads_count,
148 MockWrite* writes, 152 MockWrite* writes,
149 size_t writes_count) 153 size_t writes_count)
150 : reads_(reads), 154 : reads_(reads),
151 read_index_(0), 155 read_index_(0),
152 read_count_(reads_count), 156 read_count_(reads_count),
153 writes_(writes), 157 writes_(writes),
154 write_index_(0), 158 write_index_(0),
155 write_count_(writes_count) { 159 write_count_(writes_count) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 285 }
282 286
283 SequencedSocketData::SequencedSocketData(MockRead* reads, 287 SequencedSocketData::SequencedSocketData(MockRead* reads,
284 size_t reads_count, 288 size_t reads_count,
285 MockWrite* writes, 289 MockWrite* writes,
286 size_t writes_count) 290 size_t writes_count)
287 : helper_(reads, reads_count, writes, writes_count), 291 : helper_(reads, reads_count, writes, writes_count),
288 sequence_number_(0), 292 sequence_number_(0),
289 read_state_(IDLE), 293 read_state_(IDLE),
290 write_state_(IDLE), 294 write_state_(IDLE),
295 busy_before_sync_reads_(false),
291 weak_factory_(this) { 296 weak_factory_(this) {
292 // Check that reads and writes have a contiguous set of sequence numbers 297 // Check that reads and writes have a contiguous set of sequence numbers
293 // starting from 0 and working their way up, with no repeats and skipping 298 // starting from 0 and working their way up, with no repeats and skipping
294 // no values. 299 // no values.
295 size_t next_read = 0; 300 size_t next_read = 0;
296 size_t next_write = 0; 301 size_t next_write = 0;
297 int next_sequence_number = 0; 302 int next_sequence_number = 0;
298 while (next_read < reads_count || next_write < writes_count) { 303 while (next_read < reads_count || next_write < writes_count) {
299 if (next_read < reads_count && 304 if (next_read < reads_count &&
300 reads[next_read].sequence_number == next_sequence_number) { 305 reads[next_read].sequence_number == next_sequence_number) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 425 }
421 426
422 bool SequencedSocketData::AllReadDataConsumed() const { 427 bool SequencedSocketData::AllReadDataConsumed() const {
423 return helper_.AllReadDataConsumed(); 428 return helper_.AllReadDataConsumed();
424 } 429 }
425 430
426 bool SequencedSocketData::AllWriteDataConsumed() const { 431 bool SequencedSocketData::AllWriteDataConsumed() const {
427 return helper_.AllWriteDataConsumed(); 432 return helper_.AllWriteDataConsumed();
428 } 433 }
429 434
435 bool SequencedSocketData::IsIdle() const {
436 // If |busy_before_sync_reads_| is not set, always considered idle. If
437 // no reads left, or the next operation is a write, also consider it idle.
438 if (!busy_before_sync_reads_ || helper_.AllReadDataConsumed() ||
439 helper_.PeekRead().sequence_number != sequence_number_) {
440 return true;
441 }
442
443 // If the next operation is synchronous read, treat the socket as not idle.
444 if (helper_.PeekRead().mode == SYNCHRONOUS)
445 return false;
446 return true;
447 }
448
430 bool SequencedSocketData::IsReadPaused() { 449 bool SequencedSocketData::IsReadPaused() {
431 return read_state_ == PAUSED; 450 return read_state_ == PAUSED;
432 } 451 }
433 452
434 void SequencedSocketData::CompleteRead() { 453 void SequencedSocketData::CompleteRead() {
435 if (read_state_ != PAUSED) { 454 if (read_state_ != PAUSED) {
436 ADD_FAILURE() << "Unable to CompleteRead when not paused."; 455 ADD_FAILURE() << "Unable to CompleteRead when not paused.";
437 return; 456 return;
438 } 457 }
439 read_state_ = COMPLETING; 458 read_state_ = COMPLETING;
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 MockClientSocket::Disconnect(); 1071 MockClientSocket::Disconnect();
1053 pending_connect_callback_.Reset(); 1072 pending_connect_callback_.Reset();
1054 pending_read_callback_.Reset(); 1073 pending_read_callback_.Reset();
1055 } 1074 }
1056 1075
1057 bool MockTCPClientSocket::IsConnected() const { 1076 bool MockTCPClientSocket::IsConnected() const {
1058 return connected_ && !peer_closed_connection_; 1077 return connected_ && !peer_closed_connection_;
1059 } 1078 }
1060 1079
1061 bool MockTCPClientSocket::IsConnectedAndIdle() const { 1080 bool MockTCPClientSocket::IsConnectedAndIdle() const {
1062 return IsConnected(); 1081 return IsConnected() && data_->IsIdle();
1063 } 1082 }
1064 1083
1065 int MockTCPClientSocket::GetPeerAddress(IPEndPoint* address) const { 1084 int MockTCPClientSocket::GetPeerAddress(IPEndPoint* address) const {
1066 if (addresses_.empty()) 1085 if (addresses_.empty())
1067 return MockClientSocket::GetPeerAddress(address); 1086 return MockClientSocket::GetPeerAddress(address);
1068 1087
1069 *address = addresses_[0]; 1088 *address = addresses_[0];
1070 return OK; 1089 return OK;
1071 } 1090 }
1072 1091
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 void MockSSLClientSocket::Disconnect() { 1515 void MockSSLClientSocket::Disconnect() {
1497 MockClientSocket::Disconnect(); 1516 MockClientSocket::Disconnect();
1498 if (transport_->socket() != NULL) 1517 if (transport_->socket() != NULL)
1499 transport_->socket()->Disconnect(); 1518 transport_->socket()->Disconnect();
1500 } 1519 }
1501 1520
1502 bool MockSSLClientSocket::IsConnected() const { 1521 bool MockSSLClientSocket::IsConnected() const {
1503 return transport_->socket()->IsConnected(); 1522 return transport_->socket()->IsConnected();
1504 } 1523 }
1505 1524
1525 bool MockSSLClientSocket::IsConnectedAndIdle() const {
1526 return transport_->socket()->IsConnectedAndIdle();
1527 }
1528
1506 bool MockSSLClientSocket::WasEverUsed() const { 1529 bool MockSSLClientSocket::WasEverUsed() const {
1507 return transport_->socket()->WasEverUsed(); 1530 return transport_->socket()->WasEverUsed();
1508 } 1531 }
1509 1532
1510 bool MockSSLClientSocket::UsingTCPFastOpen() const { 1533 bool MockSSLClientSocket::UsingTCPFastOpen() const {
1511 return transport_->socket()->UsingTCPFastOpen(); 1534 return transport_->socket()->UsingTCPFastOpen();
1512 } 1535 }
1513 1536
1514 int MockSSLClientSocket::GetPeerAddress(IPEndPoint* address) const { 1537 int MockSSLClientSocket::GetPeerAddress(IPEndPoint* address) const {
1515 return transport_->socket()->GetPeerAddress(address); 1538 return transport_->socket()->GetPeerAddress(address);
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 } 2089 }
2067 2090
2068 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size) { 2091 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size) {
2069 int64_t total = 0; 2092 int64_t total = 0;
2070 for (const MockWrite* write = writes; write != writes + writes_size; ++write) 2093 for (const MockWrite* write = writes; write != writes + writes_size; ++write)
2071 total += write->data_len; 2094 total += write->data_len;
2072 return total; 2095 return total;
2073 } 2096 }
2074 2097
2075 } // namespace net 2098 } // namespace net
OLDNEW
« net/socket/socket_test_util.h ('K') | « net/socket/socket_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698