OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
9 #include "bin/eventhandler.h" | 9 #include "bin/eventhandler.h" |
10 #include "bin/file.h" | 10 #include "bin/file.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 if (getsockname(socket_handle->socket(), | 78 if (getsockname(socket_handle->socket(), |
79 &raw.addr, | 79 &raw.addr, |
80 &size) == SOCKET_ERROR) { | 80 &size) == SOCKET_ERROR) { |
81 Log::PrintErr("Error getsockname: %d\n", WSAGetLastError()); | 81 Log::PrintErr("Error getsockname: %d\n", WSAGetLastError()); |
82 return 0; | 82 return 0; |
83 } | 83 } |
84 return SocketAddress::GetAddrPort(&raw); | 84 return SocketAddress::GetAddrPort(&raw); |
85 } | 85 } |
86 | 86 |
87 | 87 |
88 bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) { | 88 SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) { |
89 ASSERT(reinterpret_cast<Handle*>(fd)->is_socket()); | 89 ASSERT(reinterpret_cast<Handle*>(fd)->is_socket()); |
90 SocketHandle* socket_handle = reinterpret_cast<SocketHandle*>(fd); | 90 SocketHandle* socket_handle = reinterpret_cast<SocketHandle*>(fd); |
91 RawAddr raw; | 91 RawAddr raw; |
92 socklen_t size = sizeof(raw); | 92 socklen_t size = sizeof(raw); |
93 if (getpeername(socket_handle->socket(), | 93 if (getpeername(socket_handle->socket(), |
94 &raw.addr, | 94 &raw.addr, |
95 &size)) { | 95 &size)) { |
96 Log::PrintErr("Error getpeername: %d\n", WSAGetLastError()); | 96 Log::PrintErr("Error getpeername: %d\n", WSAGetLastError()); |
97 return false; | 97 return NULL; |
98 } | 98 } |
99 *port = SocketAddress::GetAddrPort(&raw); | 99 *port = SocketAddress::GetAddrPort(&raw); |
100 // Clear the port before calling WSAAddressToString as WSAAddressToString | 100 return new SocketAddress(&raw.addr); |
101 // includes the port in the formatted string. | |
102 SocketAddress::SetAddrPort(&raw, 0); | |
103 DWORD len = INET6_ADDRSTRLEN; | |
104 int err = WSAAddressToStringA(&raw.addr, | |
105 sizeof(raw), | |
106 NULL, | |
107 host, | |
108 &len); | |
109 if (err != 0) { | |
110 Log::PrintErr("Error WSAAddressToString: %d\n", WSAGetLastError()); | |
111 return false; | |
112 } | |
113 return true; | |
114 } | 101 } |
115 | 102 |
116 | 103 |
117 intptr_t Socket::Create(RawAddr addr) { | 104 intptr_t Socket::Create(RawAddr addr) { |
118 SOCKET s = socket(addr.ss.ss_family, SOCK_STREAM, 0); | 105 SOCKET s = socket(addr.ss.ss_family, SOCK_STREAM, 0); |
119 if (s == INVALID_SOCKET) { | 106 if (s == INVALID_SOCKET) { |
120 return -1; | 107 return -1; |
121 } | 108 } |
122 | 109 |
123 linger l; | 110 linger l; |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 IPPROTO_TCP, | 426 IPPROTO_TCP, |
440 TCP_NODELAY, | 427 TCP_NODELAY, |
441 reinterpret_cast<char *>(&on), | 428 reinterpret_cast<char *>(&on), |
442 sizeof(on)) == 0; | 429 sizeof(on)) == 0; |
443 } | 430 } |
444 | 431 |
445 } // namespace bin | 432 } // namespace bin |
446 } // namespace dart | 433 } // namespace dart |
447 | 434 |
448 #endif // defined(TARGET_OS_WINDOWS) | 435 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |