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

Unified Diff: runtime/bin/socket.h

Issue 14083007: Add new InternetAddress class with a static lookup function (including IPv6 results). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add Windows support and update ssl tests to use 'localhost'. Created 7 years, 8 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
Index: runtime/bin/socket.h
diff --git a/runtime/bin/socket.h b/runtime/bin/socket.h
index b68b782e70f883bfe65f3bd965b72cc9eb244f3a..45fa2670ba9f89775bcf867bbba107b67051c9b2 100644
--- a/runtime/bin/socket.h
+++ b/runtime/bin/socket.h
@@ -23,6 +23,58 @@
#error Unknown target os.
#endif
+class SocketAddress {
+ public:
Søren Gjesse 2013/04/22 15:02:08 Add an enum for type which matched the enum in Dar
+ explicit SocketAddress(struct addrinfo* addrinfo);
+
+ int GetType() {
+ if (addr_.ss_family == AF_INET6) return 1;
+ return 0;
+ }
+
+ const char* AsString() const { return as_string_; }
Søren Gjesse 2013/04/22 15:02:08 This accessor should be called as_string (see http
Anders Johnsen 2013/04/23 08:03:57 Done.
+ const sockaddr_storage& GetAddr() const { return addr_; }
Søren Gjesse 2013/04/22 15:02:08 Ditto, should be called addr.
Anders Johnsen 2013/04/23 08:03:57 Done.
+
+ static intptr_t GetAddrLength(const sockaddr_storage& addr) {
+ return addr.ss_family == AF_INET6 ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN;
+ }
+
+ static int16_t FromType(int type) {
Søren Gjesse 2013/04/22 15:02:08 ASSERT type is -1, 0 or 1.
Anders Johnsen 2013/04/23 08:03:57 Done.
+ if (type == -1) return AF_UNSPEC;
+ if (type == 1) return AF_INET6;
+ return AF_INET;
+ }
+
+ private:
+ char as_string_[INET6_ADDRSTRLEN];
+ sockaddr_storage addr_;
+
+ DISALLOW_COPY_AND_ASSIGN(SocketAddress);
+};
+
+class SocketAddresses {
+ public:
+ explicit SocketAddresses(intptr_t count)
+ : count_(count),
+ addresses_(new SocketAddress*[count_]) {}
+
+ ~SocketAddresses() {
+ for (intptr_t i = 0; i < count_; i++) {
+ delete addresses_[i];
+ }
+ delete[] addresses_;
+ }
+
+ intptr_t GetCount() const { return count_; }
Søren Gjesse 2013/04/22 15:02:08 GetCount -> count
Anders Johnsen 2013/04/23 08:03:57 Done.
+ SocketAddress* GetAt(intptr_t i) const { return addresses_[i]; }
+ void SetAt(intptr_t i, SocketAddress* addr) { addresses_[i] = addr; }
+
+ private:
+ const intptr_t count_;
+ SocketAddress** addresses_;
+
+ DISALLOW_COPY_AND_ASSIGN(SocketAddresses);
+};
class Socket {
public:
@@ -34,7 +86,8 @@ class Socket {
static intptr_t Available(intptr_t fd);
static int Read(intptr_t fd, void* buffer, intptr_t num_bytes);
static int Write(intptr_t fd, const void* buffer, intptr_t num_bytes);
- static intptr_t CreateConnect(const char* host, const intptr_t port);
+ static intptr_t CreateConnect(sockaddr_storage addr,
+ const intptr_t port);
static intptr_t GetPort(intptr_t fd);
static bool GetRemotePeer(intptr_t fd, char* host, intptr_t* port);
static void GetError(intptr_t fd, OSError* os_error);
@@ -45,9 +98,10 @@ class Socket {
static bool SetBlocking(intptr_t fd);
static bool SetNoDelay(intptr_t fd, bool enabled);
- // Perform a IPv4 hostname lookup. Returns the hostname string in
- // IPv4 dotted-decimal format.
- static const char* LookupIPv4Address(char* host, OSError** os_error);
+ // Perform a hostname lookup. Returns the SocketAddresses.
+ static SocketAddresses* LookupAddress(const char* host,
+ int type,
+ OSError** os_error);
static Dart_Port GetServicePort();
@@ -76,7 +130,7 @@ class ServerSocket {
//
// -1: system error (errno set)
// -5: invalid bindAddress
- static intptr_t CreateBindListen(const char* bindAddress,
+ static intptr_t CreateBindListen(sockaddr_storage addr,
intptr_t port,
intptr_t backlog);
« no previous file with comments | « runtime/bin/secure_socket.cc ('k') | runtime/bin/socket.cc » ('j') | runtime/bin/socket.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698