Ejemplo n.º 1
0
        private static IPAddress GetNextAddress(DnsConnectState state, out Socket attempSocket)
        {
            IPAddress address = null;

            attempSocket = null;

            var currentIndex = state.NextAddressIndex;

            while (attempSocket == null)
            {
                if (currentIndex >= state.Addresses.Length)
                {
                    return(null);
                }

                address = state.Addresses[currentIndex++];

                if (address.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    attempSocket = state.Socket6;
                }
                else if (address.AddressFamily == AddressFamily.InterNetwork)
                {
                    attempSocket = state.Socket4;
                }
            }

            state.NextAddressIndex = currentIndex;
            return(address);
        }
        static partial void CreateAttempSocket(DnsConnectState connectState)
        {
            if (Socket.OSSupportsIPv6)
                connectState.Socket6 = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);

            connectState.Socket4 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        }
        private static IPAddress GetNextAddress(DnsConnectState state, out Socket attempSocket)
        {
            IPAddress address = null;
            attempSocket = null;

            var currentIndex = state.NextAddressIndex;

            while(attempSocket == null)
            {
                if (currentIndex >= state.Addresses.Length)
                    return null;

                address = state.Addresses[currentIndex++];

                if (address.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    attempSocket = state.Socket6;
                }
                else if (address.AddressFamily == AddressFamily.InterNetwork)
                {
                    attempSocket = state.Socket4;
                }
            }

            state.NextAddressIndex = currentIndex;
            return address;
        }
        private static void SocketConnectCompleted(object sender, SocketAsyncEventArgs e)
        {
            DnsConnectState dnsConnectState = e.UserToken as DnsConnectState;

            if (e.SocketError == SocketError.Success)
            {
                ClearSocketAsyncEventArgs(e);
                dnsConnectState.Callback((Socket)sender, dnsConnectState.State, e, null);
                return;
            }
            if (e.SocketError != SocketError.HostUnreachable && e.SocketError != SocketError.ConnectionRefused)
            {
                ClearSocketAsyncEventArgs(e);
                dnsConnectState.Callback(null, dnsConnectState.State, e, null);
                return;
            }
            Socket    attempSocket;
            IPAddress nextAddress = GetNextAddress(dnsConnectState, out attempSocket);

            if (nextAddress == null)
            {
                ClearSocketAsyncEventArgs(e);
                e.SocketError = SocketError.HostUnreachable;
                dnsConnectState.Callback(null, dnsConnectState.State, e, null);
                return;
            }
            e.RemoteEndPoint = new IPEndPoint(nextAddress, dnsConnectState.Port);
            if (!attempSocket.ConnectAsync(e))
            {
                SocketConnectCompleted(attempSocket, e);
            }
        }
Ejemplo n.º 5
0
        private static IPAddress GetNextAddress(DnsConnectState state, out Socket attempSocket)
        {
            IPAddress iPAddress = null;

            attempSocket = null;
            int num = state.NextAddressIndex;

            while (attempSocket == null)
            {
                if (num >= state.Addresses.Length)
                {
                    return(null);
                }
                iPAddress = state.Addresses[num++];
                if (iPAddress.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    attempSocket = state.Socket6;
                }
                else if (iPAddress.AddressFamily == AddressFamily.InterNetwork)
                {
                    attempSocket = state.Socket4;
                }
            }
            state.NextAddressIndex = num;
            return(iPAddress);
        }
 private static void CreateAttempSocket(DnsConnectState connectState)
 {
     if (Socket.OSSupportsIPv6)
     {
         connectState.Socket6 = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
     }
     connectState.Socket4 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 }
        private static void OnGetHostAddresses(IAsyncResult result)
        {
            DnsConnectState dnsConnectState = result.AsyncState as 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;
            CreateAttempSocket(dnsConnectState);
            Socket    attempSocket;
            IPAddress nextAddress = GetNextAddress(dnsConnectState, out attempSocket);

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

            socketAsyncEventArgs.Completed += SocketConnectCompleted;
            IPEndPoint iPEndPoint = (IPEndPoint)(socketAsyncEventArgs.RemoteEndPoint = new IPEndPoint(nextAddress, dnsConnectState.Port));

            socketAsyncEventArgs.UserToken = dnsConnectState;
            if (!attempSocket.ConnectAsync(socketAsyncEventArgs))
            {
                SocketConnectCompleted(attempSocket, socketAsyncEventArgs);
            }
        }
Ejemplo n.º 8
0
        static partial void CreateAttempSocket(DnsConnectState connectState)
        {
            bool ipv6 = false;

            try
            {
                if (Socket.OSSupportsIPv6)
                {
                    ipv6 = true;
                }
            }
            catch (Exception e)
            {
                GameSparks.Core.GameSparksUtil.LogError("Socket.OSSupportsIPv6: " + e.ToString());
            }

            try
            {
                if (Socket.SupportsIPv6)
                {
                    ipv6 = true;
                }
            }
            catch (Exception e)
            {
                GameSparks.Core.GameSparksUtil.LogError("Socket.SupportsIPv6: " + e.ToString());
            }

            if (ipv6)
            {
                try
                {
                    connectState.Socket6 = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);

                    GameSparks.Core.GameSparksUtil.Log("IPv6 on!");
                }
                catch (Exception e)
                {
                    GameSparks.Core.GameSparksUtil.LogError(e.ToString());
                }
            }

            connectState.Socket4 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        }
Ejemplo n.º 9
0
 static partial void CreateAttempSocket(DnsConnectState connectState);
 static partial void CreateAttempSocket(DnsConnectState connectState)
 {
     connectState.Socket4 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 }
 static partial void CreateAttempSocket(DnsConnectState connectState);