Index: runtime/bin/socket.h |
diff --git a/runtime/bin/socket.h b/runtime/bin/socket.h |
index b68b782e70f883bfe65f3bd965b72cc9eb244f3a..729a8bd24adb30905de475e1493b8212c86b9c0d 100644 |
--- a/runtime/bin/socket.h |
+++ b/runtime/bin/socket.h |
@@ -23,6 +23,46 @@ |
#error Unknown target os. |
#endif |
+class SocketAddress { |
+ public: |
+ enum Type { |
+ IPv4 = 0, |
+ IPv6 = 1, |
+ }; |
+ |
+ SocketAddress(Type type, |
+ const char* as_string, |
+ uint8_t* data, |
+ intptr_t length) |
+ : type(type), as_string(as_string), data(data), length(length) {} |
+ |
+ ~SocketAddress() { |
+ delete[] as_string; |
+ delete[] data; |
+ } |
+ |
+ Type type; |
Søren Gjesse
2013/04/18 09:07:40
Make these mempers private with _ postfix. Then ad
Anders Johnsen
2013/04/18 12:09:45
Done.
|
+ const char* as_string; |
+ uint8_t* data; |
Søren Gjesse
2013/04/18 09:07:40
can't this be
sockaddr_storage address
Anders Johnsen
2013/04/18 12:09:45
Done.
|
+ const intptr_t length; |
Søren Gjesse
2013/04/18 09:07:40
Please add:
private:
DISALLOW_COPY_AND_ASSIGN(
Anders Johnsen
2013/04/18 12:09:45
Done.
|
+}; |
+ |
+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; |
+ } |
+ |
Søren Gjesse
2013/04/18 09:07:40
As above.
Anders Johnsen
2013/04/18 12:09:45
Done.
|
+ const intptr_t count; |
+ SocketAddress** addresses; |
+}; |
class Socket { |
public: |
@@ -34,7 +74,10 @@ 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(SocketAddress::Type type, |
+ uint8_t* host_data, |
+ intptr_t host_length, |
+ 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 +88,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 +118,9 @@ class ServerSocket { |
// |
// -1: system error (errno set) |
// -5: invalid bindAddress |
- static intptr_t CreateBindListen(const char* bindAddress, |
+ static intptr_t CreateBindListen(SocketAddress::Type type, |
+ uint8_t* host_data, |
+ intptr_t host_length, |
intptr_t port, |
intptr_t backlog); |