[Socket] Improved ConnectAsync
[mono.git] / mcs / class / System / System.Net.Sockets / Socket.cs
index 5844cb9374a7063881daf75373dc61cc981d9557..53ed16251f97221b2153653d6d9fd1917bf0dcc8 100644 (file)
@@ -9,7 +9,7 @@
 //
 // Copyright (C) 2001, 2002 Phillip Pearson and Ximian, Inc.
 //    http://www.myelin.co.nz
-// (c) 2004-2006 Novell, Inc. (http://www.novell.com)
+// (c) 2004-2011 Novell, Inc. (http://www.novell.com)
 //
 
 //
@@ -665,56 +665,6 @@ namespace System.Net.Sockets
                        return(req);
                }
 
-               public IAsyncResult BeginConnect(EndPoint end_point,
-                                                AsyncCallback callback,
-                                                object state) {
-
-                       if (disposed && closed)
-                               throw new ObjectDisposedException (GetType ().ToString ());
-
-                       if (end_point == null)
-                               throw new ArgumentNullException ("end_point");
-
-                       SocketAsyncResult req = new SocketAsyncResult (this, state, callback, SocketOperation.Connect);
-                       req.EndPoint = end_point;
-
-                       // Bug #75154: Connect() should not succeed for .Any addresses.
-                       if (end_point is IPEndPoint) {
-                               IPEndPoint ep = (IPEndPoint) end_point;
-                               if (ep.Address.Equals (IPAddress.Any) || ep.Address.Equals (IPAddress.IPv6Any)) {
-                                       req.Complete (new SocketException ((int) SocketError.AddressNotAvailable), true);
-                                       return req;
-                               }
-                       }
-
-                       int error = 0;
-                       bool blk = blocking;
-                       if (blk)
-                               Blocking = false;
-                       SocketAddress serial = end_point.Serialize ();
-                       Connect_internal (socket, serial, out error);
-                       if (blk)
-                               Blocking = true;
-                       if (error == 0) {
-                               // succeeded synch
-                               connected = true;
-                               req.Complete (true);
-                               return req;
-                       }
-
-                       if (error != (int) SocketError.InProgress && error != (int) SocketError.WouldBlock) {
-                               // error synch
-                               connected = false;
-                               req.Complete (new SocketException (error), true);
-                               return req;
-                       }
-
-                       // continue asynch
-                       connected = false;
-                       socket_pool_queue (Worker.Dispatcher, req);
-                       return(req);
-               }
-
                public IAsyncResult BeginConnect (IPAddress address, int port,
                                                  AsyncCallback callback,
                                                  object state)
@@ -738,63 +688,6 @@ namespace System.Net.Sockets
                        return(BeginConnect (iep, callback, state));
                }
 
-               public IAsyncResult BeginConnect (IPAddress[] addresses,
-                                                 int port,
-                                                 AsyncCallback callback,
-                                                 object state)
-               {
-                       if (disposed && closed)
-                               throw new ObjectDisposedException (GetType ().ToString ());
-
-                       if (addresses == null)
-                               throw new ArgumentNullException ("addresses");
-
-                       if (addresses.Length == 0)
-                               throw new ArgumentException ("Empty addresses list");
-
-                       if (this.AddressFamily != AddressFamily.InterNetwork &&
-                               this.AddressFamily != AddressFamily.InterNetworkV6)
-                               throw new NotSupportedException ("This method is only valid for addresses in the InterNetwork or InterNetworkV6 families");
-
-                       if (port <= 0 || port > 65535)
-                               throw new ArgumentOutOfRangeException ("port", "Must be > 0 and < 65536");
-
-                       if (islistening)
-                               throw new InvalidOperationException ();
-
-                       SocketAsyncResult req = new SocketAsyncResult (this, state, callback, SocketOperation.Connect);
-                       req.Addresses = addresses;
-                       req.Port = port;
-                       connected = false;
-                       return BeginMConnect (req);
-               }
-
-               IAsyncResult BeginMConnect (SocketAsyncResult req)
-               {
-                       IAsyncResult ares = null;
-                       Exception exc = null;
-                       for (int i = req.CurrentAddress; i < req.Addresses.Length; i++) {
-                               IPAddress addr = req.Addresses [i];
-                               IPEndPoint ep = new IPEndPoint (addr, req.Port);
-                               try {
-                                       req.CurrentAddress++;
-                                       ares = BeginConnect (ep, null, req);
-                                       if (ares.IsCompleted && ares.CompletedSynchronously) {
-                                               ((SocketAsyncResult) ares).CheckIfThrowDelayedException ();
-                                               req.DoMConnectCallback ();
-                                       }
-                                       break;
-                               } catch (Exception e) {
-                                       exc = e;
-                               }
-                       }
-
-                       if (ares == null)
-                               throw exc;
-
-                       return req;
-               }
-
                public IAsyncResult BeginConnect (string host, int port,
                                                  AsyncCallback callback,
                                                  object state)
@@ -1215,27 +1108,6 @@ namespace System.Net.Sockets
                        seed_endpoint = local_end;
                }
 
-#if !MOONLIGHT
-               public bool ConnectAsync (SocketAsyncEventArgs e)
-               {
-                       // NO check is made whether e != null in MS.NET (NRE is thrown in such case)
-                       
-                       if (disposed && closed)
-                               throw new ObjectDisposedException (GetType ().ToString ());
-                       if (islistening)
-                               throw new InvalidOperationException ("You may not perform this operation after calling the Listen method.");
-                       if (e.RemoteEndPoint == null)
-                               throw new ArgumentNullException ("remoteEP", "Value cannot be null.");
-                       if (e.BufferList != null)
-                               throw new ArgumentException ("Multiple buffers cannot be used with this method.");
-
-                       e.DoOperation (SocketAsyncOperation.Connect, this);
-
-                       // We always return true for now
-                       return true;
-               }
-#endif
-               
                public void Connect (IPAddress address, int port)
                {
                        Connect (new IPEndPoint (address, port));