コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }