TcpSocketClientConfiguration.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Net.Security;
  3. using System.Net.Sockets;
  4. using System.Security.Authentication;
  5. using System.Security.Cryptography.X509Certificates;
  6. using MECF.Framework.Common.Communications.Tcp.Buffer;
  7. using MECF.Framework.Common.Communications.Tcp.Socket.Framing;
  8. using MECF.Framework.Common.Communications.Tcp.Socket.Framing.Base;
  9. namespace MECF.Framework.Common.Communications.Tcp.Socket.Client.APM
  10. {
  11. public sealed class TcpSocketClientConfiguration
  12. {
  13. public TcpSocketClientConfiguration()
  14. : this(new SegmentBufferManager(100, 8192, 1, true))
  15. {
  16. }
  17. public TcpSocketClientConfiguration(ISegmentBufferManager bufferManager)
  18. {
  19. BufferManager = bufferManager;
  20. 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.
  21. 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.
  22. 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.
  23. 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.
  24. NoDelay = true; // Disables the Nagle algorithm for send coalescing.
  25. LingerState = new LingerOption(false, 0); // The socket will linger for x seconds after Socket.Close is called.
  26. KeepAlive = false; // Use keep-alives.
  27. KeepAliveInterval = TimeSpan.FromSeconds(5);// https://msdn.microsoft.com/en-us/library/system.net.sockets.socketoptionname(v=vs.110).aspx
  28. ReuseAddress = false; // Allows the socket to be bound to an address that is already in use.
  29. SslEnabled = false;
  30. SslTargetHost = null;
  31. SslClientCertificates = new X509CertificateCollection();
  32. SslEncryptionPolicy = EncryptionPolicy.RequireEncryption;
  33. SslEnabledProtocols = SslProtocols.Ssl3 | SslProtocols.Tls;
  34. SslCheckCertificateRevocation = false;
  35. SslPolicyErrorsBypassed = false;
  36. ConnectTimeout = TimeSpan.FromSeconds(15);
  37. FrameBuilder = new LineBasedFrameBuilder();
  38. }
  39. public ISegmentBufferManager BufferManager { get; set; }
  40. public int ReceiveBufferSize { get; set; }
  41. public int SendBufferSize { get; set; }
  42. public TimeSpan ReceiveTimeout { get; set; }
  43. public TimeSpan SendTimeout { get; set; }
  44. public bool NoDelay { get; set; }
  45. public LingerOption LingerState { get; set; }
  46. public bool KeepAlive { get; set; }
  47. public TimeSpan KeepAliveInterval { get; set; }
  48. public bool ReuseAddress { get; set; }
  49. public bool SslEnabled { get; set; }
  50. public string SslTargetHost { get; set; }
  51. public X509CertificateCollection SslClientCertificates { get; set; }
  52. public EncryptionPolicy SslEncryptionPolicy { get; set; }
  53. public SslProtocols SslEnabledProtocols { get; set; }
  54. public bool SslCheckCertificateRevocation { get; set; }
  55. public bool SslPolicyErrorsBypassed { get; set; }
  56. public TimeSpan ConnectTimeout { get; set; }
  57. public IFrameBuilder FrameBuilder { get; set; }
  58. }
  59. }