private void SetupBasic(IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory) { if (rootConfig == null) { throw new ArgumentNullException("rootConfig"); } RootConfig = rootConfig; if (config == null) { throw new ArgumentNullException("config"); } if (!string.IsNullOrEmpty(config.Name)) { m_Name = config.Name; } else { m_Name = string.Format("{0}-{1}", this.GetType().Name, Math.Abs(this.GetHashCode())); } Config = config; SetDefaultCulture(rootConfig, config); if (!m_ThreadPoolConfigured) { if (!TheadPoolEx.ResetThreadPool(rootConfig.MaxWorkingThreads >= 0 ? rootConfig.MaxWorkingThreads : new Nullable <int>(), rootConfig.MaxCompletionPortThreads >= 0 ? rootConfig.MaxCompletionPortThreads : new Nullable <int>(), rootConfig.MinWorkingThreads >= 0 ? rootConfig.MinWorkingThreads : new Nullable <int>(), rootConfig.MinCompletionPortThreads >= 0 ? rootConfig.MinCompletionPortThreads : new Nullable <int>())) { throw new Exception("Failed to configure thread pool!"); } m_ThreadPoolConfigured = true; } if (socketServerFactory == null) { var socketServerFactoryType = Type.GetType("SuperSocket.SocketEngine.SocketServerFactory, SuperSocket.SocketEngine", true); socketServerFactory = (ISocketServerFactory)Activator.CreateInstance(socketServerFactoryType); } m_SocketServerFactory = socketServerFactory; //Read text encoding from the configuration if (!string.IsNullOrEmpty(config.TextEncoding)) { TextEncoding = Encoding.GetEncoding(config.TextEncoding); } else { TextEncoding = new ASCIIEncoding(); } }
public virtual bool Setup(IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory, ICustomProtocol <TCommandInfo> protocol) { if (rootConfig == null) { throw new ArgumentNullException("rootConfig"); } RootConfig = rootConfig; if (!m_ThreadPoolConfigured) { if (!TheadPoolEx.ResetThreadPool(rootConfig.MaxWorkingThreads >= 0 ? rootConfig.MaxWorkingThreads : new Nullable <int>(), rootConfig.MaxCompletionPortThreads >= 0 ? rootConfig.MaxCompletionPortThreads : new Nullable <int>(), rootConfig.MinWorkingThreads >= 0 ? rootConfig.MinWorkingThreads : new Nullable <int>(), rootConfig.MinCompletionPortThreads >= 0 ? rootConfig.MinCompletionPortThreads : new Nullable <int>())) { return(false); } m_ThreadPoolConfigured = true; } if (config == null) { throw new ArgumentNullException("config"); } Config = config; Name = config.Name; m_LogCommand = config.LogCommand; m_SocketServerFactory = socketServerFactory; SetupLogger(); if (!SetupLocalEndpoint(config)) { Logger.LogError("Invalid config ip/port"); return(false); } if (!SetupProtocol(config, protocol)) { return(false); } if (!SetupCommands(m_CommandDict)) { return(false); } if (!SetupSecurity(config)) { return(false); } return(SetupSocketServer()); }
private void SetupBasic(IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory) { if (rootConfig == null) { throw new ArgumentNullException("rootConfig"); } RootConfig = rootConfig; if (config == null) { throw new ArgumentNullException("config"); } Config = config; if (!m_ThreadPoolConfigured) { if (!TheadPoolEx.ResetThreadPool(rootConfig.MaxWorkingThreads >= 0 ? rootConfig.MaxWorkingThreads : new Nullable <int>(), rootConfig.MaxCompletionPortThreads >= 0 ? rootConfig.MaxCompletionPortThreads : new Nullable <int>(), rootConfig.MinWorkingThreads >= 0 ? rootConfig.MinWorkingThreads : new Nullable <int>(), rootConfig.MinCompletionPortThreads >= 0 ? rootConfig.MinCompletionPortThreads : new Nullable <int>())) { throw new Exception("Failed to configure thread pool!"); } m_ThreadPoolConfigured = true; } if (socketServerFactory == null) { throw new ArgumentNullException("socketServerFactory"); } m_SocketServerFactory = socketServerFactory; }
/// <summary> /// Setups the appServer instance /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="config">The socket server instance config.</param> /// <param name="socketServerFactory">The socket server factory.</param> /// <param name="requestFilterFactory">The request filter factory.</param> /// <returns></returns> protected virtual bool Setup(IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory, IRequestFilterFactory <TRequestInfo> requestFilterFactory) { if (rootConfig == null) { throw new ArgumentNullException("rootConfig"); } RootConfig = rootConfig; if (!m_ThreadPoolConfigured) { if (!TheadPoolEx.ResetThreadPool(rootConfig.MaxWorkingThreads >= 0 ? rootConfig.MaxWorkingThreads : new Nullable <int>(), rootConfig.MaxCompletionPortThreads >= 0 ? rootConfig.MaxCompletionPortThreads : new Nullable <int>(), rootConfig.MinWorkingThreads >= 0 ? rootConfig.MinWorkingThreads : new Nullable <int>(), rootConfig.MinCompletionPortThreads >= 0 ? rootConfig.MinCompletionPortThreads : new Nullable <int>())) { return(false); } m_ThreadPoolConfigured = true; } if (config == null) { throw new ArgumentNullException("config"); } if (!(config is ServerConfig)) { //Use config plain model directly to avoid extra object casting in runtime var newConfig = new ServerConfig(); config.CopyPropertiesTo(newConfig); config = newConfig; } Config = config; m_SocketServerFactory = socketServerFactory; SetupLogger(); if (!SetupSecurity(config)) { return(false); } if (!SetupListeners(config)) { if (Logger.IsErrorEnabled) { Logger.Error("Invalid config ip/port"); } return(false); } if (!SetupRequestFilterFactory(config, requestFilterFactory)) { return(false); } m_CommandLoaders = new List <ICommandLoader> { new ReflectCommandLoader() }; if (Config.EnableDynamicCommand) { ICommandLoader dynamicCommandLoader; try { dynamicCommandLoader = AssemblyUtil.CreateInstance <ICommandLoader>("SuperSocket.Dlr.DynamicCommandLoader, SuperSocket.Dlr"); } catch (Exception e) { if (Logger.IsErrorEnabled) { Logger.Error("The file SuperSocket.Dlr is required for dynamic command support!", e); } return(false); } m_CommandLoaders.Add(dynamicCommandLoader); } if (!SetupCommands(m_CommandDict)) { return(false); } return(SetupSocketServer()); }