summaryrefslogtreecommitdiffstats
path: root/net/base/address_list.h
diff options
context:
space:
mode:
Diffstat (limited to 'net/base/address_list.h')
-rw-r--r--net/base/address_list.h136
1 files changed, 47 insertions, 89 deletions
diff --git a/net/base/address_list.h b/net/base/address_list.h
index edcdf09..c76152f 100644
--- a/net/base/address_list.h
+++ b/net/base/address_list.h
@@ -7,8 +7,10 @@
#pragma once
#include <string>
+#include <vector>
-#include "base/memory/ref_counted.h"
+#include "base/basictypes.h"
+#include "net/base/ip_endpoint.h"
#include "net/base/net_export.h"
#include "net/base/net_util.h"
@@ -16,106 +18,62 @@ struct addrinfo;
namespace net {
-// An AddressList object contains a linked list of addrinfo structures. This
-// class is designed to be copied around by value.
-class NET_EXPORT AddressList {
+class NET_EXPORT AddressList : private std::vector<IPEndPoint> {
public:
- // Constructs an invalid address list. Should not call any methods on this
- // other than assignment.
AddressList();
-
- AddressList(const AddressList& addresslist);
~AddressList();
- AddressList& operator=(const AddressList& addresslist);
- // Creates an address list for a list of IP literals.
+ // Creates an address list for a single IP literal.
+ explicit AddressList(const IPEndPoint& endpoint);
+
+ static AddressList CreateFromIPAddress(const IPAddressNumber& address,
+ uint16 port);
+
static AddressList CreateFromIPAddressList(
const IPAddressList& addresses,
const std::string& canonical_name);
- // Creates an address list for a single IP literal.
- static AddressList CreateFromIPAddress(
- const IPAddressNumber& address,
- uint16 port);
-
- // Creates an address list for a single IP literal. If
- // |canonicalize_name| is true, fill the ai_canonname field with the
- // canonicalized IP address.
- static AddressList CreateFromIPAddressWithCname(
- const IPAddressNumber& address,
- uint16 port,
- bool canonicalize_name);
-
- // Adopts the given addrinfo list (assumed to have been created by
- // the system, e.g. returned by getaddrinfo()) in place of the
- // existing one if any. This hands over responsibility for freeing
- // the addrinfo list to the AddressList object.
- static AddressList CreateByAdoptingFromSystem(struct addrinfo* head);
-
- // Creates a new address list with a copy of |head|. This includes the
- // entire linked list.
- static AddressList CreateByCopying(const struct addrinfo* head);
-
- // Creates a new address list wich has a single address, |head|. If there
- // are other addresses in |head| they will be ignored.
- static AddressList CreateByCopyingFirstAddress(const struct addrinfo* head);
-
- // Creates an address list for a single socket address.
- // |address| the sockaddr to copy.
- // |socket_type| is either SOCK_STREAM or SOCK_DGRAM.
- // |protocol| is either IPPROTO_TCP or IPPROTO_UDP.
- static AddressList CreateFromSockaddr(
- const struct sockaddr* address,
- socklen_t address_length,
- int socket_type,
- int protocol);
-
- // Appends a copy of |head| and all its linked addrinfos to the stored
- // addrinfo. Note that this will cause a reallocation of the linked list,
- // which invalidates the head pointer.
- void Append(const struct addrinfo* head);
-
- // Sets the port of all addresses in the list to |port| (that is the
- // sin[6]_port field for the sockaddrs). Note that this will cause a
- // reallocation of the linked list, which invalidates the head pointer.
- void SetPort(uint16 port);
-
- // Retrieves the port number of the first sockaddr in the list. (If SetPort()
- // was previously used on this list, then all the addresses will have this
- // same port number.)
- uint16 GetPort() const;
-
- // Gets the canonical name for the address.
- // If the canonical name exists, |*canonical_name| is filled in with the
- // value and true is returned. If it does not exist, |*canonical_name| is
- // not altered and false is returned.
- // |canonical_name| must be a non-null value.
- bool GetCanonicalName(std::string* canonical_name) const;
-
- // Gets access to the head of the addrinfo list.
- //
- // IMPORTANT: Callers SHOULD NOT mutate the addrinfo chain, since under the
- // hood this data might be shared by other AddressLists, which
- // might even be running on other threads.
- //
- // Additionally, non-const methods like SetPort() and Append() can
- // cause the head to be reallocated, so do not cache the return
- // value of head() across such calls.
- const struct addrinfo* head() const;
+ // Copies the data from |head| and the chained list into an AddressList.
+ static AddressList CreateFromAddrinfo(const struct addrinfo* head);
+
+ // TODO(szym): Remove all three. http://crbug.com/126134
+ const std::string& canonical_name() const {
+ return canonical_name_;
+ }
+
+ void set_canonical_name(const std::string& canonical_name) {
+ canonical_name_ = canonical_name;
+ }
+
+ // Sets canonical name to the literal of the first IP address on the list.
+ void SetDefaultCanonicalName();
+
+ // Exposed methods from std::vector.
+ using std::vector<IPEndPoint>::size;
+ using std::vector<IPEndPoint>::empty;
+ using std::vector<IPEndPoint>::clear;
+ using std::vector<IPEndPoint>::reserve;
+ using std::vector<IPEndPoint>::capacity;
+ using std::vector<IPEndPoint>::operator[];
+ using std::vector<IPEndPoint>::front;
+ using std::vector<IPEndPoint>::back;
+ using std::vector<IPEndPoint>::push_back;
+ using std::vector<IPEndPoint>::insert;
+ using std::vector<IPEndPoint>::erase;
+ using std::vector<IPEndPoint>::iterator;
+ using std::vector<IPEndPoint>::const_iterator;
+ using std::vector<IPEndPoint>::begin;
+ using std::vector<IPEndPoint>::end;
+ using std::vector<IPEndPoint>::rbegin;
+ using std::vector<IPEndPoint>::rend;
private:
- struct Data;
-
- explicit AddressList(Data* data);
-
- scoped_refptr<Data> data_;
+ // TODO(szym): Remove. http://crbug.com/126134
+ std::string canonical_name_;
};
-// Helper to create an AddressList that has a particular port. It has an
-// optimization to avoid allocating a new address linked list when the
-// port is already what we want.
-AddressList NET_EXPORT CreateAddressListUsingPort(const AddressList& src,
- int port);
+// Sets the port on each element in |list| to |port|.
+void NET_EXPORT SetPortOnAddressList(uint16 port, AddressList* list);
} // namespace net