using System.Transactions;
using System.ServiceModel;
using System.ServiceModel.Description;
+using System.Net.Sockets;
+using System.Xml;
+using System.IO;
namespace System.ServiceModel.Dispatcher
{
public void Start ()
{
- if (loop_thread == null)
+ if (loop_thread == null) {
loop_thread = new Thread (new ThreadStart (Loop));
+ loop_thread.IsBackground = true;
+ }
+
loop_thread.Start ();
}
if (loop_thread == null)
return;
- close_started = DateTime.Now;
+ close_started = DateTime.UtcNow;
close_timeout = timeout;
loop = false;
creator_handle.Set ();
Logger.Warning (String.Format ("Channel listener '{0}' is not closed. Aborting.", owner.Listener.GetType ()));
owner.Listener.Abort ();
}
- if (loop_thread != null && loop_thread.IsAlive)
- loop_thread.Abort ();
+ if (loop_thread != null && loop_thread.IsAlive) {
+ if (!loop_thread.Join (500))
+ loop_thread.Abort ();
+ }
loop_thread = null;
}
}
else {
try {
- ch.Close (close_timeout - (DateTime.Now - close_started));
+ ch.Close (close_timeout - (DateTime.UtcNow - close_started));
} catch (Exception ex) {
// FIXME: log it.
Logger.Error (String.Format ("Exception on closing channel ({0})", ch.GetType ()), ex);
{
Message msg;
var input = (IInputChannel) result.AsyncState;
- if (input.EndTryReceive (result, out msg))
- ProcessInput (input, msg);
- else
+ try {
+ if (input.EndTryReceive (result, out msg))
+ ProcessInput (input, msg);
+ else
+ input.Close ();
+ } catch (ObjectDisposedException) {
input.Close ();
+ }
}
void ProcessRequest (IReplyChannel reply, RequestContext rc)
if (ProcessErrorWithHandlers (reply, ex, out res))
return;
- rc.Reply (res);
+ if ((!(ex is SocketException)) &&
+ (!(ex is XmlException)) &&
+ (!(ex is IOException)))
+ rc.Reply (res);
reply.Close (owner.DefaultCloseTimeout); // close the channel
} finally {