Inheritance: System.Net.ContextAwareResult
Example #1
0
 public IAsyncResult BeginConnect(IPAddress[] addresses, int port, AsyncCallback requestCallback, object state)
 {
     if (Socket.s_LoggingEnabled)
     Logging.Enter(Logging.Sockets, (object) this, "BeginConnect", (object) addresses);
       if (this.CleanedUp)
     throw new ObjectDisposedException(this.GetType().FullName);
       if (addresses == null)
     throw new ArgumentNullException("addresses");
       if (addresses.Length == 0)
     throw new ArgumentException(SR.GetString("net_invalidAddressList"), "addresses");
       if (!ValidationHelper.ValidateTcpPort(port))
     throw new ArgumentOutOfRangeException("port");
       if (this.addressFamily != AddressFamily.InterNetwork && this.addressFamily != AddressFamily.InterNetworkV6)
     throw new NotSupportedException(SR.GetString("net_invalidversion"));
       if (this.isListening)
     throw new InvalidOperationException(SR.GetString("net_sockets_mustnotlisten"));
       Socket.MultipleAddressConnectAsyncResult context = new Socket.MultipleAddressConnectAsyncResult(addresses, port, this, state, requestCallback);
       context.StartPostingAsyncOp(false);
       if (Socket.DoMultipleAddressConnectCallback(Socket.PostOneBeginConnect(context), context))
     context.InvokeCallback();
       context.FinishPostingAsyncOp(ref this.Caches.ConnectClosureCache);
       if (Socket.s_LoggingEnabled)
     Logging.Exit(Logging.Sockets, (object) this, "BeginConnect", (object) context);
       return (IAsyncResult) context;
 }
Example #2
0
 public IAsyncResult BeginConnect(string host, int port, AsyncCallback requestCallback, object state)
 {
     if (Socket.s_LoggingEnabled)
     Logging.Enter(Logging.Sockets, (object) this, "BeginConnect", host);
       if (this.CleanedUp)
     throw new ObjectDisposedException(this.GetType().FullName);
       if (host == null)
     throw new ArgumentNullException("host");
       if (!ValidationHelper.ValidateTcpPort(port))
     throw new ArgumentOutOfRangeException("port");
       if (this.addressFamily != AddressFamily.InterNetwork && this.addressFamily != AddressFamily.InterNetworkV6)
     throw new NotSupportedException(SR.GetString("net_invalidversion"));
       if (this.isListening)
     throw new InvalidOperationException(SR.GetString("net_sockets_mustnotlisten"));
       Socket.MultipleAddressConnectAsyncResult context = new Socket.MultipleAddressConnectAsyncResult((IPAddress[]) null, port, this, state, requestCallback);
       context.StartPostingAsyncOp(false);
       IAsyncResult hostAddresses = Dns.UnsafeBeginGetHostAddresses(host, new AsyncCallback(Socket.DnsCallback), (object) context);
       if (hostAddresses.CompletedSynchronously && Socket.DoDnsCallback(hostAddresses, context))
     context.InvokeCallback();
       context.FinishPostingAsyncOp(ref this.Caches.ConnectClosureCache);
       if (Socket.s_LoggingEnabled)
     Logging.Exit(Logging.Sockets, (object) this, "BeginConnect", (object) context);
       return (IAsyncResult) context;
 }