Author: atsushi
Date: 2008-02-20 08:47:07 -0500 (Wed, 20 Feb 2008)
New Revision: 96248
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/DuplexSessionChannelBase.cs
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/TcpChannelFactory.cs
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/TcpChannelListener.cs
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/TcpDuplexSessionChannel.cs
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/TcpTransportBindingElementTest.cs
Log:
2008-02-20 Atsushi Enomoto <[EMAIL PROTECTED]>
* DuplexSessionChannelBase.cs : made it non-session (more reusable).
* TcpChannelFactory.cs, TcpChannelListener.cs :
unify factory and listener into TcpChannelInfo for use in
TCP channel implementation. Do not store stream in the listener.
Factory now uses BinaryMessageEncoder.
* TcpDuplexSessionChannel.cs : changes explained above, and now it
holds TcpClient that the listener has accepted.
tcp-transport-binding-element sample now communicates (though
only when both sides are mono: there seems binary mismatch).
* TcpTransportBindingElementTest.cs : IDuplexChannel is not supported.
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
===================================================================
---
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
2008-02-20 13:28:37 UTC (rev 96247)
+++
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
2008-02-20 13:47:07 UTC (rev 96248)
@@ -1,5 +1,18 @@
2008-02-20 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * DuplexSessionChannelBase.cs : made it non-session (more reusable).
+ * TcpChannelFactory.cs, TcpChannelListener.cs :
+ unify factory and listener into TcpChannelInfo for use in
+ TCP channel implementation. Do not store stream in the listener.
+ Factory now uses BinaryMessageEncoder.
+ * TcpDuplexSessionChannel.cs : changes explained above, and now it
+ holds TcpClient that the listener has accepted.
+
+ tcp-transport-binding-element sample now communicates (though
+ only when both sides are mono: there seems binary mismatch).
+
+2008-02-20 Atsushi Enomoto <[EMAIL PROTECTED]>
+
* TcpTransportBindingElement.cs, TcpConnectionPoolSettings.cs :
clone connection pool settings too.
* NamedPipetransportBindingElement.cs,
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/DuplexSessionChannelBase.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/DuplexSessionChannelBase.cs
2008-02-20 13:28:37 UTC (rev 96247)
+++
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/DuplexSessionChannelBase.cs
2008-02-20 13:47:07 UTC (rev 96248)
@@ -12,21 +12,20 @@
namespace System.ServiceModel.Channels
{
- internal abstract class DuplexSessionChannelBase : ChannelBase,
IDuplexSessionChannel
+ internal abstract class DuplexChannelBase : ChannelBase, IDuplexChannel
{
ChannelFactoryBase channel_factory_base;
ChannelListenerBase channel_listener_base;
EndpointAddress local_address;
EndpointAddress remote_address;
- IDuplexSession session;
Uri via;
- public DuplexSessionChannelBase (ChannelFactoryBase factory) :
base (factory)
+ public DuplexChannelBase (ChannelFactoryBase factory) : base
(factory)
{
channel_factory_base = factory;
}
- public DuplexSessionChannelBase (ChannelListenerBase listener)
: base (listener)
+ public DuplexChannelBase (ChannelListenerBase listener) : base
(listener)
{
channel_listener_base = listener;
}
@@ -35,8 +34,6 @@
public abstract EndpointAddress RemoteAddress { get; }
- public abstract IDuplexSession Session { get; }
-
public abstract Uri Via { get; }
public abstract IAsyncResult BeginSend (Message message,
AsyncCallback callback, object state);
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/TcpChannelFactory.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/TcpChannelFactory.cs
2008-02-20 13:28:37 UTC (rev 96247)
+++
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/TcpChannelFactory.cs
2008-02-20 13:47:07 UTC (rev 96248)
@@ -18,16 +18,34 @@
namespace System.ServiceModel.Channels
{
- internal class TcpChannelFactory<TChannel> :
ChannelFactoryBase<TChannel>
+ internal class TcpChannelInfo
{
- // not sure if they are required.
- TcpTransportBindingElement source;
+ public TcpChannelInfo (TcpTransportBindingElement element,
MessageEncoder encoder)
+ {
+ this.element = element;
+ this.encoder = encoder;
+ }
+
+ TcpTransportBindingElement element;
MessageEncoder encoder;
+ public TcpTransportBindingElement BindingElement {
+ get { return element; }
+ }
+
+ public MessageEncoder MessageEncoder {
+ get { return encoder; }
+ }
+ }
+
+ internal class TcpChannelFactory<TChannel> :
ChannelFactoryBase<TChannel>
+ {
+ TcpChannelInfo info;
+
[MonoTODO]
public TcpChannelFactory (TcpTransportBindingElement source,
BindingContext ctx)
{
- this.source = source;
+ MessageEncoder encoder = null;
foreach (BindingElement be in
ctx.RemainingBindingElements) {
MessageEncodingBindingElement mbe = be as
MessageEncodingBindingElement;
if (mbe != null) {
@@ -36,26 +54,23 @@
}
}
if (encoder == null)
- encoder = new TextMessageEncoder
(MessageVersion.Default, Encoding.UTF8);
+ encoder = new BinaryMessageEncoder ();
+ info = new TcpChannelInfo (source, encoder);
}
- public MessageEncoder MessageEncoder {
- get { return encoder; }
- }
-
[MonoTODO]
protected override TChannel OnCreateChannel (
EndpointAddress address, Uri via)
{
ThrowIfDisposedOrNotOpen ();
- if (source.Scheme != address.Uri.Scheme)
+ if (info.BindingElement.Scheme != address.Uri.Scheme)
throw new ArgumentException (String.Format
("Argument EndpointAddress has unsupported URI scheme: {0}",
address.Uri.Scheme));
Type t = typeof (TChannel);
if (t == typeof (IDuplexSessionChannel))
- return (TChannel) (object) new
TcpDuplexSessionChannel ((TcpChannelFactory<IDuplexSessionChannel>) (object)
this, address, via);
+ return (TChannel) (object) new
TcpDuplexSessionChannel (this, info, address, via);
throw new InvalidOperationException (String.Format
("Channel type {0} is not supported.", typeof (TChannel).Name));
}
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/TcpChannelListener.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/TcpChannelListener.cs
2008-02-20 13:28:37 UTC (rev 96247)
+++
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/TcpChannelListener.cs
2008-02-20 13:47:07 UTC (rev 96248)
@@ -22,10 +22,8 @@
{
List<IChannel> channels = new List<IChannel> ();
BindingContext context;
- MessageEncoder encoder;
- Stream s;
- IDuplexSession session;
- TcpTransportBindingElement source;
+ TcpChannelInfo info;
+ IDuplexSession session;
Uri listen_uri;
TcpListener tcp_listener;
@@ -33,8 +31,7 @@
public TcpChannelListener (TcpTransportBindingElement source,
BindingContext context) : base
(context.Binding)
{
- this.source = source;
-
+ MessageEncoder encoder = null;
if (context.ListenUriMode == ListenUriMode.Explicit)
listen_uri =
context.ListenUriRelativeAddress !=
null ?
@@ -53,16 +50,10 @@
if (encoder == null)
encoder = new BinaryMessageEncoder ();
+
+ info = new TcpChannelInfo (source, encoder);
}
- public MessageEncoder MessageEncoder {
- get { return encoder; }
- }
-
- public Stream ClientStream {
- get { return s; }
- }
-
public override Uri Uri {
get { return listen_uri; }
}
@@ -70,35 +61,18 @@
[MonoTODO]
protected override TChannel OnAcceptChannel (TimeSpan timeout)
{
- TcpClient cli = tcp_listener.AcceptTcpClient ();
- s = cli.GetStream ();
-
- //while (s.CanRead)
- // Console.Write ("{0:X02} ", s.ReadByte ());
-
- for (int i = 0; i < 6; i++)
- s.ReadByte ();
-
- int size = s.ReadByte ();
-
- for (int i = 0; i < size; i++)
- s.ReadByte (); // URI
-
- s.ReadByte ();
- s.ReadByte ();
- s.ReadByte ();
- s.WriteByte (0x0B);
- TChannel channel = PopulateChannel (timeout);
+ TChannel channel = PopulateChannel (timeout);
channels.Add (channel);
-
return channel;
}
TChannel PopulateChannel (TimeSpan timeout)
{
+ TcpClient cli = tcp_listener.AcceptTcpClient ();
+
+ // FIXME: pass delegate or something to remove the
channel instance from "channels" when it is closed.
if (typeof (TChannel) == typeof (IDuplexSessionChannel))
- return (TChannel) (object) new
TcpDuplexSessionChannel (
-
(TcpChannelListener<IDuplexSessionChannel>) (object) this, timeout);
+ return (TChannel) (object) new
TcpDuplexSessionChannel (this, info, cli, timeout);
// FIXME: To implement more.
throw new NotImplementedException ();
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/TcpDuplexSessionChannel.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/TcpDuplexSessionChannel.cs
2008-02-20 13:28:37 UTC (rev 96247)
+++
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/TcpDuplexSessionChannel.cs
2008-02-20 13:47:07 UTC (rev 96248)
@@ -18,44 +18,56 @@
namespace System.ServiceModel.Channels
{
- internal class TcpDuplexSessionChannel : DuplexSessionChannelBase
+ internal class TcpDuplexSessionChannel : DuplexChannelBase,
IDuplexSessionChannel
{
- TcpChannelFactory<IDuplexSessionChannel> channel_factory;
- TcpChannelListener<IDuplexSessionChannel> channel_listener;
+
+ TcpChannelInfo info;
TcpClient client;
bool is_service_side;
EndpointAddress local_address;
EndpointAddress remote_address;
- Stream s;
- IDuplexSession session;
TcpListener tcp_listener;
TimeSpan timeout;
Uri via;
- public TcpDuplexSessionChannel
(TcpChannelFactory<IDuplexSessionChannel> factory,
- EndpointAddress address, Uri
via) : base (factory)
+ public TcpDuplexSessionChannel (ChannelFactoryBase factory,
TcpChannelInfo info, EndpointAddress address, Uri via)
+ : base (factory)
{
is_service_side = false;
- channel_factory = factory;
+ this.info = info;
remote_address = address;
this.via = via;
}
- public TcpDuplexSessionChannel
(TcpChannelListener<IDuplexSessionChannel> listener,
- TimeSpan timeout) : base
(listener)
+ public TcpDuplexSessionChannel (ChannelListenerBase listener,
TcpChannelInfo info, TcpClient acceptedRequest, TimeSpan timeout)
+ : base (listener)
{
is_service_side = true;
- channel_listener = listener;
+ this.info = info;
+ this.client = acceptedRequest;
this.timeout = timeout;
+
+ Stream s = client.GetStream ();
+
+ //while (s.CanRead)
+ // Console.Write ("{0:X02} ", s.ReadByte ());
+
+ for (int i = 0; i < 6; i++)
+ s.ReadByte ();
+
+ int size = s.ReadByte ();
+
+ for (int i = 0; i < size; i++)
+ s.ReadByte (); // URI
+
+ s.ReadByte ();
+ s.ReadByte ();
+ s.ReadByte ();
+ s.WriteByte (0x0B);
}
public MessageEncoder Encoder {
- get {
- if (! is_service_side)
- return channel_factory.MessageEncoder;
- else
- return channel_listener.MessageEncoder;
- }
+ get { return info.MessageEncoder; }
}
public override EndpointAddress LocalAddress {
@@ -66,8 +78,9 @@
get { return remote_address; }
}
- public override IDuplexSession Session {
- get { return session; }
+ // FIXME: implement
+ public IDuplexSession Session {
+ get { throw new NotImplementedException (); }
}
public override Uri Via {
@@ -109,8 +122,6 @@
bw.Flush ();
stream.ReadByte (); // 7
-
- stream.Close ();
}
catch (Exception e)
{
@@ -169,7 +180,7 @@
[MonoTODO]
public override Message Receive ()
{
- s = channel_listener.ClientStream;
+ Stream s = client.GetStream ();
s.ReadByte (); // 6
MyBinaryReader br = new MyBinaryReader (s);
// string msg = br.ReadString ();
@@ -189,8 +200,8 @@
s.ReadByte (); // 7
// Console.WriteLine (msg);
s.WriteByte (7);
- ms.Close ();
-
+ s.Flush ();
+
return msg;
}
@@ -237,10 +248,7 @@
[MonoTODO]
protected override void OnClose (TimeSpan timeout)
{
- if (! is_service_side)
- client.Close ();
- else
- s.Close ();
+ client.Close ();
}
[MonoTODO]
Modified:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
===================================================================
---
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
2008-02-20 13:28:37 UTC (rev 96247)
+++
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
2008-02-20 13:47:07 UTC (rev 96248)
@@ -1,5 +1,9 @@
2008-02-20 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * TcpTransportBindingElementTest.cs : IDuplexChannel is not supported.
+
+2008-02-20 Atsushi Enomoto <[EMAIL PROTECTED]>
+
* NetNamedPipeTransportBindingElementTest.cs : new test.
2008-02-20 Atsushi Enomoto <[EMAIL PROTECTED]>
Modified:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/TcpTransportBindingElementTest.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/TcpTransportBindingElementTest.cs
2008-02-20 13:28:37 UTC (rev 96247)
+++
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/TcpTransportBindingElementTest.cs
2008-02-20 13:47:07 UTC (rev 96248)
@@ -92,7 +92,7 @@
Assert.IsFalse
(be.CanBuildChannelFactory<IServiceChannel> (ctx), "#9");
Assert.IsFalse
(be.CanBuildChannelFactory<IClientChannel> (ctx), "#10");
- Assert.IsTrue
(be.CanBuildChannelFactory<IDuplexSessionChannel> (ctx), "#11");
+ Assert.IsFalse
(be.CanBuildChannelFactory<IDuplexChannel> (ctx), "#11");
Assert.IsTrue
(be.CanBuildChannelFactory<IDuplexSessionChannel> (ctx), "#12");
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches