HttpServer.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using BeetleX;
  2. using BeetleX.EventArgs;
  3. using Microsoft.Extensions.Hosting;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. namespace PlatformBenchmarks
  10. {
  11. public class HttpServer : IHostedService
  12. {
  13. private IServer mApiServer;
  14. public virtual Task StartAsync(CancellationToken cancellationToken)
  15. {
  16. ArraySegment<byte> date = GMTDate.Default.DATE;
  17. ServerOptions serverOptions = new ServerOptions();
  18. serverOptions.LogLevel = LogType.Error;
  19. serverOptions.DefaultListen.Port = 8080;
  20. serverOptions.Statistical = false;
  21. serverOptions.PrivateBufferPool = true;
  22. serverOptions.BufferSize = 1024 * 4;
  23. serverOptions.PrivateBufferPool = true;
  24. serverOptions.MaxConnections = 100000;
  25. serverOptions.BufferPoolMaxMemory = 500;
  26. mApiServer = SocketFactory.CreateTcpServer<HttpHandler>(serverOptions);
  27. mApiServer.Open();
  28. return Task.CompletedTask;
  29. }
  30. public virtual Task StopAsync(CancellationToken cancellationToken)
  31. {
  32. mApiServer.Dispose();
  33. return Task.CompletedTask;
  34. }
  35. }
  36. }