Revert "THRIFT-3000 .NET implementation has trouble with mixed IP modes"
This reverts commit 018c1b8f77e7d69da61014437d5f04fedbaad81d.
diff --git a/lib/csharp/src/Transport/TServerSocket.cs b/lib/csharp/src/Transport/TServerSocket.cs
index 524003e..82a367c 100644
--- a/lib/csharp/src/Transport/TServerSocket.cs
+++ b/lib/csharp/src/Transport/TServerSocket.cs
@@ -23,7 +23,6 @@
using System;
using System.Net.Sockets;
-using System.Reflection;
namespace Thrift.Transport
@@ -54,7 +53,7 @@
* Creates a server socket from underlying socket object
*/
public TServerSocket(TcpListener listener)
- : this(listener, 0)
+ :this(listener, 0)
{
}
@@ -79,7 +78,7 @@
* Creates just a port listening server socket
*/
public TServerSocket(int port, int clientTimeout)
- : this(port, clientTimeout, false)
+ :this(port, clientTimeout, false)
{
}
@@ -91,8 +90,8 @@
try
{
// Make server socket
- this.server = TSocketVersionizer.CreateTcpListener(port);
- this.server.Server.NoDelay = true;
+ server = new TcpListener(System.Net.IPAddress.Any, this.port);
+ server.Server.NoDelay = true;
}
catch (Exception)
{
diff --git a/lib/csharp/src/Transport/TServerTransport.cs b/lib/csharp/src/Transport/TServerTransport.cs
index 8e84323..05d7d0f 100644
--- a/lib/csharp/src/Transport/TServerTransport.cs
+++ b/lib/csharp/src/Transport/TServerTransport.cs
@@ -22,8 +22,6 @@
*/
using System;
-using System.Net.Sockets;
-using System.Reflection;
namespace Thrift.Transport
{
@@ -36,11 +34,10 @@
public TTransport Accept()
{
TTransport transport = AcceptImpl();
- if (transport == null)
- {
- throw new TTransportException("accept() may not return NULL");
+ if (transport == null) {
+ throw new TTransportException("accept() may not return NULL");
}
return transport;
- }
+ }
}
}
diff --git a/lib/csharp/src/Transport/TSocket.cs b/lib/csharp/src/Transport/TSocket.cs
index 0b47572..cf1a440 100644
--- a/lib/csharp/src/Transport/TSocket.cs
+++ b/lib/csharp/src/Transport/TSocket.cs
@@ -60,9 +60,9 @@
private void InitSocket()
{
- this.client = TSocketVersionizer.CreateTcpClient();
- this.client.ReceiveTimeout = client.SendTimeout = timeout;
- this.client.Client.NoDelay = true;
+ client = new TcpClient();
+ client.ReceiveTimeout = client.SendTimeout = timeout;
+ client.Client.NoDelay = true;
}
public int Timeout
@@ -132,7 +132,7 @@
InitSocket();
}
- if (timeout == 0) // no timeout -> infinite
+ if( timeout == 0) // no timeout -> infinite
{
client.Connect(host, port);
}
@@ -145,7 +145,7 @@
{
lock (hlp.Mutex)
{
- if (hlp.CallbackDone)
+ if( hlp.CallbackDone)
{
asyncres.AsyncWaitHandle.Close();
client.Close();
@@ -174,7 +174,7 @@
try
{
- if (hlp.Client.Client != null)
+ if( hlp.Client.Client != null)
hlp.Client.EndConnect(asyncres);
}
catch (Exception)
@@ -184,18 +184,14 @@
if (hlp.DoCleanup)
{
- try
- {
+ try {
asyncres.AsyncWaitHandle.Close();
- }
- catch (Exception) { }
+ } catch (Exception) {}
- try
- {
+ try {
if (hlp.Client is IDisposable)
((IDisposable)hlp.Client).Dispose();
- }
- catch (Exception) { }
+ } catch (Exception) {}
hlp.Client = null;
}
}
@@ -223,23 +219,23 @@
}
}
- #region " IDisposable Support "
- private bool _IsDisposed;
+ #region " IDisposable Support "
+ private bool _IsDisposed;
- // IDisposable
- protected override void Dispose(bool disposing)
+ // IDisposable
+ protected override void Dispose(bool disposing)
+ {
+ if (!_IsDisposed)
+ {
+ if (disposing)
{
- if (!_IsDisposed)
- {
- if (disposing)
- {
- if (client != null)
- ((IDisposable)client).Dispose();
- base.Dispose(disposing);
- }
- }
- _IsDisposed = true;
+ if (client != null)
+ ((IDisposable)client).Dispose();
+ base.Dispose(disposing);
}
- #endregion
+ }
+ _IsDisposed = true;
}
+ #endregion
+ }
}
diff --git a/lib/csharp/src/Transport/TSocketVersionizer.cs b/lib/csharp/src/Transport/TSocketVersionizer.cs
deleted file mode 100644
index 1928fac..0000000
--- a/lib/csharp/src/Transport/TSocketVersionizer.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Sockets;
-using System.Reflection;
-using System.Text;
-
-namespace Thrift.Transport
-{
- /**
- * PropertyInfo for the DualMode property of the System.Net.Sockets.Socket class. Used to determine if the sockets are capable of
- * automatic IPv4 and IPv6 handling. If DualMode is present the sockets automatically handle IPv4 and IPv6 connections.
- * If the DualMode is not available the system configuration determines whether IPv4 or IPv6 is used.
- */
- internal static class TSocketVersionizer
- {
- /*
- * PropertyInfo for the DualMode property of System.Net.Sockets.Socket.
- */
- private static PropertyInfo DualModeProperty = typeof(Socket).GetProperty("DualMode");
-
- /*
- * Indicates whether the used framework supports DualMode on sockets or not.
- */
- internal static Boolean SupportsDualMode
- {
- get
- {
- return TSocketVersionizer.DualModeProperty != null;
- }
- }
-
- /*
- * Creates a TcpClient according to the capabilitites of the used framework
- */
- internal static TcpClient CreateTcpClient()
- {
- TcpClient client = null;
-
- if (TSocketVersionizer.SupportsDualMode)
- {
- client = new TcpClient(AddressFamily.InterNetworkV6);
- TSocketVersionizer.DualModeProperty.SetValue(client.Client, true);
- }
- else
- {
- client = new TcpClient(AddressFamily.InterNetwork);
- }
-
- return client;
- }
-
- /*
- * Creates a TcpListener according to the capabilitites of the used framework
- */
- internal static TcpListener CreateTcpListener(Int32 port)
- {
- TcpListener listener = null;
-
- if (TSocketVersionizer.SupportsDualMode)
- {
- listener = new TcpListener(System.Net.IPAddress.IPv6Any, port);
- TSocketVersionizer.DualModeProperty.SetValue(listener.Server, true);
- }
- else
- {
- listener = new TcpListener(System.Net.IPAddress.Any, port);
- }
-
- return listener;
- }
- }
-}
diff --git a/lib/csharp/src/Transport/TTLSServerSocket.cs b/lib/csharp/src/Transport/TTLSServerSocket.cs
index e56c66c..631a593 100644
--- a/lib/csharp/src/Transport/TTLSServerSocket.cs
+++ b/lib/csharp/src/Transport/TTLSServerSocket.cs
@@ -115,8 +115,8 @@
try
{
// Create server socket
- this.server = TSocketVersionizer.CreateTcpListener(port);
- this.server.Server.NoDelay = true;
+ server = new TcpListener(System.Net.IPAddress.Any, this.port);
+ server.Server.NoDelay = true;
}
catch (Exception)
{
diff --git a/lib/csharp/src/Transport/TTLSSocket.cs b/lib/csharp/src/Transport/TTLSSocket.cs
index d48b7d5..5652556 100644
--- a/lib/csharp/src/Transport/TTLSSocket.cs
+++ b/lib/csharp/src/Transport/TTLSSocket.cs
@@ -172,7 +172,7 @@
/// </summary>
private void InitSocket()
{
- this.client = TSocketVersionizer.CreateTcpClient();
+ this.client = new TcpClient();
client.ReceiveTimeout = client.SendTimeout = timeout;
client.Client.NoDelay = true;
}
@@ -286,7 +286,7 @@
public void setupTLS()
{
RemoteCertificateValidationCallback validator = this.certValidator ?? DefaultCertificateValidator;
-
+
if( this.localCertificateSelectionCallback != null)
{
this.secureStream = new SslStream(
@@ -304,7 +304,7 @@
validator
);
}
-
+
try
{
if (isServer)
diff --git a/lib/csharp/src/Transport/TTransport.cs b/lib/csharp/src/Transport/TTransport.cs
index d4977f1..2811399 100644
--- a/lib/csharp/src/Transport/TTransport.cs
+++ b/lib/csharp/src/Transport/TTransport.cs
@@ -55,7 +55,7 @@
}
catch( IOException)
{
- return false;
+ return false;
}
_hasPeekByte = true;