2009-05-22 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Fri, 22 May 2009 13:58:03 +0000 (13:58 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Fri, 22 May 2009 13:58:03 +0000 (13:58 -0000)
* Socket_2_1.cs: Do not throw a SecurityException if the security
policy check fails in NET_2_1 but set the SocketError to AccessDenied
ensure the EndPoint has a valid policy before connecting.
* SocketAsyncEventArgs.cs: Don't recurse endlessly in SendCallback
and ReceiveCallback if the socket is not connected. Check for
AccessDenied in ConnectCallback (needed for the security policy
check in NET_2_1).

svn path=/trunk/mcs/; revision=134596

mcs/class/System/System.Net.Sockets/ChangeLog
mcs/class/System/System.Net.Sockets/SocketAsyncEventArgs.cs
mcs/class/System/System.Net.Sockets/Socket_2_1.cs

index 88fcdde19c2f2a66b640d9367797503738e86b08..0c40cec58cd66ac405daa449471422191038855d 100644 (file)
@@ -1,3 +1,13 @@
+2009-05-22  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * Socket_2_1.cs: Do not throw a SecurityException if the security
+       policy check fails in NET_2_1 but set the SocketError to AccessDenied
+       ensure the EndPoint has a valid policy before connecting.
+       * SocketAsyncEventArgs.cs: Don't recurse endlessly in SendCallback
+       and ReceiveCallback if the socket is not connected. Check for
+       AccessDenied in ConnectCallback (needed for the security policy
+       check in NET_2_1).
+
 2009-05-14  Sebastien Pouliot  <sebastien@ximian.com>
 
        * Socket_2_1.cs: Add ConnectAsync support for NET_2_1 which will
index f05cb2208dac22eaf124abbfb7443758adede138..3e488f24c382969cd870e0d412e7e621f74f087c 100644 (file)
@@ -163,6 +163,11 @@ namespace System.Net.Sockets
                        SocketError = SocketError.Success;
                        LastOperation = SocketAsyncOperation.Receive;
                        SocketError error = SocketError.Success;
+
+                       if (!curSocket.Connected) {
+                               SocketError = SocketError.NotConnected;
+                               return;
+                       }
                        
                        try {
                                // FIXME: this does not support using BufferList
@@ -175,8 +180,15 @@ namespace System.Net.Sockets
 
                void ConnectCallback ()
                {
-                       SocketError = SocketError.Success;
                        LastOperation = SocketAsyncOperation.Connect;
+#if NET_2_1
+                       if (SocketError == SocketError.AccessDenied) {
+                               curSocket.Connected = false;
+                               OnCompleted (this);
+                               return;
+                       }
+#endif
+                       SocketError = SocketError.Success;
                        SocketError error = SocketError.Success;
 
                        try {
@@ -207,6 +219,11 @@ namespace System.Net.Sockets
                        LastOperation = SocketAsyncOperation.Send;
                        SocketError error = SocketError.Success;
 
+                       if (!curSocket.Connected) {
+                               SocketError = SocketError.NotConnected;
+                               return;
+                       }
+
                        try {
                                if (Buffer != null) {
                                        BytesTransferred = curSocket.Send_nochecks (Buffer, Offset, Count, SocketFlags.None, out error);
index df03ea10dd1512f39291545cc102817d32fd3438..cf91f60c3a4719ab993e341580fc1af43a8517db 100644 (file)
@@ -191,6 +191,10 @@ namespace System.Net.Sockets {
                
                public Socket(AddressFamily family, SocketType type, ProtocolType proto)
                {
+#if NET_2_1
+                       if (family == AddressFamily.Unspecified)
+                               throw new ArgumentException ("family");
+#endif
                        address_family=family;
                        socket_type=type;
                        protocol_type=proto;
@@ -695,14 +699,15 @@ namespace System.Net.Sockets {
                        if (!checkPolicy)
                                return;
 
+                       e.SocketError = SocketError.AccessDenied;
                        if (check_socket_policy == null) {
                                Type type = Type.GetType ("System.Windows.Browser.Net.CrossDomainPolicyManager, System.Windows.Browser, Version=2.0.5.0, Culture=Neutral, PublicKeyToken=7cec85d7bea7798e");
                                check_socket_policy = type.GetMethod ("CheckEndPoint");
                                if (check_socket_policy == null)
                                        throw new SecurityException ();
                        }
-                       if (!(bool) check_socket_policy.Invoke (null, new object [1] { e.RemoteEndPoint }))
-                               throw new SecurityException ();
+                       if ((bool) check_socket_policy.Invoke (null, new object [1] { e.RemoteEndPoint }))
+                               e.SocketError = SocketError.Success;
                }
 
                // only _directly_ used (with false) to download the socket policy