Skip to content

Commit

Permalink
Fix remaining moon-unit failures wrt Sockets changes
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Sebastien Pouliot authored and gonzalop committed Jun 15, 2011
1 parent ce9ff91 commit 395aae6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mcs/class/System/System.Net.Sockets/Socket_2_1.cs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 395aae6

Please sign in to comment.