From 395aae632d98c8d1b10ed97d8d5a5a75c5b07b79 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Thu, 28 Apr 2011 16:33:12 -0400 Subject: [PATCH] Fix remaining moon-unit failures wrt Sockets changes * System.Net.Sockets/Socket_2_1.cs: Ensure RemoteEndPoint is always available after ConnectAsync (connected or not, allowed or not). Ensure the Connect event is fired even if denied by policy. --- .../System/System.Net.Sockets/Socket_2_1.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mcs/class/System/System.Net.Sockets/Socket_2_1.cs b/mcs/class/System/System.Net.Sockets/Socket_2_1.cs index c74b9567b33f..6682cfbefe90 100644 --- a/mcs/class/System/System.Net.Sockets/Socket_2_1.cs +++ b/mcs/class/System/System.Net.Sockets/Socket_2_1.cs @@ -573,6 +573,11 @@ public void Connect () #if !MOONLIGHT bool is_mconnect = (mconnect != null && mconnect.Addresses != null); #else + if (result.ErrorCode == SocketError.AccessDenied) { + result.Complete (); + result.DoMConnectCallback (); + return; + } bool is_mconnect = false; #endif try { @@ -1605,6 +1610,8 @@ bool GetCheckedIPs (SocketAsyncEventArgs e, out IPAddress [] addresses) continue; valid.Add (a); } + if (valid.Count == 0) + e.SocketError = SocketError.AccessDenied; addresses = valid.ToArray (); } #endif @@ -1615,6 +1622,8 @@ bool GetCheckedIPs (SocketAsyncEventArgs e, out IPAddress [] addresses) if (!e.PolicyRestricted && !SecurityManager.HasElevatedPermissions) { if (CrossDomainPolicyManager.CheckEndPoint (e.RemoteEndPoint, e.SocketClientAccessPolicyProtocol)) return false; + else + e.SocketError = SocketError.AccessDenied; } else #endif return false; @@ -1631,11 +1640,23 @@ bool ConnectAsyncReal (SocketAsyncEventArgs e) bool use_remoteep = true; #if MOONLIGHT || NET_4_0 use_remoteep = !GetCheckedIPs (e, out addresses); + bool policy_failed = (e.SocketError == SocketError.AccessDenied); #endif e.curSocket = this; Worker w = e.Worker; w.Init (this, e, SocketOperation.Connect); SocketAsyncResult result = w.result; +#if MOONLIGHT + if (policy_failed) { + // SocketAsyncEventArgs.Completed must be called + connected = false; + result.EndPoint = e.RemoteEndPoint; + result.error = (int) SocketError.AccessDenied; + result.Complete (); + socket_pool_queue (Worker.Dispatcher, result); + return true; + } +#endif IAsyncResult ares = null; try { if (use_remoteep) { @@ -1699,6 +1720,9 @@ public bool ConnectAsync (SocketAsyncEventArgs e) if ((raf != AddressFamily.Unspecified) && (raf != AddressFamily)) throw new NotSupportedException ("AddressFamily mismatch between socket and endpoint"); + // connected, not yet connected or even policy denied, the Socket.RemoteEndPoint is always + // available after the ConnectAsync call + seed_endpoint = e.RemoteEndPoint; return ConnectAsyncReal (e); }