-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathClientHandler.cs
More file actions
44 lines (37 loc) · 1.14 KB
/
ClientHandler.cs
File metadata and controls
44 lines (37 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using GenHTTP.Engine.Rocket.Infrastructure;
using Microsoft.Extensions.ObjectPool;
namespace GenHTTP.Engine.Rocket.Protocol;
internal sealed class ClientHandler
{
private static readonly DefaultObjectPool<ClientContext> ContextPool = new(new ClientContextPolicy(), 1024 * 64);
private readonly RocketServer _server;
public ClientHandler(RocketServer server)
{
_server = server;
}
public async Task RunAsync(CancellationToken cancellationToken = default)
{
try
{
while (_server.Engine.ServerRunning)
{
var conn = await _server.Engine.AcceptAsync(cancellationToken);
if(conn is null)
continue;
Console.WriteLine($"Connection: {conn.ClientFd}");
}
}
catch (OperationCanceledException)
{
Console.WriteLine("Signaled to stop");
}
catch (Exception e)
{
Console.WriteLine($"[Cowabunga!] {e.Message}");
}
finally
{
_server.Engine.Stop();
}
}
}