Просмотр исходного кода

2009-08-26 Atsushi Enomoto <[email protected]>

	* PeerDuplexChannel.cs : When received Connect() from neighbor,
	  add the peer to its internal list.
	  Finally ChatApplication got working.


svn path=/trunk/mcs/; revision=140700
Atsushi Eno 16 лет назад
Родитель
Сommit
ef6042e66b

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

@@ -1,3 +1,9 @@
+2009-08-26  Atsushi Enomoto  <[email protected]>
+
+	* PeerDuplexChannel.cs : When received Connect() from neighbor,
+	  add the peer to its internal list.
+	  Finally ChatApplication got working.
+
 2009-08-26  Atsushi Enomoto  <[email protected]>
 
 	* PeerDuplexChannel.cs : since the channel factory is per instance,

+ 5 - 1
mcs/class/System.ServiceModel/System.ServiceModel.Channels/PeerDuplexChannel.cs

@@ -29,6 +29,7 @@ using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.IO;
+using System.Linq;
 using System.Net;
 using System.Net.Security;
 using System.Net.Sockets;
@@ -95,6 +96,8 @@ namespace System.ServiceModel.Channels
 				// FIXME: check and reject if inappropriate. For example, maximum connection exceeded.
 				using (var octx = new OperationContextScope ((IContextChannel) ch)) {
 					OperationContext.Current.OutgoingMessageHeaders.To = new Uri (Constants.WsaAnonymousUri);
+					if (!owner.peers.Any (p => p.Address.EndpointAddress.Equals (connect.Address.EndpointAddress)))
+						owner.peers.Add (new RemotePeerConnection (connect.Address));
 					ch.Welcome (new WelcomeInfo () { NodeId = owner.node.NodeId });
 				}
 			}
@@ -217,7 +220,8 @@ namespace System.ServiceModel.Channels
 			// FIXME: give max buffer size
 			var mb = message.CreateBufferedCopy (0x10000);
 
-			foreach (var pc in peers) {
+			for (int i = 0; i < peers.Count; i++) {
+				var pc = peers [i];
 				message = mb.CreateMessage ();
 
 				if (pc.Status == RemotePeerStatus.None) {