From 9c2e3f136a5568911cb61e71d35e8d170f99a01c Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:46:21 +0000 Subject: Utilisateur : Fcolin Date : 11/11/03 Heure : 20:54 Archivé dans $/EScribe/Ivy Commentaire: (vss 13) --- CSharp/Ivy/Ivy/IvyClient.cs | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/CSharp/Ivy/Ivy/IvyClient.cs b/CSharp/Ivy/Ivy/IvyClient.cs index 3d541d0..dbf8ef1 100644 --- a/CSharp/Ivy/Ivy/IvyClient.cs +++ b/CSharp/Ivy/Ivy/IvyClient.cs @@ -128,8 +128,8 @@ namespace IvyBus private Ivy bus; private MyTcpClient socket; - private StreamReader in_stream; private StreamWriter out_stream; + private StreamReader in_stream; private Hashtable regexp_in; private Hashtable regexp_text; private int appPort; @@ -153,8 +153,8 @@ namespace IvyBus this.bus = bus; this.socket = socket; clientKey = clientSerial++; - in_stream = new StreamReader(socket.GetStream(),System.Text.Encoding.ASCII); out_stream = new StreamWriter(socket.GetStream(),System.Text.Encoding.ASCII); + in_stream = new StreamReader(socket.GetStream(),System.Text.Encoding.ASCII); // sends our ID, whether we initiated the connexion or not // the ID is the couple "host name,application Port", the host name // information is in the socket itself, the port is not known if we @@ -172,10 +172,12 @@ namespace IvyBus // spawns a thread to manage the incoming traffic on this // socket. We should be ready to receive messages now. clientThread = new Thread(new ThreadStart(this.Run)); + clientThread.Name = "Ivy Tcp Client Reader Thread"; clientThread.Start(); if (doping) { pingerThread = new Thread(new ThreadStart(PingerRun)); + pingerThread.Name = "Ivy Pinger Thread"; pingerThread.Start(); } } @@ -227,7 +229,10 @@ namespace IvyBus sendBye("hasta la vista"); stopListening(); // bus.clientDisconnect(this); - socket.Close(); // should I also close in and out ? + // in_stream close in the thread + out_stream.Close(); + out_stream = null; + socket.Close(); socket = null; } @@ -256,19 +261,17 @@ namespace IvyBus internal void stopListening() { - Thread t = clientThread; - if (t == null) + if (clientThread == null) return ; - // we can be summoned to quit from two path at a time - clientThread = null; - // Tell newThread to go to sleep. + // Tell Thread to stop. running = false; - if ( Thread.CurrentThread != t ) + in_stream.Close(); + if ( Thread.CurrentThread != clientThread ) { - t.Interrupt(); - // Wait for newThread to end. - t.Join(); + // Wait for Thread to end. + clientThread.Join(); } + clientThread = null; } /// compares two peers the id is the couple (host,service port). @@ -298,6 +301,7 @@ namespace IvyBus traceDebug("Interrupted while resolving remote hostname"); } traceDebug("Thread started"); + bool running = true; while (running) { @@ -318,10 +322,9 @@ namespace IvyBus break; } } - catch (ThreadInterruptedException te) + catch ( ObjectDisposedException e ) { - Console.Error.WriteLine( te.Message ); - Console.Error.WriteLine( te.StackTrace); + traceDebug( "ivyclient socket closed" ); running = false; break; } @@ -332,11 +335,18 @@ namespace IvyBus running = false; break; } + catch (SocketException se) + { + traceDebug( "ivyclient socket closed" ); + running = false; + break; + } catch (IOException e) { if ( e.InnerException is SocketException ) { - + traceDebug( "ivyclient socket closed" ); + } else { @@ -348,6 +358,8 @@ namespace IvyBus break; } } + in_stream.Close(); + in_stream = null; traceDebug("normally Disconnected from " + appName); traceDebug("Thread stopped"); // invokes the Disconnected applicationListeners -- cgit v1.1