瀏覽代碼

2009-05-29 Atsushi Enomoto <[email protected]>

	* TcpDuplexSessionChannel.cs : Moved tcp listener accept to OnOpen().
	  I cannot precisely identify when EndRecord should be consumed,
	  so allow it at either at the end of ReadSizedMessage() or on
	  consuming preamble (it's likely handling EndRecord of previous
	  message though).

	  Now duplex IPeerResolverContract communication works between
	  either of .NET/Mono client and .NET/Mono server.


svn path=/trunk/mcs/; revision=135046
Atsushi Eno 16 年之前
父節點
當前提交
fb62ee47c1

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

@@ -1,3 +1,14 @@
+2009-05-29  Atsushi Enomoto  <[email protected]>
+
+	* TcpDuplexSessionChannel.cs : Moved tcp listener accept to OnOpen().
+	  I cannot precisely identify when EndRecord should be consumed,
+	  so allow it at either at the end of ReadSizedMessage() or on
+	  consuming preamble (it's likely handling EndRecord of previous
+	  message though).
+
+	  Now duplex IPeerResolverContract communication works between
+	  either of .NET/Mono client and .NET/Mono server.
+
 2009-05-29  Atsushi Enomoto  <[email protected]>
 
 	* TcpDuplexSessionChannel.cs : looks like I have added some bogus

+ 21 - 18
mcs/class/System.ServiceModel/System.ServiceModel.Channels/TcpDuplexSessionChannel.cs

@@ -168,19 +168,7 @@ namespace System.ServiceModel.Channels
 		
 		public override bool WaitForMessage (TimeSpan timeout)
 		{
-			// FIXME: use timeout
-			try {
-				client = tcp_listener.AcceptTcpClient ();
-				Stream s = client.GetStream ();
-
-				frame = new TcpBinaryFrameManager (TcpBinaryFrameManager.DuplexMode, s, is_service_side) { Encoder = this.Encoder };
-
-				// FIXME: use retrieved record properties in the request processing.
-
-				return true;
-			} catch (TimeoutException) {
-				return false;
-			}
+			return true;
 		}
 		
 		// CommunicationObject
@@ -237,6 +225,13 @@ namespace System.ServiceModel.Channels
 					Via = RemoteAddress.Uri };
 			} else {
 				// server side
+				client = tcp_listener.AcceptTcpClient ();
+				Stream s = client.GetStream ();
+
+				frame = new TcpBinaryFrameManager (TcpBinaryFrameManager.DuplexMode, s, is_service_side) { Encoder = this.Encoder };
+
+				// FIXME: use retrieved record properties in the request processing.
+
 			}
 		}
 		
@@ -409,7 +404,7 @@ namespace System.ServiceModel.Channels
 			s.WriteByte (PreambleAckRecord);
 		}
 
-		void ProcessPreambleRecipient ()
+		void ProcessPreambleRecipient (bool allowEndRecord)
 		{
 			bool preambleEnd = false;
 			while (!preambleEnd) {
@@ -440,17 +435,24 @@ namespace System.ServiceModel.Channels
 				case PreambleEndRecord:
 					preambleEnd = true;
 					break;
+				case EndRecord:
+					if (allowEndRecord)
+						break;
+					goto default;
 				default:
 					throw new ProtocolException (String.Format ("Unexpected record type {0:X2}", b));
 				}
 			}
 		}
 
+		bool message_already_read_once;
+
 		public Message ReadSizedMessage ()
 		{
 			// FIXME: implement full [MC-NMF].
 			if (is_service_side) {
-				ProcessPreambleRecipient ();
+				ProcessPreambleRecipient (message_already_read_once);
+				message_already_read_once = true;
 				ProcessPreambleAckRecipient ();
 			}
 
@@ -486,9 +488,10 @@ namespace System.ServiceModel.Channels
 			if (benc != null)
 				benc.CurrentReaderSession = null;
 
-			if (s.Read (eof_buffer, 0, 1) == 1)
-				if (eof_buffer [0] != EndRecord)
-					throw new ProtocolException (String.Format ("Expected EndRecord message, got {0:X02}", eof_buffer [0]));
+			if (!is_service_side)
+				if (s.Read (eof_buffer, 0, 1) == 1)
+					if (eof_buffer [0] != EndRecord)
+						throw new ProtocolException (String.Format ("Expected EndRecord message, got {0:X02}", eof_buffer [0]));
 
 			return msg;
 		}