public void KeepAliveInterval_get_and_set_work(uint value)
        {
            var subject = new KeepAliveValues();

            subject.KeepAliveInterval = value;
            var result = subject.KeepAliveInterval;

            result.Should().Be(value);
        }
        public void OnOff_get_and_set_work(uint value)
        {
            var subject = new KeepAliveValues();

            subject.OnOff = value;
            var result = subject.OnOff;

            result.Should().Be(value);
        }
Ejemplo n.º 3
0
        public void KeepAliveTime_get_and_set_work(ulong value)
        {
            var subject = new KeepAliveValues();

            subject.KeepAliveTime = value;
            var result = subject.KeepAliveTime;

            result.Should().Be(value);
        }
        public void ToBytes_should_return_expected_result(uint onOff, uint keepAliveTime, uint keepAliveInterval, byte[] expectedResult)
        {
            var subject = new KeepAliveValues
            {
                OnOff             = onOff,
                KeepAliveTime     = keepAliveTime,
                KeepAliveInterval = keepAliveInterval
            };

            var result = subject.ToBytes();

            result.Should().Equal(expectedResult);
        }
        private Socket CreateSocket(EndPoint endPoint)
        {
            var addressFamily = endPoint.AddressFamily;

            if (addressFamily == AddressFamily.Unspecified || addressFamily == AddressFamily.Unknown)
            {
                addressFamily = _settings.AddressFamily;
            }

            var socket          = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp);
            var keepAliveValues = new KeepAliveValues
            {
                OnOff             = 1,
                KeepAliveTime     = 300000, // 300 seconds in milliseconds
                KeepAliveInterval = 10000   // 10 seconds in milliseconds
            };

            socket.IOControl(IOControlCode.KeepAliveValues, keepAliveValues.ToBytes(), null);

            return(socket);
        }
        private Socket CreateSocket(EndPoint endPoint)
        {
            var addressFamily = endPoint.AddressFamily;

            if (addressFamily == AddressFamily.Unspecified || addressFamily == AddressFamily.Unknown)
            {
                addressFamily = _settings.AddressFamily;
            }

            var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp);

            // not all platforms support IOControl
            try
            {
                var keepAliveValues = new KeepAliveValues
                {
                    OnOff             = 1,
                    KeepAliveTime     = 300000, // 300 seconds in milliseconds
                    KeepAliveInterval = 10000   // 10 seconds in milliseconds
                };
                socket.IOControl(IOControlCode.KeepAliveValues, keepAliveValues.ToBytes(), null);
            }
            catch (PlatformNotSupportedException)
            {
                // most platforms should support this call to SetSocketOption, but just in case call it in a try/catch also
                try
                {
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                }
                catch (PlatformNotSupportedException)
                {
                    // ignore PlatformNotSupportedException
                }
            }

            return(socket);
        }