123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Configuration;
- using System.Linq;
- using System.Security.Authentication;
- using System.Text;
- using SuperSocket.Common;
- namespace SuperSocket.SocketBase.Config
- {
- /// <summary>
- /// Server configruation model
- /// </summary>
- [Serializable]
- public partial class ServerConfig : IServerConfig
- {
- /// <summary>
- /// Default ReceiveBufferSize
- /// </summary>
- public const int DefaultReceiveBufferSize = 4096;
- /// <summary>
- /// Default MaxConnectionNumber
- /// </summary>
- public const int DefaultMaxConnectionNumber = 10000;
- /// <summary>
- /// Default sending queue size
- /// </summary>
- public const int DefaultSendingQueueSize = 5;
- /// <summary>
- /// Default MaxRequestLength
- /// </summary>
- public const int DefaultMaxRequestLength = 1024;
- /// <summary>
- /// Default send timeout value, in milliseconds
- /// </summary>
- public const int DefaultSendTimeout = 5000;
- /// <summary>
- /// Default clear idle session interval
- /// </summary>
- public const int DefaultClearIdleSessionInterval = 120;
- /// <summary>
- /// Default idle session timeout
- /// </summary>
- public const int DefaultIdleSessionTimeOut = 300;
- /// <summary>
- /// The default send buffer size
- /// </summary>
- public const int DefaultSendBufferSize = 2048;
- /// <summary>
- /// The default session snapshot interval
- /// </summary>
- public const int DefaultSessionSnapshotInterval = 5;
- /// <summary>
- /// The default keep alive time
- /// </summary>
- public const int DefaultKeepAliveTime = 600; // 60 * 10 = 10 minutes
- /// <summary>
- /// The default keep alive interval
- /// </summary>
- public const int DefaultKeepAliveInterval = 60; // 60 seconds
- /// <summary>
- /// The default listen backlog
- /// </summary>
- public const int DefaultListenBacklog = 100;
- /// <summary>
- /// Initializes a new instance of the <see cref="ServerConfig"/> class.
- /// </summary>
- /// <param name="serverConfig">The server config.</param>
- public ServerConfig(IServerConfig serverConfig)
- {
- serverConfig.CopyPropertiesTo(this);
-
- this.Options = serverConfig.Options;
- this.OptionElements = serverConfig.OptionElements;
- if (serverConfig.Certificate != null)
- this.Certificate = serverConfig.Certificate.CopyPropertiesTo(new CertificateConfig());
- if (serverConfig.Listeners != null && serverConfig.Listeners.Any())
- {
- this.Listeners = serverConfig.Listeners.Select(l => l.CopyPropertiesTo(new ListenerConfig())).OfType<ListenerConfig>().ToArray();
- }
- if (serverConfig.CommandAssemblies != null && serverConfig.CommandAssemblies.Any())
- {
- this.CommandAssemblies = serverConfig.CommandAssemblies.Select(c => c.CopyPropertiesTo(new CommandAssemblyConfig())).OfType<CommandAssemblyConfig>().ToArray();
- }
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="ServerConfig"/> class.
- /// </summary>
- public ServerConfig()
- {
- Security = "None";
- MaxConnectionNumber = DefaultMaxConnectionNumber;
- Mode = SocketMode.Tcp;
- MaxRequestLength = DefaultMaxRequestLength;
- KeepAliveTime = DefaultKeepAliveTime;
- KeepAliveInterval = DefaultKeepAliveInterval;
- ListenBacklog = DefaultListenBacklog;
- ReceiveBufferSize = DefaultReceiveBufferSize;
- SendingQueueSize = DefaultSendingQueueSize;
- SendTimeOut = DefaultSendTimeout;
- ClearIdleSessionInterval = DefaultClearIdleSessionInterval;
- IdleSessionTimeOut = DefaultIdleSessionTimeOut;
- SendBufferSize = DefaultSendBufferSize;
- LogBasicSessionActivity = true;
- SessionSnapshotInterval = DefaultSessionSnapshotInterval;
- }
- #region IServerConfig Members
- /// <summary>
- /// Gets/sets the name of the server type of this appServer want to use.
- /// </summary>
- /// <value>
- /// The name of the server type.
- /// </value>
- public string ServerTypeName { get; set; }
- /// <summary>
- /// Gets/sets the type definition of the appserver.
- /// </summary>
- /// <value>
- /// The type of the server.
- /// </value>
- public string ServerType { get; set; }
- /// <summary>
- /// Gets/sets the Receive filter factory.
- /// </summary>
- public string ReceiveFilterFactory { get; set; }
- /// <summary>
- /// Gets/sets the ip.
- /// </summary>
- public string Ip { get; set; }
- /// <summary>
- /// Gets/sets the port.
- /// </summary>
- public int Port { get; set; }
- /// <summary>
- /// Gets/sets the options.
- /// </summary>
- [HotUpdate]
- public NameValueCollection Options { get; set; }
- /// <summary>
- /// Gets the option elements.
- /// </summary>
- [HotUpdate]
- public NameValueCollection OptionElements { get; set; }
- /// <summary>
- /// Gets/sets a value indicating whether this <see cref="IServerConfig"/> is disabled.
- /// </summary>
- /// <value>
- /// <c>true</c> if disabled; otherwise, <c>false</c>.
- /// </value>
- public bool Disabled { get; set; }
- /// <summary>
- /// Gets the name.
- /// </summary>
- public string Name { get; set; }
- /// <summary>
- /// Gets/sets the mode.
- /// </summary>
- public SocketMode Mode { get; set; }
- /// <summary>
- /// Gets/sets the send time out.
- /// </summary>
- public int SendTimeOut { get; set; }
- /// <summary>
- /// Gets the max connection number.
- /// </summary>
- public int MaxConnectionNumber { get; set; }
- /// <summary>
- /// Gets the size of the receive buffer.
- /// </summary>
- /// <value>
- /// The size of the receive buffer.
- /// </value>
- public int ReceiveBufferSize { get; set; }
- /// <summary>
- /// Gets the size of the send buffer.
- /// </summary>
- /// <value>
- /// The size of the send buffer.
- /// </value>
- public int SendBufferSize { get; set; }
- /// <summary>
- /// Gets a value indicating whether sending is in synchronous mode.
- /// </summary>
- /// <value>
- /// <c>true</c> if [sync send]; otherwise, <c>false</c>.
- /// </value>
- public bool SyncSend { get; set; }
- /// <summary>
- /// Gets/sets a value indicating whether log command in log file.
- /// </summary>
- /// <value>
- /// <c>true</c> if log command; otherwise, <c>false</c>.
- /// </value>
- [HotUpdate]
- public bool LogCommand { get; set; }
- /// <summary>
- /// Gets/sets a value indicating whether clear idle session.
- /// </summary>
- /// <value>
- /// <c>true</c> if clear idle session; otherwise, <c>false</c>.
- /// </value>
- public bool ClearIdleSession { get; set; }
- /// <summary>
- /// Gets/sets the clear idle session interval, in seconds.
- /// </summary>
- /// <value>
- /// The clear idle session interval.
- /// </value>
- public int ClearIdleSessionInterval { get; set; }
- /// <summary>
- /// Gets/sets the idle session timeout time length, in seconds.
- /// </summary>
- /// <value>
- /// The idle session time out.
- /// </value>
- [HotUpdate]
- public int IdleSessionTimeOut { get; set; }
- /// <summary>
- /// Gets/sets X509Certificate configuration.
- /// </summary>
- /// <value>
- /// X509Certificate configuration.
- /// </value>
- public ICertificateConfig Certificate { get; set; }
- /// <summary>
- /// Gets/sets the security protocol, X509 certificate.
- /// </summary>
- public string Security { get; set; }
- /// <summary>
- /// Gets/sets the length of the max request.
- /// </summary>
- /// <value>
- /// The length of the max request.
- /// </value>
- [HotUpdate]
- public int MaxRequestLength { get; set; }
- /// <summary>
- /// Gets/sets a value indicating whether [disable session snapshot].
- /// </summary>
- /// <value>
- /// <c>true</c> if [disable session snapshot]; otherwise, <c>false</c>.
- /// </value>
- public bool DisableSessionSnapshot { get; set; }
- /// <summary>
- /// Gets/sets the interval to taking snapshot for all live sessions.
- /// </summary>
- public int SessionSnapshotInterval { get; set; }
- /// <summary>
- /// Gets/sets the connection filters used by this server instance.
- /// </summary>
- /// <value>
- /// The connection filter's name list, seperated by comma
- /// </value>
- public string ConnectionFilter { get; set; }
- /// <summary>
- /// Gets the command loader, multiple values should be separated by comma.
- /// </summary>
- public string CommandLoader { get; set; }
- /// <summary>
- /// Gets/sets the start keep alive time, in seconds
- /// </summary>
- public int KeepAliveTime { get; set; }
- /// <summary>
- /// Gets/sets the keep alive interval, in seconds.
- /// </summary>
- public int KeepAliveInterval { get; set; }
- /// <summary>
- /// Gets the backlog size of socket listening.
- /// </summary>
- public int ListenBacklog { get; set; }
- /// <summary>
- /// Gets/sets the startup order of the server instance.
- /// </summary>
- public int StartupOrder { get; set; }
- /// <summary>
- /// Gets the child config.
- /// </summary>
- /// <typeparam name="TConfig">The type of the config.</typeparam>
- /// <param name="childConfigName">Name of the child config.</param>
- /// <returns></returns>
- public virtual TConfig GetChildConfig<TConfig>(string childConfigName)
- where TConfig : ConfigurationElement, new()
- {
- return this.OptionElements.GetChildConfig<TConfig>(childConfigName);
- }
- /// <summary>
- /// Gets and sets the listeners' configuration.
- /// </summary>
- public IEnumerable<IListenerConfig> Listeners { get; set; }
- /// <summary>
- /// Gets/sets the log factory name.
- /// </summary>
- public string LogFactory { get; set; }
- /// <summary>
- /// Gets/sets the size of the sending queue.
- /// </summary>
- /// <value>
- /// The size of the sending queue.
- /// </value>
- public int SendingQueueSize { get; set; }
- /// <summary>
- /// Gets a value indicating whether [log basic session activity like connected and disconnected].
- /// </summary>
- /// <value>
- /// <c>true</c> if [log basic session activity]; otherwise, <c>false</c>.
- /// </value>
- [HotUpdate]
- public bool LogBasicSessionActivity { get; set; }
- /// <summary>
- /// Gets/sets a value indicating whether [log all socket exception].
- /// </summary>
- /// <value>
- /// <c>true</c> if [log all socket exception]; otherwise, <c>false</c>.
- /// </value>
- [HotUpdate]
- public bool LogAllSocketException { get; set; }
- /// <summary>
- /// Gets/sets the default text encoding.
- /// </summary>
- /// <value>
- /// The text encoding.
- /// </value>
- public string TextEncoding { get; set; }
- /// <summary>
- /// Gets the command assemblies configuration.
- /// </summary>
- /// <value>
- /// The command assemblies.
- /// </value>
- public IEnumerable<ICommandAssemblyConfig> CommandAssemblies { get; set; }
- #endregion
- }
- }
|