summaryrefslogtreecommitdiff
path: root/Ivy/IvyUDPStream.cs
diff options
context:
space:
mode:
authorfcolin2008-08-22 16:44:01 +0000
committerfcolin2008-08-22 16:44:01 +0000
commit8d10e8bbd1e19adc7c70e1101dbb69c213c910dd (patch)
treef41034ab66b1b3174277b07c8aa45791dadbaae8 /Ivy/IvyUDPStream.cs
parent7053d3d604920ab708076e107be4b55666c5af80 (diff)
downloadivy-csharp-8d10e8bbd1e19adc7c70e1101dbb69c213c910dd.zip
ivy-csharp-8d10e8bbd1e19adc7c70e1101dbb69c213c910dd.tar.gz
ivy-csharp-8d10e8bbd1e19adc7c70e1101dbb69c213c910dd.tar.bz2
ivy-csharp-8d10e8bbd1e19adc7c70e1101dbb69c213c910dd.tar.xz
optimisation for parsing same regular expression from multiple client
using fxCop for code beauty fix bug on concurrent connect
Diffstat (limited to 'Ivy/IvyUDPStream.cs')
-rw-r--r--Ivy/IvyUDPStream.cs72
1 files changed, 51 insertions, 21 deletions
diff --git a/Ivy/IvyUDPStream.cs b/Ivy/IvyUDPStream.cs
index 0e3f517..986a550 100644
--- a/Ivy/IvyUDPStream.cs
+++ b/Ivy/IvyUDPStream.cs
@@ -1,34 +1,34 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Net;
-using System.Net.Sockets;
-using System.IO;
namespace IvyBus
{
- abstract class IvyUDPStream
+ using System;
+ using System.Collections.Generic;
+ using System.Text;
+ using System.Net;
+ using System.Net.Sockets;
+ using System.IO;
+
+ abstract class IvyUDPStream: IDisposable
{
- Socket socket;
- byte[] buffer;
-
protected MemoryStream out_stream;
protected MemoryStream in_stream;
+ private Socket socket;
+ private byte[] buffer;
+
+ private int protocolVersion;
- ushort protocol_version;
-
- public ushort ProtocolVersion
+ public int ProtocolVersion
{
- get { return protocol_version; }
+ get { return protocolVersion; }
}
- public IvyUDPStream(Socket _socket, ushort protocol)
+ public IvyUDPStream(Socket _socket, int protocol)
{
socket = _socket;
buffer = new byte[4096];
in_stream = new MemoryStream(buffer);
out_stream = new MemoryStream();
- protocol_version = protocol;
+ protocolVersion = protocol;
}
internal void Close()
{
@@ -37,7 +37,7 @@ namespace IvyBus
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}
- internal void receiveMsg(out IPEndPoint remote, out ushort version, out ushort port, out string appId, out string appName)
+ internal void receiveMsg(out IPEndPoint remote, out int version, out int port, out string appId, out string appName)
{
int len;
IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
@@ -51,7 +51,7 @@ namespace IvyBus
//Call Deserialization
Deserialize( out version, out port, out appId, out appName );
}
- internal void sendMsg(IPEndPoint EPhost, ushort port, string appId, string appName)
+ internal void sendMsg(IPEndPoint EPhost, int port, string appId, string appName)
{
// Call Serialisation
Serialize(port, appId, appName);
@@ -59,8 +59,38 @@ namespace IvyBus
byte[] hellob = out_stream.GetBuffer();
socket.SendTo(hellob, (int)out_stream.Length, 0, EPhost);
}
- abstract internal void Serialize(ushort port, string appId, string appName);
- abstract internal void Deserialize(out ushort version, out ushort port, out string appId, out string appName);
-
+ abstract internal void Serialize(int port, string appId, string appName);
+ abstract internal void Deserialize(out int version, out int port, out string appId, out string appName);
+
+
+ #region IDisposable Membres
+
+ //Implement IDisposable.
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ // Free other state (managed objects).
+ }
+ // Free your own state (unmanaged objects).
+ // Set large fields to null.
+ if (out_stream != null)
+ {
+ out_stream.Close();
+ out_stream = null;
+ }
+ if (in_stream != null)
+ {
+ in_stream.Close();
+ in_stream = null;
+ }
+ }
+ #endregion
}
}