Sfoglia il codice sorgente

2009-07-23 Atsushi Enomoto <[email protected]>

	* TcpChannelListener.cs, TcpReplyChannel.cs, TcpRequestChannel.cs:
	  Acquire TcpClient for each request/reply. Now it is fully
	  interoperable with .NET.


svn path=/trunk/mcs/; revision=138501
Atsushi Eno 16 anni fa
parent
commit
e4dc971355

+ 6 - 0
mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog

@@ -1,3 +1,9 @@
+2009-07-23  Atsushi Enomoto  <[email protected]>
+
+	* TcpChannelListener.cs, TcpReplyChannel.cs, TcpRequestChannel.cs:
+	  Acquire TcpClient for each request/reply. Now it is fully
+	  interoperable with .NET.
+
 2009-07-23  Atsushi Enomoto  <[email protected]>
 
 	* TcpReplyChannel.cs, TcpRequestChannel.cs: it somehow adds/expects

+ 17 - 10
mcs/class/System.ServiceModel/System.ServiceModel.Channels/TcpChannelListener.cs

@@ -64,6 +64,22 @@ namespace System.ServiceModel.Channels
 		List<ManualResetEvent> accept_handles = new List<ManualResetEvent> ();
 
 		protected override TChannel OnAcceptChannel (TimeSpan timeout)
+		{
+			TcpClient client = AcceptTcpClient (timeout);
+			if (client == null)
+				return null; // onclose
+
+			if (typeof (TChannel) == typeof (IDuplexSessionChannel))
+				return (TChannel) (object) new TcpDuplexSessionChannel (this, info, client);
+
+			if (typeof (TChannel) == typeof (IReplyChannel))
+				return (TChannel) (object) new TcpReplyChannel (this, info, client);
+
+			throw new InvalidOperationException (String.Format ("Channel type {0} is not supported.", typeof (TChannel).Name));
+		}
+
+		// TcpReplyChannel requires refreshed connection after each request processing.
+		internal TcpClient AcceptTcpClient (TimeSpan timeout)
 		{
 			TcpClient client = null;
 			if (tcp_listener.Pending ()) {
@@ -80,16 +96,7 @@ namespace System.ServiceModel.Channels
 				accept_handles.Add (wait);
 				wait.WaitOne (timeout);
 			}
-			if (client == null)
-				return null; // onclose
-
-			if (typeof (TChannel) == typeof (IDuplexSessionChannel))
-				return (TChannel) (object) new TcpDuplexSessionChannel (this, info, client);
-
-			if (typeof (TChannel) == typeof (IReplyChannel))
-				return (TChannel) (object) new TcpReplyChannel (this, info, client);
-
-			throw new InvalidOperationException (String.Format ("Channel type {0} is not supported.", typeof (TChannel).Name));
+			return client;
 		}
 
 		[MonoTODO]

+ 7 - 2
mcs/class/System.ServiceModel/System.ServiceModel.Channels/TcpReplyChannel.cs

@@ -96,6 +96,8 @@ namespace System.ServiceModel.Channels
 				DateTime start = DateTime.Now;
 				owner.frame.WriteUnsizedMessage (message, timeout);
 				owner.frame.ProcessEndRecordInitiator ();
+				owner.client.Close ();
+				owner.client = null;
 			}
 		}
 
@@ -127,12 +129,15 @@ namespace System.ServiceModel.Channels
 
 		protected override void OnClose (TimeSpan timeout)
 		{
-			if (client != null)
-				client.Close ();
 		}
 
 		protected override void OnOpen (TimeSpan timeout)
 		{
+			DateTime start = DateTime.Now;
+			if (client == null)
+				client = ((TcpChannelListener<IReplyChannel>) Manager).AcceptTcpClient (timeout);
+
+			// FIXME: use timeout
 			NetworkStream ns = client.GetStream ();
 			frame = new TcpBinaryFrameManager (TcpBinaryFrameManager.SingletonUnsizedMode, ns, true) { Encoder = this.Encoder, EncodingRecord = TcpBinaryFrameManager.EncodingBinary };
 			frame.ProcessPreambleRecipient ();

+ 7 - 1
mcs/class/System.ServiceModel/System.ServiceModel.Channels/TcpRequestChannel.cs

@@ -65,6 +65,10 @@ namespace System.ServiceModel.Channels
 		}
 
 		protected override void OnOpen (TimeSpan timeout)
+		{
+		}
+
+		void CreateClient (TimeSpan timeout)
 		{
 			int explicitPort = RemoteAddress.Uri.Port;
 			client = new TcpClient (RemoteAddress.Uri.Host, explicitPort <= 0 ? TcpTransportBindingElement.DefaultPort : explicitPort);
@@ -82,6 +86,8 @@ namespace System.ServiceModel.Channels
 		{
 			DateTime start = DateTime.Now;
 
+			CreateClient (timeout);
+
 			if (input.Headers.To == null)
 				input.Headers.To = RemoteAddress.Uri;
 			if (input.Headers.ReplyTo == null)
@@ -89,7 +95,7 @@ namespace System.ServiceModel.Channels
 			if (input.Headers.MessageId == null)
 				input.Headers.MessageId = new UniqueId ();
 
-			frame.WriteUnsizedMessage (input, timeout);
+			frame.WriteUnsizedMessage (input, timeout - (DateTime.Now - start));
 
 			// It somehow sends EndRecord now ...
 			frame.ProcessEndRecordInitiator ();