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
3 // found in the LICENSE file.
5 #include "net/socket/socket_descriptor.h"
9 #include <sys/socket.h>
12 #include "base/basictypes.h"
16 #include "base/win/windows_version.h"
17 #include "net/base/winsock_init.h"
22 PlatformSocketFactory
* g_socket_factory
= NULL
;
24 PlatformSocketFactory::PlatformSocketFactory() {
27 PlatformSocketFactory::~PlatformSocketFactory() {
30 void PlatformSocketFactory::SetInstance(PlatformSocketFactory
* factory
) {
31 g_socket_factory
= factory
;
34 SocketDescriptor
CreateSocketDefault(int family
, int type
, int protocol
) {
37 SocketDescriptor result
= ::WSASocket(family
, type
, protocol
, NULL
, 0,
39 if (result
!= kInvalidSocket
&& family
== AF_INET6
&&
40 base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_VISTA
) {
42 if (setsockopt(result
, IPPROTO_IPV6
, IPV6_V6ONLY
,
43 reinterpret_cast<const char*>(&value
), sizeof(value
))) {
45 return kInvalidSocket
;
50 return ::socket(family
, type
, protocol
);
54 SocketDescriptor
CreatePlatformSocket(int family
, int type
, int protocol
) {
56 return g_socket_factory
->CreateSocket(family
, type
, protocol
);
58 return CreateSocketDefault(family
, type
, protocol
);