Skip to content

Commit

Permalink
net: use IPAddress IPv4 ctor directly in some cases
Browse files Browse the repository at this point in the history
This patch changes some places to use IPAddress(b0, b1, b2, b3) IPv4
ctor to avoid the need for some temporary variables.

This is a follow up to
https://crrev.com/21968ea54a412821a1d4ba23f9f9442aae52275e

BUG=496258
TEST=net_unittests
R=eroman@chromium.org

Review URL: https://codereview.chromium.org/1735433003

Cr-Commit-Position: refs/heads/master@{#377533}
  • Loading branch information
tfarina authored and Commit bot committed Feb 25, 2016
1 parent 50ba0ec commit a3dd7aa
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 28 deletions.
3 changes: 1 addition & 2 deletions net/http/http_transaction_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ bool MockNetworkTransaction::GetLoadTimingInfo(
}

bool MockNetworkTransaction::GetRemoteEndpoint(IPEndPoint* endpoint) const {
IPAddress ip_address(127, 0, 0, 1);
*endpoint = IPEndPoint(ip_address, 80);
*endpoint = IPEndPoint(IPAddress(127, 0, 0, 1), 80);
return true;
}

Expand Down
15 changes: 7 additions & 8 deletions net/quic/p2p/quic_p2p_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ namespace net {
QuicP2PSession::QuicP2PSession(const QuicConfig& config,
const QuicP2PCryptoConfig& crypto_config,
scoped_ptr<QuicConnection> connection,
scoped_ptr<net::Socket> socket)
scoped_ptr<Socket> socket)
: QuicSession(connection.release(), config),
socket_(std::move(socket)),
crypto_stream_(new QuicP2PCryptoStream(this, crypto_config)),
read_buffer_(new net::IOBuffer(static_cast<size_t>(kMaxPacketSize))) {
read_buffer_(new IOBuffer(static_cast<size_t>(kMaxPacketSize))) {
DCHECK(config.negotiated());

// Non-null IP address needs to be passed here because QuicConnection uses
// ToString() to format addresses for logging and ToString() is not allowed
// for empty addresses.
// TODO(sergeyu): Fix QuicConnection and remove SetSelfAddress() call below.
net::IPAddress ip(0, 0, 0, 0);
this->connection()->SetSelfAddress(net::IPEndPoint(ip, 0));
this->connection()->SetSelfAddress(IPEndPoint(IPAddress(0, 0, 0, 0), 0));
}

QuicP2PSession::~QuicP2PSession() {}
Expand Down Expand Up @@ -60,7 +59,7 @@ QuicP2PStream* QuicP2PSession::CreateIncomingDynamicStream(QuicStreamId id) {
}

QuicP2PStream* QuicP2PSession::CreateOutgoingDynamicStream(
net::SpdyPriority priority) {
SpdyPriority priority) {
QuicP2PStream* stream = new QuicP2PStream(GetNextOutgoingStreamId(), this);
if (stream) {
ActivateStream(stream);
Expand All @@ -82,7 +81,7 @@ void QuicP2PSession::OnConnectionClosed(QuicErrorCode error,
}

void QuicP2PSession::DoReadLoop(int result) {
while (error() == net::QUIC_NO_ERROR) {
while (error() == QUIC_NO_ERROR) {
switch (read_state_) {
case READ_STATE_DO_READ:
CHECK_EQ(result, OK);
Expand All @@ -106,7 +105,7 @@ int QuicP2PSession::DoRead() {
read_state_ = READ_STATE_DO_READ_COMPLETE;

if (!socket_) {
return net::ERR_SOCKET_NOT_CONNECTED;
return ERR_SOCKET_NOT_CONNECTED;
}

return socket_->Read(
Expand All @@ -119,7 +118,7 @@ int QuicP2PSession::DoReadComplete(int result) {
read_state_ = READ_STATE_DO_READ;

if (result <= 0) {
connection()->CloseConnection(net::QUIC_PACKET_READ_ERROR,
connection()->CloseConnection(QUIC_PACKET_READ_ERROR,
ConnectionCloseSource::FROM_SELF);
return result;
}
Expand Down
17 changes: 8 additions & 9 deletions net/quic/p2p/quic_p2p_session_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class QuicP2PSessionTest : public ::testing::Test {
QuicP2PSessionTest()
: quic_helper_(base::ThreadTaskRunnerHandle::Get().get(),
&quic_clock_,
net::QuicRandom::GetInstance()) {
QuicRandom::GetInstance()) {
// Simulate out-of-bound config handshake.
CryptoHandshakeMessage hello_message;
config_.ToHandshakeMessage(&hello_message);
Expand Down Expand Up @@ -226,11 +226,10 @@ class QuicP2PSessionTest : public ::testing::Test {
scoped_ptr<QuicP2PSession> CreateP2PSession(scoped_ptr<Socket> socket,
QuicP2PCryptoConfig crypto_config,
Perspective perspective) {
net::QuicChromiumPacketWriter* writer =
new net::QuicChromiumPacketWriter(socket.get());
net::IPAddress ip(0, 0, 0, 0);
QuicChromiumPacketWriter* writer =
new QuicChromiumPacketWriter(socket.get());
scoped_ptr<QuicConnection> quic_connection1(new QuicConnection(
0, net::IPEndPoint(ip, 0), &quic_helper_, writer,
0, IPEndPoint(IPAddress(0, 0, 0, 0), 0), &quic_helper_, writer,
true /* owns_writer */, perspective, QuicSupportedVersions()));
writer->SetConnection(quic_connection1.get());

Expand Down Expand Up @@ -272,10 +271,10 @@ void QuicP2PSessionTest::TestStreamConnection(QuicP2PSession* from_session,

// Add streams to write_blocked_lists of both QuicSession objects.
QuicWriteBlockedList* write_blocked_list1 =
net::test::QuicSessionPeer::GetWriteBlockedStreams(from_session);
test::QuicSessionPeer::GetWriteBlockedStreams(from_session);
write_blocked_list1->RegisterStream(expected_stream_id, kV3HighestPriority);
QuicWriteBlockedList* write_blocked_list2 =
net::test::QuicSessionPeer::GetWriteBlockedStreams(to_session);
test::QuicSessionPeer::GetWriteBlockedStreams(to_session);
write_blocked_list2->RegisterStream(expected_stream_id, kV3HighestPriority);

// Send a test message to the client.
Expand Down Expand Up @@ -329,7 +328,7 @@ TEST_F(QuicP2PSessionTest, DestroySocketWhenClosed) {

// The socket must be destroyed when connection is closed.
EXPECT_TRUE(socket1_);
session1_->connection()->CloseConnection(net::QUIC_NO_ERROR,
session1_->connection()->CloseConnection(QUIC_NO_ERROR,
ConnectionCloseSource::FROM_SELF);
EXPECT_FALSE(socket1_);
}
Expand All @@ -349,7 +348,7 @@ TEST_F(QuicP2PSessionTest, TransportWriteError) {

// Add stream to write_blocked_list.
QuicWriteBlockedList* write_blocked_list =
net::test::QuicSessionPeer::GetWriteBlockedStreams(session1_.get());
test::QuicSessionPeer::GetWriteBlockedStreams(session1_.get());
write_blocked_list->RegisterStream(stream->id(), kV3HighestPriority);

socket1_->SetWriteError(ERR_INTERNET_DISCONNECTED);
Expand Down
5 changes: 2 additions & 3 deletions net/quic/quic_end_to_end_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class QuicEndToEndTest : public ::testing::TestWithParam<TestParams> {
params_.http_auth_handler_factory = auth_handler_factory_.get();
params_.http_server_properties = http_server_properties.GetWeakPtr();

net::CertVerifyResult verify_result;
CertVerifyResult verify_result;
verify_result.verified_cert = ImportCertFromFile(
GetTestCertsDirectory(), "quic_test.example.com.crt");
cert_verifier_.AddResultForCertAndHost(verify_result.verified_cert.get(),
Expand Down Expand Up @@ -167,8 +167,7 @@ class QuicEndToEndTest : public ::testing::TestWithParam<TestParams> {

// Starts the QUIC server listening on a random port.
void StartServer() {
IPAddress ip(127, 0, 0, 1);
server_address_ = IPEndPoint(ip, 0);
server_address_ = IPEndPoint(IPAddress(127, 0, 0, 1), 0);
server_config_.SetInitialStreamFlowControlWindowToSend(
kInitialStreamFlowControlWindowForTest);
server_config_.SetInitialSessionFlowControlWindowToSend(
Expand Down
3 changes: 1 addition & 2 deletions net/tools/quic/end_to_end_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1453,8 +1453,7 @@ TEST_P(EndToEndTest, StreamCancelErrorTest) {
class WrongAddressWriter : public QuicPacketWriterWrapper {
public:
WrongAddressWriter() {
IPAddress ip(127, 0, 0, 2);
self_address_ = IPEndPoint(ip, 0);
self_address_ = IPEndPoint(IPAddress(127, 0, 0, 2), 0);
}

WriteResult WritePacket(const char* buffer,
Expand Down
3 changes: 1 addition & 2 deletions net/tools/quic/quic_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ bool QuicClient::CreateUDPSocket() {
if (bind_to_address_.size() != 0) {
client_address = IPEndPoint(bind_to_address_, local_port_);
} else if (address_family == AF_INET) {
IPAddress any4(0, 0, 0, 0);
client_address = IPEndPoint(any4, local_port_);
client_address = IPEndPoint(IPAddress(0, 0, 0, 0), local_port_);
} else {
IPAddress any6;
CHECK(any6.AssignFromIPLiteral("::"));
Expand Down
3 changes: 1 addition & 2 deletions net/tools/quic/quic_simple_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ bool QuicSimpleClient::CreateUDPSocket() {
if (bind_to_address_.size() != 0) {
client_address_ = IPEndPoint(bind_to_address_, local_port_);
} else if (address_family == AF_INET) {
IPAddress any4(0, 0, 0, 0);
client_address_ = IPEndPoint(any4, local_port_);
client_address_ = IPEndPoint(IPAddress(0, 0, 0, 0), local_port_);
} else {
IPAddress any6;
CHECK(any6.AssignFromIPLiteral("::"));
Expand Down

0 comments on commit a3dd7aa

Please sign in to comment.