Chromium Code Reviews| Index: runtime/bin/socket.h |
| diff --git a/runtime/bin/socket.h b/runtime/bin/socket.h |
| index b68b782e70f883bfe65f3bd965b72cc9eb244f3a..a2c1007233a10c5c8207eac11e41d814da3dec3f 100644 |
| --- a/runtime/bin/socket.h |
| +++ b/runtime/bin/socket.h |
| @@ -23,6 +23,51 @@ |
| #error Unknown target os. |
| #endif |
| +#define SOCKADDR_STORAGE_LENGTH(sa) \ |
|
Søren Gjesse
2013/04/19 10:36:06
Maybe make this a static method on SocketAddress i
Anders Johnsen
2013/04/22 14:05:15
Done.
|
| + sa.ss_family == AF_INET6 ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN |
| + |
| +class SocketAddress { |
| + public: |
| + explicit SocketAddress(struct addrinfo* addrinfo); |
| + |
| + int GetType() { |
| + if (addr_.ss_family == AF_INET6) return 1; |
| + return 0; |
| + } |
| + |
| + const char* AsString() const { return as_string_; } |
| + const sockaddr_storage& GetAddr() const { return addr_; } |
| + |
| + 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_; } |
| + 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 +79,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 +91,8 @@ 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(char* host, OSError** os_error); |
| static Dart_Port GetServicePort(); |
| @@ -76,7 +121,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); |