/// <summary> /// Creates an asynchronous HTTP host. /// </summary> /// <param name="handler">Handler to serve requests with</param> /// <param name="accepts"> /// Higher values mean more connections can be maintained yet at a much slower average response time; fewer connections will be rejected. /// Lower values mean less connections can be maintained yet at a much faster average response time; more connections will be rejected. /// </param> public HttpAsyncHost(IHttpAsyncHandler handler, int accepts = 4) { _handler = handler ?? NullHttpAsyncHandler.Default; _listener = new HttpListener(); // Multiply by number of cores: _accepts = accepts * Environment.ProcessorCount; log_timer = new Timer(WriteLog, null, 300000, 300000); HttpCdnAddress = new HttpCDNAddress(); }
/// <summary> /// /// </summary> protected GameSocketHost(RequestHandler requestHandler) { _setting = GameEnvironment.Setting; int port = _setting != null ? _setting.GamePort : 0; IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, port); var section = GetSection(); int maxConnections = section.SocketMaxConnection; int backlog = section.SocketBacklog; int maxAcceptOps = section.SocketMaxAcceptOps; int bufferSize = section.SocketBufferSize; int expireInterval = section.SocketExpireInterval; int expireTime = section.SocketExpireTime; //threadPool = new SmartThreadPool(180 * 1000, 100, 5); //threadPool.Start(); var socketSettings = new SocketSettings(maxConnections, backlog, maxAcceptOps, bufferSize, localEndPoint, expireInterval, expireTime); socketListener = new SocketListener(socketSettings, requestHandler); socketListener.DataReceived += new ConnectionEventHandler(socketLintener_DataReceived); socketListener.Connected += new ConnectionEventHandler(socketLintener_OnConnectCompleted); socketListener.Disconnected += new ConnectionEventHandler(socketLintener_Disconnected); _httpCdnAddress = new HttpCDNAddress(); httpListener = new HttpListener(); var httpHost = section.HttpHost; var httpPort = section.HttpPort; var httpName = section.HttpName; if (!string.IsNullOrEmpty(httpHost)) { EnableHttp = true; var hosts = httpHost.Split(','); foreach (var point in hosts) { var addressList = point.Split(':'); string host = addressList[0]; int hport = httpPort; if (addressList.Length > 1) { int.TryParse(addressList[1], out hport); } string address = host.StartsWith("http", StringComparison.InvariantCultureIgnoreCase) ? host : "http://" + host; httpListener.Prefixes.Add(string.Format("{0}:{1}/{2}/", address, hport, httpName)); } } }