OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef NET_SOCKET_SOCKET_DESCRIPTOR_H_ | |
6 #define NET_SOCKET_SOCKET_DESCRIPTOR_H_ | |
7 | |
8 #include "build/build_config.h" | |
9 #include "net/base/net_export.h" | |
10 | |
11 #if defined(OS_WIN) | |
12 #include <winsock2.h> | |
13 #endif // OS_WIN | |
14 | |
15 namespace net { | |
16 | |
17 #if defined(OS_POSIX) | |
18 typedef int SocketDescriptor; | |
19 const SocketDescriptor kInvalidSocket = -1; | |
20 #elif defined(OS_WIN) | |
21 typedef SOCKET SocketDescriptor; | |
22 const SocketDescriptor kInvalidSocket = INVALID_SOCKET; | |
23 #endif | |
24 | |
25 // Interface to create native socket. | |
26 // Usually such factories are used for testing purposes, which is not true in | |
27 // this case. This interface is used to substitute WSASocket/socket to make | |
28 // possible execution of some network code in sandbox. | |
29 class NET_EXPORT PlatformSocketFactory { | |
30 public: | |
31 PlatformSocketFactory(); | |
32 virtual ~PlatformSocketFactory(); | |
33 | |
34 // Replace WSASocket/socket with given factory. The factory will be used by | |
35 // CreatePlatformSocket. | |
36 static void SetInstance(PlatformSocketFactory* factory); | |
37 | |
38 // Creates socket. See WSASocket/socket documentation of parameters. | |
39 virtual SocketDescriptor CreateSocket(int family, int type, int protocol) = 0; | |
40 }; | |
41 | |
42 // Creates socket. See WSASocket/socket documentation of parameters. | |
43 SocketDescriptor NET_EXPORT CreatePlatformSocket(int family, | |
44 int type, | |
45 int protocol); | |
46 | |
47 } // namespace net | |
48 | |
49 #endif // NET_SOCKET_SOCKET_DESCRIPTOR_H_ | |
OLD | NEW |