using System; using System.Net.Security; using System.Net.Sockets; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using MECF.Framework.Common.Communications.Tcp.Buffer; using MECF.Framework.Common.Communications.Tcp.Socket.Framing; using MECF.Framework.Common.Communications.Tcp.Socket.Framing.Base; namespace MECF.Framework.Common.Communications.Tcp.Socket.Client.APM { public sealed class TcpSocketClientConfiguration { public TcpSocketClientConfiguration() : this(new SegmentBufferManager(100, 8192, 1, true)) { } public TcpSocketClientConfiguration(ISegmentBufferManager bufferManager) { BufferManager = bufferManager; ReceiveBufferSize = 8192; // Specifies the total per-socket buffer space reserved for receives. This is unrelated to the maximum message size or the size of a TCP window. SendBufferSize = 8192; // Specifies the total per-socket buffer space reserved for sends. This is unrelated to the maximum message size or the size of a TCP window. ReceiveTimeout = TimeSpan.Zero; // Receive a time-out. This option applies only to synchronous methods; it has no effect on asynchronous methods such as the BeginSend method. SendTimeout = TimeSpan.Zero; // Send a time-out. This option applies only to synchronous methods; it has no effect on asynchronous methods such as the BeginSend method. NoDelay = true; // Disables the Nagle algorithm for send coalescing. LingerState = new LingerOption(false, 0); // The socket will linger for x seconds after Socket.Close is called. KeepAlive = false; // Use keep-alives. KeepAliveInterval = TimeSpan.FromSeconds(5);// https://msdn.microsoft.com/en-us/library/system.net.sockets.socketoptionname(v=vs.110).aspx ReuseAddress = false; // Allows the socket to be bound to an address that is already in use. SslEnabled = false; SslTargetHost = null; SslClientCertificates = new X509CertificateCollection(); SslEncryptionPolicy = EncryptionPolicy.RequireEncryption; SslEnabledProtocols = SslProtocols.Ssl3 | SslProtocols.Tls; SslCheckCertificateRevocation = false; SslPolicyErrorsBypassed = false; ConnectTimeout = TimeSpan.FromSeconds(15); FrameBuilder = new LineBasedFrameBuilder(); } public ISegmentBufferManager BufferManager { get; set; } public int ReceiveBufferSize { get; set; } public int SendBufferSize { get; set; } public TimeSpan ReceiveTimeout { get; set; } public TimeSpan SendTimeout { get; set; } public bool NoDelay { get; set; } public LingerOption LingerState { get; set; } public bool KeepAlive { get; set; } public TimeSpan KeepAliveInterval { get; set; } public bool ReuseAddress { get; set; } public bool SslEnabled { get; set; } public string SslTargetHost { get; set; } public X509CertificateCollection SslClientCertificates { get; set; } public EncryptionPolicy SslEncryptionPolicy { get; set; } public SslProtocols SslEnabledProtocols { get; set; } public bool SslCheckCertificateRevocation { get; set; } public bool SslPolicyErrorsBypassed { get; set; } public TimeSpan ConnectTimeout { get; set; } public IFrameBuilder FrameBuilder { get; set; } } }