summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfcolin2010-03-12 16:40:27 +0000
committerfcolin2010-03-12 16:40:27 +0000
commitebc2a8ef21bd90e753cf9b88ea186b0c87775de3 (patch)
treea872054e01243a0cb1a000f36f8a1e64e1f87914
parentddccd3d8f4fd59fb19fa6262460bbc5e2e67eac7 (diff)
downloadivy-csharp-ebc2a8ef21bd90e753cf9b88ea186b0c87775de3.zip
ivy-csharp-ebc2a8ef21bd90e753cf9b88ea186b0c87775de3.tar.gz
ivy-csharp-ebc2a8ef21bd90e753cf9b88ea186b0c87775de3.tar.bz2
ivy-csharp-ebc2a8ef21bd90e753cf9b88ea186b0c87775de3.tar.xz
mise en conformité des messages ping /pong
start regexpid a 0 catch plantage NULL ref Correction pb a la fermeture d'ivy
-rw-r--r--Ivy.sln3
-rw-r--r--Ivy/Ivy.cs7
-rw-r--r--Ivy/IvyClient.cs20
-rw-r--r--Ivy/IvyProtocol.cs4
-rw-r--r--Ivy/IvyTCPStreamV3.cs21
-rw-r--r--Ivy/IvyTCPStreamV4.cs19
6 files changed, 45 insertions, 29 deletions
diff --git a/Ivy.sln b/Ivy.sln
index c3cdd2d..18ed02a 100644
--- a/Ivy.sln
+++ b/Ivy.sln
@@ -96,8 +96,7 @@ Global
{19023DE7-AAD8-4EC4-8FAF-D793868F8861}.Release|x86.ActiveCfg = Release|Any CPU
{F2F03CF7-0087-4EDB-AD15-80C9E8DA2617}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2F03CF7-0087-4EDB-AD15-80C9E8DA2617}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {F2F03CF7-0087-4EDB-AD15-80C9E8DA2617}.Debug|x86.ActiveCfg = Debug|x86
- {F2F03CF7-0087-4EDB-AD15-80C9E8DA2617}.Debug|x86.Build.0 = Debug|x86
+ {F2F03CF7-0087-4EDB-AD15-80C9E8DA2617}.Debug|x86.ActiveCfg = Debug|Any CPU
{F2F03CF7-0087-4EDB-AD15-80C9E8DA2617}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2F03CF7-0087-4EDB-AD15-80C9E8DA2617}.Release|Any CPU.Build.0 = Release|Any CPU
{F2F03CF7-0087-4EDB-AD15-80C9E8DA2617}.Release|x86.ActiveCfg = Release|x86
diff --git a/Ivy/Ivy.cs b/Ivy/Ivy.cs
index 1dfd967..922bb27 100644
--- a/Ivy/Ivy.cs
+++ b/Ivy/Ivy.cs
@@ -198,7 +198,7 @@ namespace IvyBus
private static readonly string DefaultDomain = "127.0.0.1:" + DefaultPort;
internal int protocolVersion = 3;
private static bool debugProtocol; // false by default runtime
- private static int serial; /* an unique ID for each regexp */ // 0 by default runtime
+ private static int serial = -1; /* an unique ID for each regexp */ // -1 to start numbering at 0
private MyTcpListener app;
private List<IvyWatcher> watchers;
private Thread serverThread; // to ensure quick communication of the end
@@ -887,9 +887,12 @@ namespace IvyBus
/// <returns></returns>
public int Ping(string target, string message)
{
+ int id = (int)DateTime.Now.Ticks;
ReadOnlyCollection<IvyClient> v = GetClientsByName(target);
foreach (IvyClient clnt in v)
- clnt.stream.TokenPing(message);
+ {
+ clnt.stream.TokenPing(id, message);
+ }
return v.Count;
}
diff --git a/Ivy/IvyClient.cs b/Ivy/IvyClient.cs
index 93f62ca..98d7901 100644
--- a/Ivy/IvyClient.cs
+++ b/Ivy/IvyClient.cs
@@ -291,6 +291,10 @@ namespace IvyBus
{
stream.Close(); // should stop the Reading Client Thread
}
+ catch (EndOfStreamException ioe)
+ {
+ throw new IvyException(ioe.Message);
+ }
catch (IOException ioe)
{
throw new IvyException(ioe.Message);
@@ -325,8 +329,11 @@ namespace IvyBus
try
{
- stream.TokenMsg(id, args);
- count++;
+ if (stream != null)
+ {
+ stream.TokenMsg(id, args);
+ count++;
+ }
}
catch (ObjectDisposedException ex)
{
@@ -581,13 +588,13 @@ namespace IvyBus
{
bus.OnDirectMessage(new IvyEventArgs(this,id,arg));
}
- void IvyProtocol.TokenPing(string arg)
+ void IvyProtocol.TokenPing(int id, string arg)
{
// I receive a ping. I can answer a pong.
Ivy.traceProtocol(Resources.IvyClient, Resources.PingReceive + appName + " : " + arg );
- stream.TokenPong(arg);
+ stream.TokenPong(id,arg);
}
- void IvyProtocol.TokenPong(string arg)
+ void IvyProtocol.TokenPong(int id, string arg)
{
Ivy.traceProtocol(Resources.IvyClient, Resources.PingReceive + appName + " : " + arg);
}
@@ -614,7 +621,8 @@ namespace IvyBus
try
{
Thread.Sleep(PINGTIMEOUT);
- stream.TokenPing(Resources.PingerThreadMessage);
+ int id = (int)DateTime.Now.Ticks;
+ stream.TokenPing( id, Resources.PingerThreadMessage);
}
catch (ThreadAbortException ie)
{
diff --git a/Ivy/IvyProtocol.cs b/Ivy/IvyProtocol.cs
index 6c276e3..c9d11ed 100644
--- a/Ivy/IvyProtocol.cs
+++ b/Ivy/IvyProtocol.cs
@@ -18,8 +18,8 @@ namespace IvyBus
void TokenAddBinding(BindingType type, int id, string expression);
void TokenDelBinding(int bind);
void TokenDirectMsg(int id, string message);
- void TokenPong(string s);
- void TokenPing(string s);
+ void TokenPong(int id, string s);
+ void TokenPing(int id, string s);
void TokenBye(int id, string message);
void TokenDie(int err, string message);
void TokenMsg(int key, string[] args);
diff --git a/Ivy/IvyTCPStreamV3.cs b/Ivy/IvyTCPStreamV3.cs
index e261f5e..6c23726 100644
--- a/Ivy/IvyTCPStreamV3.cs
+++ b/Ivy/IvyTCPStreamV3.cs
@@ -31,10 +31,11 @@ namespace IvyBus
this.input = new StreamReader(this, Ivy.ivyEncoding);
this.receiver = receiver;
}
- internal void Close()
+ void IvyProtocol.Close()
{
- this.input.Close();
this.output.Close();
+ this.input.Close();
+ this.Socket.Shutdown(SocketShutdown.Both);
base.Close();
}
@@ -110,14 +111,14 @@ namespace IvyBus
this.SendMsg(MessageType.DirectMsg, id, message);
}
- void IvyProtocol.TokenPong(string s)
+ void IvyProtocol.TokenPong(int id, string s)
{
- this.SendMsg(MessageType.Pong, 0, s);
+ this.SendMsg(MessageType.Pong, id, s);
}
- void IvyProtocol.TokenPing(string s)
+ void IvyProtocol.TokenPing(int id, string s)
{
- this.SendMsg(MessageType.Ping, 0, s);
+ this.SendMsg(MessageType.Ping, id, s);
}
void IvyProtocol.TokenBye(int id, string message)
@@ -223,11 +224,11 @@ namespace IvyBus
break;
case MessageType.Pong:
- this.receiver.TokenPong(msgData);
+ this.receiver.TokenPong(msgId,msgData);
break;
case MessageType.Ping:
- this.receiver.TokenPing(msgData);
+ this.receiver.TokenPing(msgId,msgData);
break;
case MessageType.Error:
@@ -249,6 +250,10 @@ namespace IvyBus
}
+ catch (NullReferenceException)
+ {
+ return false;
+ }
catch (EndOfStreamException)
{
return false;
diff --git a/Ivy/IvyTCPStreamV4.cs b/Ivy/IvyTCPStreamV4.cs
index 65e325c..20526c7 100644
--- a/Ivy/IvyTCPStreamV4.cs
+++ b/Ivy/IvyTCPStreamV4.cs
@@ -45,11 +45,12 @@ namespace IvyBus
this.output = new BinaryWriter(this, Ivy.ivyEncoding);
this.receiver = _receiver;
}
-
- internal void Close()
+
+ void IvyProtocol.Close()
{
- this.input.Close();
this.output.Close();
+ this.input.Close();
+ this.Socket.Shutdown(SocketShutdown.Both);
base.Close();
}
@@ -124,13 +125,13 @@ namespace IvyBus
{
sendMsg(MessageType.DirectMsg, id, message);
}
- void IvyProtocol.TokenPong(string s)
+ void IvyProtocol.TokenPong(int id, string s)
{
- sendMsg(MessageType.Pong, 0, s);
+ sendMsg(MessageType.Pong, id, s);
}
- void IvyProtocol.TokenPing(string s)
+ void IvyProtocol.TokenPing(int id, string s)
{
- sendMsg(MessageType.Ping, 0, s);
+ sendMsg(MessageType.Ping, id, s);
}
void IvyProtocol.TokenBye(int id, string message)
@@ -233,11 +234,11 @@ namespace IvyBus
break;
case MessageType.Pong:
- receiver.TokenPong(msgData[0]);
+ receiver.TokenPong( msgId, msgData[0]);
break;
case MessageType.Ping:
- receiver.TokenPing(msgData[0]);
+ receiver.TokenPing( msgId, msgData[0]);
break;
case MessageType.Error: