summaryrefslogtreecommitdiff
path: root/CSharp
diff options
context:
space:
mode:
authorfcolin2007-02-01 09:49:57 +0000
committerfcolin2007-02-01 09:49:57 +0000
commit3fdb92cf94b8da5c50e431bce0c2de884a5e1c05 (patch)
tree572109723d49bc3b84530bd7ff88dd0f8b0eaab5 /CSharp
parentcc4c8fa1bf41be667705c1aea5ef282a8ef0fa3b (diff)
downloadivy-csharp-3fdb92cf94b8da5c50e431bce0c2de884a5e1c05.zip
ivy-csharp-3fdb92cf94b8da5c50e431bce0c2de884a5e1c05.tar.gz
ivy-csharp-3fdb92cf94b8da5c50e431bce0c2de884a5e1c05.tar.bz2
ivy-csharp-3fdb92cf94b8da5c50e431bce0c2de884a5e1c05.tar.xz
Utilisateur : Fcolin Date : 22/12/05 Heure : 17:48 Archivé dans $/CSharp/Ivy Commentaire: bug dans l'implementation du protocol (vss 3)
Diffstat (limited to 'CSharp')
-rw-r--r--CSharp/Ivy/Ivy/IvyTCPStreamV3.cs80
1 files changed, 27 insertions, 53 deletions
diff --git a/CSharp/Ivy/Ivy/IvyTCPStreamV3.cs b/CSharp/Ivy/Ivy/IvyTCPStreamV3.cs
index 88e7041..43d0d54 100644
--- a/CSharp/Ivy/Ivy/IvyTCPStreamV3.cs
+++ b/CSharp/Ivy/Ivy/IvyTCPStreamV3.cs
@@ -52,28 +52,19 @@ namespace IvyBus
* message Format:
MessageType, id , length, string
*/
- private void Serialize(ushort arg, char sep)
- {
- output.Write(arg);
- output.Write(sep);
- }
- private void Serialize(string[] arg, char sep)
- {
- for (int i = 0; i < arg.Length; i++)
- {
- output.Write(arg[i]);
- if ( i != (arg.Length-1) ) output.Write(sep);
- }
- }
- private void sendMsg(MessageType msgType, ushort msgId,params string[] msgData)
+
+ private void sendMsg(MessageType msgType, ushort msgId, string msgData)
{
#if DEBUG
Console.WriteLine(" sendMsg {0} id={1} data={2}", msgType, msgId, msgData);
#endif
- Serialize((ushort)msgType, ' ');
- Serialize(msgId, ARG_START);
- Serialize(msgData, ARG_END);
- output.Write(MSG_END);
+
+ output.Write((ushort)msgType);
+ output.Write( ' ' );
+ output.Write( msgId );
+ output.Write( ARG_START );
+ output.Write( msgData );
+ output.Write( MSG_END);
output.Flush();
}
public override void TokenStartRegexp(ushort port, string appName)
@@ -128,7 +119,9 @@ namespace IvyBus
public override void TokenMsg(ushort key, string[] args)
{
- sendMsg(MessageType.Msg, key, args);
+ string delimiter = "" + ARG_END;
+ string data = string.Join(delimiter, args);
+ sendMsg(MessageType.Msg, key, data);
}
public override void TokenError(ushort key, string arg)
@@ -152,10 +145,10 @@ namespace IvyBus
} while (Char.IsDigit(digit));
return ret;
}
- private string DeserializeString(char sep,char eol_sep, out bool eol)
+ private string DeserializeString(char sep)
{
int read;
- char car = eol_sep;
+ char car;
StringBuilder str = new StringBuilder();
// this will eat next non separator char
do
@@ -163,56 +156,37 @@ namespace IvyBus
read = input.Read();
if (read < 0) break;
car = (char)read;
- if (car != sep && car != eol_sep) str.Append(car);
- } while (car != sep && car != eol_sep);
- eol = car == eol_sep || (read < 0 );
+ if (car != sep ) str.Append(car);
+ } while (car != sep);
return str.ToString();
}
-
- private string[] DeserializeArgument()
- {
- StringCollection coll;
- string[] args;
- string str;
- bool eol;
-
- coll = new StringCollection();
- do
- {
- str = DeserializeString(ARG_END, MSG_END, out eol);
- coll.Add(str);
- } while (!eol);
- args = new string[coll.Count];
- coll.CopyTo(args, 0);
- return args;
- }
internal override bool receiveMsg()
{
MessageType msgType = MessageType.Die;
ushort msgId = 0;
- string[] msgData = null;
+ string msgData = null;
try
{
msgType = (MessageType)DeserializeShort();
msgId = DeserializeShort();
- msgData = DeserializeArgument();
+ msgData = DeserializeString(MSG_END);
#if DEBUG
Console.WriteLine(" receiveMsg {0} id={1} data={2}", msgType, msgId, msgData);
#endif
switch (msgType)
{
case MessageType.Die:
- receiver.TokenDie(msgId, msgData[0]);
+ receiver.TokenDie(msgId, msgData);
break;
case MessageType.Bye:
- receiver.TokenBye(msgId, msgData[0]);
+ receiver.TokenBye(msgId, msgData);
break;
case MessageType.AddRegexp:
- receiver.TokenAddRegexp(msgId, msgData[0]);
+ receiver.TokenAddRegexp(msgId, msgData);
break;
case MessageType.DelBinding:
@@ -224,27 +198,27 @@ namespace IvyBus
break;
case MessageType.Msg:
- receiver.TokenMsg(msgId, msgData);
+ receiver.TokenMsg(msgId, msgData.Split( ARG_END ));
break;
case MessageType.Pong:
- receiver.TokenPong(msgData[0]);
+ receiver.TokenPong(msgData);
break;
case MessageType.Ping:
- receiver.TokenPing(msgData[0]);
+ receiver.TokenPing(msgData);
break;
case MessageType.Error:
- receiver.TokenError(msgId, msgData[0]);
+ receiver.TokenError(msgId, msgData);
break;
case MessageType.StartRegexp:
- receiver.TokenStartRegexp(msgId, msgData[0]);
+ receiver.TokenStartRegexp(msgId, msgData);
break;
case MessageType.DirectMsg:
- receiver.TokenDirectMsg(msgId, msgData[0]);
+ receiver.TokenDirectMsg(msgId, msgData);
break;
default:
throw new IvyException("protocol error, unknown message type " + msgType);