Esempio n. 1
0
 // Token: 0x060007F4 RID: 2036 RVA: 0x0001CCD0 File Offset: 0x0001AED0
 private static void ConnectAsyncpublic(this EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectedCallback callback, object state)
 {
     if (remoteEndPoint is DnsEndPoint)
     {
         DnsEndPoint  dnsEndPoint = (DnsEndPoint)remoteEndPoint;
         IAsyncResult asyncResult = Dns.BeginGetHostAddresses(dnsEndPoint.Host, new AsyncCallback(ConnectAsyncExtension.OnGetHostAddresses), new ConnectAsyncExtension.DnsConnectState
         {
             Port          = dnsEndPoint.Port,
             Callback      = callback,
             State         = state,
             LocalEndPoint = localEndPoint
         });
         if (asyncResult.CompletedSynchronously)
         {
             ConnectAsyncExtension.OnGetHostAddresses(asyncResult);
             return;
         }
     }
     else
     {
         SocketAsyncEventArgs e = ConnectAsyncExtension.CreateSocketAsyncEventArgs(remoteEndPoint, callback, state);
         Socket socket          = new Socket(remoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
         if (localEndPoint != null)
         {
             socket.ExclusiveAddressUse = false;
             socket.Bind(localEndPoint);
         }
         socket.ConnectAsync(e);
     }
 }
Esempio n. 2
0
        // Token: 0x060007F7 RID: 2039 RVA: 0x0001CF08 File Offset: 0x0001B108
        private static void SocketConnectCompleted(object sender, SocketAsyncEventArgs e)
        {
            ConnectAsyncExtension.DnsConnectState dnsConnectState = e.UserToken as ConnectAsyncExtension.DnsConnectState;
            if (e.SocketError == SocketError.Success)
            {
                ConnectAsyncExtension.ClearSocketAsyncEventArgs(e);
                dnsConnectState.Callback((Socket)sender, dnsConnectState.State, e, null);
                return;
            }
            if (e.SocketError != SocketError.HostUnreachable && e.SocketError != SocketError.ConnectionRefused)
            {
                ConnectAsyncExtension.ClearSocketAsyncEventArgs(e);
                dnsConnectState.Callback(null, dnsConnectState.State, e, null);
                return;
            }
            Socket    socket;
            IPAddress nextAddress = ConnectAsyncExtension.GetNextAddress(dnsConnectState, out socket);

            if (nextAddress == null)
            {
                ConnectAsyncExtension.ClearSocketAsyncEventArgs(e);
                e.SocketError = SocketError.HostUnreachable;
                dnsConnectState.Callback(null, dnsConnectState.State, e, null);
                return;
            }
            e.RemoteEndPoint = new IPEndPoint(nextAddress, dnsConnectState.Port);
            if (!socket.ConnectAsync(e))
            {
                ConnectAsyncExtension.SocketConnectCompleted(socket, e);
            }
        }
Esempio n. 3
0
        // Token: 0x060007F6 RID: 2038 RVA: 0x0001CDD4 File Offset: 0x0001AFD4
        private static void OnGetHostAddresses(IAsyncResult result)
        {
            ConnectAsyncExtension.DnsConnectState dnsConnectState = result.AsyncState as ConnectAsyncExtension.DnsConnectState;
            IPAddress[] array;
            try
            {
                array = Dns.EndGetHostAddresses(result);
            }
            catch (Exception exception)
            {
                dnsConnectState.Callback(null, dnsConnectState.State, null, exception);
                return;
            }
            if (array == null || array.Length == 0)
            {
                dnsConnectState.Callback(null, dnsConnectState.State, null, new SocketException(11001));
                return;
            }
            dnsConnectState.Addresses = array;
            Socket    socket;
            IPAddress nextAddress = ConnectAsyncExtension.GetNextAddress(dnsConnectState, out socket);

            if (nextAddress == null)
            {
                dnsConnectState.Callback(null, dnsConnectState.State, null, new SocketException(10047));
                return;
            }
            if (dnsConnectState.LocalEndPoint != null)
            {
                try
                {
                    socket.ExclusiveAddressUse = false;
                    socket.Bind(dnsConnectState.LocalEndPoint);
                }
                catch (Exception exception2)
                {
                    dnsConnectState.Callback(null, dnsConnectState.State, null, exception2);
                    return;
                }
            }
            SocketAsyncEventArgs socketAsyncEventArgs = new SocketAsyncEventArgs();

            socketAsyncEventArgs.Completed += ConnectAsyncExtension.SocketConnectCompleted;
            IPEndPoint remoteEndPoint = new IPEndPoint(nextAddress, dnsConnectState.Port);

            socketAsyncEventArgs.RemoteEndPoint = remoteEndPoint;
            socketAsyncEventArgs.UserToken      = dnsConnectState;
            if (!socket.ConnectAsync(socketAsyncEventArgs))
            {
                ConnectAsyncExtension.SocketConnectCompleted(socket, socketAsyncEventArgs);
            }
        }