Chromium Code Reviews| Index: runtime/bin/socket.h |
| diff --git a/runtime/bin/socket.h b/runtime/bin/socket.h |
| index fc27903a40cf88a8a234d725bf7df29ad9fd4995..9db348a32ad0b07a762ba2f0ec82c949d2865471 100644 |
| --- a/runtime/bin/socket.h |
| +++ b/runtime/bin/socket.h |
| @@ -66,15 +66,15 @@ class SocketAddress { |
| const char* as_string() const { return as_string_; } |
| const RawAddr& addr() const { return addr_; } |
| - static intptr_t GetAddrLength(const RawAddr* addr) { |
| - ASSERT(addr->ss.ss_family == AF_INET || addr->ss.ss_family == AF_INET6); |
| - return addr->ss.ss_family == AF_INET6 ? |
| + static intptr_t GetAddrLength(const RawAddr& addr) { |
| + ASSERT(addr.ss.ss_family == AF_INET || addr.ss.ss_family == AF_INET6); |
| + return addr.ss.ss_family == AF_INET6 ? |
| sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in); |
| } |
| - static intptr_t GetInAddrLength(const RawAddr* addr) { |
| - ASSERT(addr->ss.ss_family == AF_INET || addr->ss.ss_family == AF_INET6); |
| - return addr->ss.ss_family == AF_INET6 ? |
| + static intptr_t GetInAddrLength(const RawAddr& addr) { |
| + ASSERT(addr.ss.ss_family == AF_INET || addr.ss.ss_family == AF_INET6); |
| + return addr.ss.ss_family == AF_INET6 ? |
| sizeof(struct in6_addr) : sizeof(struct in_addr); |
| } |
| @@ -132,39 +132,41 @@ class SocketAddress { |
| } |
| } |
| - static intptr_t GetAddrPort(const RawAddr* addr) { |
| - if (addr->ss.ss_family == AF_INET) { |
| - return ntohs(addr->in.sin_port); |
| + static intptr_t GetAddrPort(const RawAddr& addr) { |
| + if (addr.ss.ss_family == AF_INET) { |
| + return ntohs(addr.in.sin_port); |
| } else { |
| - return ntohs(addr->in6.sin6_port); |
| + return ntohs(addr.in6.sin6_port); |
| } |
| } |
| - static Dart_Handle ToTypedData(RawAddr* raw) { |
| + static Dart_Handle ToTypedData(const RawAddr& raw) { |
| int len = GetInAddrLength(raw); |
| Dart_Handle result = Dart_NewTypedData(Dart_TypedData_kUint8, len); |
| if (Dart_IsError(result)) Dart_PropagateError(result); |
| Dart_Handle err; |
| - if (raw->addr.sa_family == AF_INET6) { |
| + RawAddr* ptr = &const_cast<RawAddr&>(raw); |
|
kustermann
2015/02/11 14:54:31
Could you explain why it is necessary to remove th
Søren Gjesse
2015/02/11 15:19:39
Taking the address below is not allowed whithout c
|
| + if (raw.addr.sa_family == AF_INET6) { |
| err = Dart_ListSetAsBytes( |
| - result, 0, reinterpret_cast<uint8_t*>(&raw->in6.sin6_addr), len); |
| + result, 0, reinterpret_cast<uint8_t*>(&ptr->in6.sin6_addr), len); |
| } else { |
| err = Dart_ListSetAsBytes( |
| - result, 0, reinterpret_cast<uint8_t*>(&raw->in.sin_addr), len); |
| + result, 0, reinterpret_cast<uint8_t*>(&ptr->in.sin_addr), len); |
| } |
| if (Dart_IsError(err)) Dart_PropagateError(err); |
| return result; |
| } |
| - static CObjectUint8Array* ToCObject(RawAddr* raw) { |
| + static CObjectUint8Array* ToCObject(const RawAddr& raw) { |
| int in_addr_len = SocketAddress::GetInAddrLength(raw); |
| void* in_addr; |
| + RawAddr* ptr = &const_cast<RawAddr&>(raw); |
| CObjectUint8Array* data = |
| new CObjectUint8Array(CObject::NewUint8Array(in_addr_len)); |
| - if (raw->addr.sa_family == AF_INET6) { |
| - in_addr = reinterpret_cast<void*>(&raw->in6.sin6_addr); |
| + if (raw.addr.sa_family == AF_INET6) { |
| + in_addr = reinterpret_cast<void*>(&ptr->in6.sin6_addr); |
| } else { |
| - in_addr = reinterpret_cast<void*>(&raw->in.sin_addr); |
| + in_addr = reinterpret_cast<void*>(&ptr->in.sin_addr); |
| } |
| memmove(data->Buffer(), in_addr, in_addr_len); |
| return data; |
| @@ -241,16 +243,13 @@ class Socket { |
| static intptr_t Read(intptr_t fd, void* buffer, intptr_t num_bytes); |
| static intptr_t Write(intptr_t fd, const void* buffer, intptr_t num_bytes); |
| static intptr_t SendTo( |
| - intptr_t fd, const void* buffer, intptr_t num_bytes, RawAddr addr); |
| + intptr_t fd, const void* buffer, intptr_t num_bytes, const RawAddr& addr); |
| static intptr_t RecvFrom( |
| intptr_t fd, void* buffer, intptr_t num_bytes, RawAddr* addr); |
| - static intptr_t CreateConnect(const RawAddr& addr, |
| - const intptr_t port); |
| + static intptr_t CreateConnect(const RawAddr& addr); |
| static intptr_t CreateBindConnect(const RawAddr& addr, |
| - const intptr_t port, |
| const RawAddr& source_addr); |
| - static intptr_t CreateBindDatagram( |
| - RawAddr* addr, intptr_t port, bool reuseAddress); |
| + static intptr_t CreateBindDatagram(const RawAddr& addr, bool reuseAddress); |
| static intptr_t GetPort(intptr_t fd); |
| static SocketAddress* GetRemotePeer(intptr_t fd, intptr_t* port); |
| static void GetError(intptr_t fd, OSError* os_error); |
| @@ -265,23 +264,27 @@ class Socket { |
| static bool SetMulticastHops(intptr_t fd, intptr_t protocol, int value); |
| static bool GetBroadcast(intptr_t fd, bool* value); |
| static bool SetBroadcast(intptr_t fd, bool value); |
| - static bool JoinMulticast( |
| - intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex); |
| - static bool LeaveMulticast( |
| - intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex); |
| + static bool JoinMulticast(intptr_t fd, |
| + const RawAddr& addr, |
| + const RawAddr& interface, |
| + int interfaceIndex); |
| + static bool LeaveMulticast(intptr_t fd, |
| + const RawAddr& addr, |
| + const RawAddr& interface, |
| + int interfaceIndex); |
| // Perform a hostname lookup. Returns a AddressList of SocketAddress's. |
| static AddressList<SocketAddress>* LookupAddress(const char* host, |
| int type, |
| OSError** os_error); |
| - static bool ReverseLookup(RawAddr addr, |
| + static bool ReverseLookup(const RawAddr& addr, |
| char* host, |
| intptr_t host_len, |
| OSError** os_error); |
| static bool ParseAddress(int type, const char* address, RawAddr* addr); |
| - static bool FormatNumericAddress(RawAddr* addr, char* address, int len); |
| + static bool FormatNumericAddress(const RawAddr& addr, char* address, int len); |
| // List interfaces. Returns a AddressList of InterfaceSocketAddress's. |
| static AddressList<InterfaceSocketAddress>* ListInterfaces( |
| @@ -314,8 +317,7 @@ class ServerSocket { |
| // |
| // -1: system error (errno set) |
| // -5: invalid bindAddress |
| - static intptr_t CreateBindListen(RawAddr addr, |
| - intptr_t port, |
| + static intptr_t CreateBindListen(const RawAddr& addr, |
|
kustermann
2015/02/11 14:54:31
Please add a comment here (and other places) where
Søren Gjesse
2015/02/11 15:19:39
Done.
|
| intptr_t backlog, |
| bool v6_only = false); |
| @@ -367,7 +369,6 @@ class ListeningSocketRegistry { |
| // a new (potentially shared) socket. |
| Dart_Handle CreateBindListen(Dart_Handle socket_object, |
| RawAddr addr, |
| - intptr_t port, |
| intptr_t backlog, |
| bool v6_only, |
| bool shared); |