THRIFT-2952 Improve handling of Server.Stop()
Client: C#
Patch: Jens Geyer
This closes #361
diff --git a/lib/csharp/src/Server/TSimpleServer.cs b/lib/csharp/src/Server/TSimpleServer.cs
index 36bbe9d..267b470 100644
--- a/lib/csharp/src/Server/TSimpleServer.cs
+++ b/lib/csharp/src/Server/TSimpleServer.cs
@@ -116,7 +116,7 @@
connectionContext = serverEventHandler.createContext(inputProtocol, outputProtocol);
//Process client requests until client disconnects
- while (true)
+ while (!stop)
{
if (!inputTransport.Peek())
break;
@@ -136,9 +136,12 @@
}
}
}
- catch (TTransportException)
+ catch (TTransportException ttx)
{
- //Usually a client disconnect, expected
+ if (!stop || ttx.Type != TTransportException.ExceptionType.Interrupted)
+ {
+ logDelegate(ttx.ToString());
+ }
}
catch (Exception x)
{
diff --git a/lib/csharp/src/Server/TThreadPoolServer.cs b/lib/csharp/src/Server/TThreadPoolServer.cs
index aff5733..4c201e9 100644
--- a/lib/csharp/src/Server/TThreadPoolServer.cs
+++ b/lib/csharp/src/Server/TThreadPoolServer.cs
@@ -118,11 +118,7 @@
}
catch (TTransportException ttx)
{
- if (stop)
- {
- logDelegate("TThreadPoolServer was shutting down, caught " + ttx.GetType().Name);
- }
- else
+ if (!stop || ttx.Type != TTransportException.ExceptionType.Interrupted)
{
++failureCount;
logDelegate(ttx.ToString());
@@ -170,7 +166,7 @@
connectionContext = serverEventHandler.createContext(inputProtocol, outputProtocol);
//Process client requests until client disconnects
- while (true)
+ while (!stop)
{
if (!inputTransport.Peek())
break;
diff --git a/lib/csharp/src/Server/TThreadedServer.cs b/lib/csharp/src/Server/TThreadedServer.cs
index 9e96371..a09337c 100644
--- a/lib/csharp/src/Server/TThreadedServer.cs
+++ b/lib/csharp/src/Server/TThreadedServer.cs
@@ -120,11 +120,7 @@
}
catch (TTransportException ttx)
{
- if (stop)
- {
- logDelegate("TThreadPoolServer was shutting down, caught " + ttx);
- }
- else
+ if (!stop || ttx.Type != TTransportException.ExceptionType.Interrupted)
{
++failureCount;
logDelegate(ttx.ToString());
@@ -202,7 +198,7 @@
connectionContext = serverEventHandler.createContext(inputProtocol, outputProtocol);
//Process client requests until client disconnects
- while (true)
+ while (!stop)
{
if (!inputTransport.Peek())
break;
diff --git a/lib/csharp/src/Transport/TTransportException.cs b/lib/csharp/src/Transport/TTransportException.cs
index 6dcd987..ae987d5 100644
--- a/lib/csharp/src/Transport/TTransportException.cs
+++ b/lib/csharp/src/Transport/TTransportException.cs
@@ -62,7 +62,8 @@
NotOpen,
AlreadyOpen,
TimedOut,
- EndOfFile
+ EndOfFile,
+ Interrupted
}
}
}