| 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" |
| 11 #include "bin/log.h" | 11 #include "bin/log.h" |
| 12 #include "bin/socket.h" | 12 #include "bin/socket.h" |
| 13 #include "bin/utils.h" | 13 #include "bin/utils.h" |
| 14 | 14 |
| 15 #include "vm/thread.h" |
| 16 |
| 15 | 17 |
| 16 namespace dart { | 18 namespace dart { |
| 17 namespace bin { | 19 namespace bin { |
| 18 | 20 |
| 19 SocketAddress::SocketAddress(struct sockaddr* sockaddr) { | 21 SocketAddress::SocketAddress(struct sockaddr* sockaddr) { |
| 20 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); | 22 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); |
| 21 RawAddr* raw = reinterpret_cast<RawAddr*>(sockaddr); | 23 RawAddr* raw = reinterpret_cast<RawAddr*>(sockaddr); |
| 22 | 24 |
| 23 // Clear the port before calling WSAAddressToString as WSAAddressToString | 25 // Clear the port before calling WSAAddressToString as WSAAddressToString |
| 24 // includes the port in the formatted string. | 26 // includes the port in the formatted string. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 ListenSocket* listen_socket = reinterpret_cast<ListenSocket*>(fd); | 212 ListenSocket* listen_socket = reinterpret_cast<ListenSocket*>(fd); |
| 211 ClientSocket* client_socket = listen_socket->Accept(); | 213 ClientSocket* client_socket = listen_socket->Accept(); |
| 212 if (client_socket != NULL) { | 214 if (client_socket != NULL) { |
| 213 return reinterpret_cast<intptr_t>(client_socket); | 215 return reinterpret_cast<intptr_t>(client_socket); |
| 214 } else { | 216 } else { |
| 215 return -1; | 217 return -1; |
| 216 } | 218 } |
| 217 } | 219 } |
| 218 | 220 |
| 219 | 221 |
| 222 static Mutex* getaddrinfo_mutex = new Mutex(); |
| 220 AddressList<SocketAddress>* Socket::LookupAddress(const char* host, | 223 AddressList<SocketAddress>* Socket::LookupAddress(const char* host, |
| 221 int type, | 224 int type, |
| 222 OSError** os_error) { | 225 OSError** os_error) { |
| 223 Initialize(); | 226 Initialize(); |
| 224 | 227 |
| 228 // getaddrinfo is not thread-safe on Windows. Use a mutex to get around it. |
| 229 MutexLocker locker(getaddrinfo_mutex); |
| 230 |
| 225 // Perform a name lookup for a host name. | 231 // Perform a name lookup for a host name. |
| 226 struct addrinfo hints; | 232 struct addrinfo hints; |
| 227 memset(&hints, 0, sizeof(hints)); | 233 memset(&hints, 0, sizeof(hints)); |
| 228 hints.ai_family = SocketAddress::FromType(type); | 234 hints.ai_family = SocketAddress::FromType(type); |
| 229 hints.ai_socktype = SOCK_STREAM; | 235 hints.ai_socktype = SOCK_STREAM; |
| 230 hints.ai_flags = 0; | 236 hints.ai_flags = 0; |
| 231 hints.ai_protocol = IPPROTO_TCP; | 237 hints.ai_protocol = IPPROTO_TCP; |
| 232 struct addrinfo* info = NULL; | 238 struct addrinfo* info = NULL; |
| 233 int status = getaddrinfo(host, 0, &hints, &info); | 239 int status = getaddrinfo(host, 0, &hints, &info); |
| 234 if (status != 0) { | 240 if (status != 0) { |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 proto, | 641 proto, |
| 636 MCAST_LEAVE_GROUP, | 642 MCAST_LEAVE_GROUP, |
| 637 reinterpret_cast<char *>(&mreq), | 643 reinterpret_cast<char *>(&mreq), |
| 638 sizeof(mreq)) == 0; | 644 sizeof(mreq)) == 0; |
| 639 } | 645 } |
| 640 | 646 |
| 641 } // namespace bin | 647 } // namespace bin |
| 642 } // namespace dart | 648 } // namespace dart |
| 643 | 649 |
| 644 #endif // defined(TARGET_OS_WINDOWS) | 650 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |