]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | /** |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | * | |
19 | * Contains some contributions under the Thrift Software License. | |
20 | * Please see doc/old-thrift-license.txt in the Thrift distribution for | |
21 | * details. | |
22 | */ | |
23 | ||
24 | using System; | |
25 | using System.Collections.Generic; | |
26 | using System.Linq; | |
27 | using System.Net.Sockets; | |
28 | using System.Reflection; | |
29 | using System.Text; | |
30 | #if NET45 | |
31 | using System.Threading.Tasks; | |
32 | #endif | |
33 | ||
34 | namespace Thrift.Transport | |
35 | { | |
36 | /// <summary> | |
37 | /// PropertyInfo for the DualMode property of the System.Net.Sockets.Socket class. Used to determine if the sockets are capable of | |
38 | /// automatic IPv4 and IPv6 handling. If DualMode is present the sockets automatically handle IPv4 and IPv6 connections. | |
39 | /// If the DualMode is not available the system configuration determines whether IPv4 or IPv6 is used. | |
40 | /// </summary> | |
41 | internal static class TSocketVersionizer | |
42 | { | |
43 | /// <summary> | |
44 | /// Creates a TcpClient according to the capabilities of the used framework. | |
45 | /// </summary> | |
46 | internal static TcpClient CreateTcpClient() | |
47 | { | |
48 | TcpClient client = null; | |
49 | ||
50 | #if NET45 | |
51 | client = new TcpClient(AddressFamily.InterNetworkV6); | |
52 | client.Client.DualMode = true; | |
53 | #else | |
54 | client = new TcpClient(AddressFamily.InterNetwork); | |
55 | #endif | |
56 | ||
57 | return client; | |
58 | } | |
59 | ||
60 | /// <summary> | |
61 | /// Creates a TcpListener according to the capabilities of the used framework. | |
62 | /// </summary> | |
63 | internal static TcpListener CreateTcpListener(Int32 port) | |
64 | { | |
65 | TcpListener listener = null; | |
66 | ||
67 | #if NET45 | |
68 | listener = new TcpListener(System.Net.IPAddress.IPv6Any, port); | |
69 | listener.Server.DualMode = true; | |
70 | #else | |
71 | ||
72 | listener = new TcpListener(System.Net.IPAddress.Any, port); | |
73 | #endif | |
74 | ||
75 | return listener; | |
76 | } | |
77 | } | |
78 | } |