OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/socket/socket_descriptor.h" | 5 #include "net/socket/socket_descriptor.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #endif | 10 #endif |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 | 13 |
14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
| 15 #include <ws2tcpip.h> |
| 16 #include "base/win/windows_version.h" |
15 #include "net/base/winsock_init.h" | 17 #include "net/base/winsock_init.h" |
16 #endif | 18 #endif |
17 | 19 |
18 namespace net { | 20 namespace net { |
19 | 21 |
20 PlatformSocketFactory* g_socket_factory = NULL; | 22 PlatformSocketFactory* g_socket_factory = NULL; |
21 | 23 |
22 PlatformSocketFactory::PlatformSocketFactory() { | 24 PlatformSocketFactory::PlatformSocketFactory() { |
23 } | 25 } |
24 | 26 |
25 PlatformSocketFactory::~PlatformSocketFactory() { | 27 PlatformSocketFactory::~PlatformSocketFactory() { |
26 } | 28 } |
27 | 29 |
28 void PlatformSocketFactory::SetInstance(PlatformSocketFactory* factory) { | 30 void PlatformSocketFactory::SetInstance(PlatformSocketFactory* factory) { |
29 g_socket_factory = factory; | 31 g_socket_factory = factory; |
30 } | 32 } |
31 | 33 |
32 SocketDescriptor CreateSocketDefault(int family, int type, int protocol) { | 34 SocketDescriptor CreateSocketDefault(int family, int type, int protocol) { |
33 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
34 EnsureWinsockInit(); | 36 EnsureWinsockInit(); |
35 return ::WSASocket(family, type, protocol, NULL, 0, WSA_FLAG_OVERLAPPED); | 37 SocketDescriptor result = ::WSASocket(family, type, protocol, NULL, 0, |
| 38 WSA_FLAG_OVERLAPPED); |
| 39 if (result != kInvalidSocket && family == AF_INET6 && |
| 40 base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_VISTA) { |
| 41 DWORD value = 0; |
| 42 if (setsockopt(result, IPPROTO_IPV6, IPV6_V6ONLY, |
| 43 reinterpret_cast<const char*>(&value), sizeof(value))) { |
| 44 closesocket(result); |
| 45 return kInvalidSocket; |
| 46 } |
| 47 } |
| 48 return result; |
36 #else // OS_WIN | 49 #else // OS_WIN |
37 return ::socket(family, type, protocol); | 50 return ::socket(family, type, protocol); |
38 #endif // OS_WIN | 51 #endif // OS_WIN |
39 } | 52 } |
40 | 53 |
41 SocketDescriptor CreatePlatformSocket(int family, int type, int protocol) { | 54 SocketDescriptor CreatePlatformSocket(int family, int type, int protocol) { |
42 if (g_socket_factory) | 55 if (g_socket_factory) |
43 return g_socket_factory->CreateSocket(family, type, protocol); | 56 return g_socket_factory->CreateSocket(family, type, protocol); |
44 else | 57 else |
45 return CreateSocketDefault(family, type, protocol); | 58 return CreateSocketDefault(family, type, protocol); |
46 } | 59 } |
47 | 60 |
48 } // namespace net | 61 } // namespace net |
OLD | NEW |