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