diff options
author | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-07 21:44:56 +0000 |
---|---|---|
committer | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-07 21:44:56 +0000 |
commit | 7054e78fe6a2fcda72b06dc196b5f91cfdc75872 (patch) | |
tree | 2efdd9b07a784a17905d737df9b762d88a6cd1c4 /net/curvecp | |
parent | cd46545164adf645d744f3955b256cf89412cdc6 (diff) | |
download | chromium_src-7054e78fe6a2fcda72b06dc196b5f91cfdc75872.zip chromium_src-7054e78fe6a2fcda72b06dc196b5f91cfdc75872.tar.gz chromium_src-7054e78fe6a2fcda72b06dc196b5f91cfdc75872.tar.bz2 |
Reimplements net::AddressList without struct addrinfo.
net::AddressList extends std::vector<std::IPEndPoint> by canonical name. (Canonical name is planned to be removed as well.)
Removes dependency on sys_addrinfo.h throughout the codebase.
Introduces net::SockaddrStorage for convenience.
BUG=125696
TEST=green waterfall
Review URL: http://codereview.chromium.org/10309002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135731 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/curvecp')
-rw-r--r-- | net/curvecp/client_packetizer.cc | 19 | ||||
-rw-r--r-- | net/curvecp/client_packetizer.h | 2 | ||||
-rw-r--r-- | net/curvecp/curvecp_client_socket.cc | 13 | ||||
-rw-r--r-- | net/curvecp/curvecp_server_socket.cc | 3 |
4 files changed, 8 insertions, 29 deletions
diff --git a/net/curvecp/client_packetizer.cc b/net/curvecp/client_packetizer.cc index 4b75c6e..712a4e2 100644 --- a/net/curvecp/client_packetizer.cc +++ b/net/curvecp/client_packetizer.cc @@ -7,7 +7,6 @@ #include "base/bind.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" -#include "net/base/sys_addrinfo.h" #include "net/curvecp/protocol.h" #include "net/udp/udp_client_socket.h" @@ -33,7 +32,7 @@ ClientPacketizer::ClientPacketizer() : Packetizer(), next_state_(NONE), listener_(NULL), - current_address_(NULL), + current_address_index_(-1), hello_attempts_(0), initiate_sent_(false), ALLOW_THIS_IN_INITIALIZER_LIST( @@ -290,25 +289,17 @@ void ClientPacketizer::DoCallback(int result) { int ClientPacketizer::ConnectNextAddress() { // TODO(mbelshe): plumb Netlog information - DCHECK(addresses_.head()); + DCHECK(!addresses_.empty()); socket_.reset(new UDPClientSocket(DatagramSocket::DEFAULT_BIND, RandIntCallback(), NULL, NetLog::Source())); - // Rotate to next address in the list. - if (current_address_) - current_address_ = current_address_->ai_next; - if (!current_address_) - current_address_ = addresses_.head(); + // Rotate to next address in the list. Note, this sets it to 0 on first call. + current_address_index_ = (current_address_index_ + 1) % addresses_.size(); - IPEndPoint endpoint; - if (!endpoint.FromSockAddr(current_address_->ai_addr, - current_address_->ai_addrlen)) - return ERR_FAILED; - - int rv = socket_->Connect(endpoint); + int rv = socket_->Connect(addresses_[current_address_index_]); DCHECK_NE(ERR_IO_PENDING, rv); return rv; diff --git a/net/curvecp/client_packetizer.h b/net/curvecp/client_packetizer.h index 1214463..691276f 100644 --- a/net/curvecp/client_packetizer.h +++ b/net/curvecp/client_packetizer.h @@ -85,7 +85,7 @@ class ClientPacketizer : public Packetizer { Packetizer::Listener* listener_; CompletionCallback user_callback_; AddressList addresses_; - const struct addrinfo* current_address_; + int current_address_index_; int hello_attempts_; // Number of attempts to send a Hello Packet. bool initiate_sent_; // Indicates whether the Initiate Packet was sent. diff --git a/net/curvecp/curvecp_client_socket.cc b/net/curvecp/curvecp_client_socket.cc index 30bb378..4aaea1b 100644 --- a/net/curvecp/curvecp_client_socket.cc +++ b/net/curvecp/curvecp_client_socket.cc @@ -4,7 +4,6 @@ #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" -#include "net/base/sys_addrinfo.h" #include "net/curvecp/curvecp_client_socket.h" #include "net/curvecp/messenger.h" @@ -47,17 +46,7 @@ int CurveCPClientSocket::GetPeerAddress(AddressList* address) const { int rv = packetizer_.GetPeerAddress(&endpoint); if (rv < 0) return rv; - struct sockaddr_storage sockaddr; - size_t sockaddr_length = sizeof(sockaddr); - bool success = endpoint.ToSockAddr( - reinterpret_cast<struct sockaddr*>(&sockaddr), &sockaddr_length); - if (!success) - return ERR_FAILED; - struct addrinfo ai; - memset(&ai, 0, sizeof(ai)); - memcpy(&ai.ai_addr, &sockaddr, sockaddr_length); - ai.ai_addrlen = sockaddr_length; - *address = AddressList::CreateByCopying(&ai); + *address = AddressList(endpoint); return OK; } diff --git a/net/curvecp/curvecp_server_socket.cc b/net/curvecp/curvecp_server_socket.cc index d5d5b68..5951c19 100644 --- a/net/curvecp/curvecp_server_socket.cc +++ b/net/curvecp/curvecp_server_socket.cc @@ -1,10 +1,9 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" -#include "net/base/sys_addrinfo.h" #include "net/curvecp/curvecp_server_socket.h" #include "net/curvecp/messenger.h" |