blob: 904e5195de8014b40d62cf0fd2d63259a5ae816e [file] [log] [blame]
Jens Geyerfeea4782017-01-28 19:53:28 +01001using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Net.Sockets;
5using System.Reflection;
6using System.Text;
7#if NET45
8using System.Threading.Tasks;
9#endif
10
11namespace Thrift.Transport
12{
13 /**
14 * PropertyInfo for the DualMode property of the System.Net.Sockets.Socket class. Used to determine if the sockets are capable of
15 * automatic IPv4 and IPv6 handling. If DualMode is present the sockets automatically handle IPv4 and IPv6 connections.
16 * If the DualMode is not available the system configuration determines whether IPv4 or IPv6 is used.
17 */
18 internal static class TSocketVersionizer
19 {
20 /*
21 * Creates a TcpClient according to the capabilitites of the used framework
22 */
23 internal static TcpClient CreateTcpClient()
24 {
25 TcpClient client = null;
26
27#if NET45
28 client = new TcpClient(AddressFamily.InterNetworkV6);
29 client.Client.DualMode = true;
30#else
31 client = new TcpClient(AddressFamily.InterNetwork);
32#endif
33
34 return client;
35 }
36
37 /*
38 * Creates a TcpListener according to the capabilitites of the used framework
39 */
40 internal static TcpListener CreateTcpListener(Int32 port)
41 {
42 TcpListener listener = null;
43
44#if NET45
45 listener = new TcpListener(System.Net.IPAddress.IPv6Any, port);
46 listener.Server.DualMode = true;
47#else
48
49 listener = new TcpListener(System.Net.IPAddress.Any, port);
50#endif
51
52 return listener;
53 }
54 }
55}