THRIFT-3000 .NET implementation has trouble with mixed IP modes
Client: C#
Patch: sharpdevel <icode666@github> & Jens Geyer
This closes #377
This closes #452
This commit effectively establishes .NET 4.5 as a requirement for C#. Trying to build for earlier platform versions will fail. If that turns out to become a problem we should address this with a subsequent ticket.
TcpListener and TcpClient are created based on the capabilities of the used runtime framework. For windows the changes automatically handle IPv4 and IPv6 sockets. In mono it behaves as before.
When using TcpListener and TcpClient it depends on the network configuration if IPv4 or IPv6 is used. By upgrading the framework to .NET 4.5 the DualMode can be set on the sockets of the listener and the client. The sockets then try to establish IPv6 sockets before they fallback to IPv4
diff --git a/lib/csharp/src/Transport/TSocket.cs b/lib/csharp/src/Transport/TSocket.cs
index cf1a440..0b47572 100644
--- a/lib/csharp/src/Transport/TSocket.cs
+++ b/lib/csharp/src/Transport/TSocket.cs
@@ -60,9 +60,9 @@
private void InitSocket()
{
- client = new TcpClient();
- client.ReceiveTimeout = client.SendTimeout = timeout;
- client.Client.NoDelay = true;
+ this.client = TSocketVersionizer.CreateTcpClient();
+ this.client.ReceiveTimeout = client.SendTimeout = timeout;
+ this.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,14 +184,18 @@
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;
}
}
@@ -219,23 +223,23 @@
}
}
- #region " IDisposable Support "
- private bool _IsDisposed;
+ #region " IDisposable Support "
+ private bool _IsDisposed;
- // IDisposable
- protected override void Dispose(bool disposing)
- {
- if (!_IsDisposed)
- {
- if (disposing)
+ // IDisposable
+ protected override void Dispose(bool disposing)
{
- if (client != null)
- ((IDisposable)client).Dispose();
- base.Dispose(disposing);
+ if (!_IsDisposed)
+ {
+ if (disposing)
+ {
+ if (client != null)
+ ((IDisposable)client).Dispose();
+ base.Dispose(disposing);
+ }
+ }
+ _IsDisposed = true;
}
- }
- _IsDisposed = true;
+ #endregion
}
- #endregion
- }
}