diff options
author | fcolin | 2007-02-01 09:57:47 +0000 |
---|---|---|
committer | fcolin | 2007-02-01 09:57:47 +0000 |
commit | 65be617982f9fcce82c58dcccb8c45c2a8e16189 (patch) | |
tree | dcb7418d05d2c8326111c58bfb78519f9e6d606b /CSharp/Ivy/IvyPPC/IvyClient.cs | |
parent | 1b438e4c49394be9dca6909f7bdedd090f0cc054 (diff) | |
download | ivy-csharp-65be617982f9fcce82c58dcccb8c45c2a8e16189.zip ivy-csharp-65be617982f9fcce82c58dcccb8c45c2a8e16189.tar.gz ivy-csharp-65be617982f9fcce82c58dcccb8c45c2a8e16189.tar.bz2 ivy-csharp-65be617982f9fcce82c58dcccb8c45c2a8e16189.tar.xz |
Utilisateur : Fcolin Date : 11/11/03 Heure : 20:54 Archivé dans $/EScribe/Ivy Commentaire: (vss 13)
Diffstat (limited to 'CSharp/Ivy/IvyPPC/IvyClient.cs')
-rw-r--r-- | CSharp/Ivy/IvyPPC/IvyClient.cs | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/CSharp/Ivy/IvyPPC/IvyClient.cs b/CSharp/Ivy/IvyPPC/IvyClient.cs index 3d541d0..dbf8ef1 100644 --- a/CSharp/Ivy/IvyPPC/IvyClient.cs +++ b/CSharp/Ivy/IvyPPC/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;
}
/// <summary> 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
|