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;
}
public void CloseInput ()
{
foreach (var ch in channels.ToArray ()) {
- if (ch.State == CommunicationState.Closed)
- RemoveChannel (ch);
+ if (ch.State == CommunicationState.Closed) {
+ lock (channels) {
+ RemoveChannel (ch);
+ }
+ }
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)