From c813852691545ca51f3164638b1145b37f8b217f Mon Sep 17 00:00:00 2001 From: Cristian Pufu Date: Mon, 28 Oct 2024 21:51:48 +0200 Subject: [PATCH] Reduce buffer size to 16kb --- src/Tunnelite.Client/Tunnelite.Client.csproj | 2 +- src/Tunnelite.Sdk/TcpTunnel/TcpTunnelClient.cs | 2 +- src/Tunnelite.Server/TcpTunnel/TcpTunnelHub.cs | 5 +++-- test/Test.TcpClient/instructions.txt | 3 +++ 4 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 test/Test.TcpClient/instructions.txt diff --git a/src/Tunnelite.Client/Tunnelite.Client.csproj b/src/Tunnelite.Client/Tunnelite.Client.csproj index e7e7c6b..34134ac 100644 --- a/src/Tunnelite.Client/Tunnelite.Client.csproj +++ b/src/Tunnelite.Client/Tunnelite.Client.csproj @@ -16,7 +16,7 @@ Tool for tunneling URLs https://github.com/cristipufu/ws-tunnel-signalr https://github.com/cristipufu/ws-tunnel-signalr - 1.1.6 + 1.1.7 true diff --git a/src/Tunnelite.Sdk/TcpTunnel/TcpTunnelClient.cs b/src/Tunnelite.Sdk/TcpTunnel/TcpTunnelClient.cs index 5d9dbb7..099510b 100644 --- a/src/Tunnelite.Sdk/TcpTunnel/TcpTunnelClient.cs +++ b/src/Tunnelite.Sdk/TcpTunnel/TcpTunnelClient.cs @@ -180,7 +180,7 @@ private async Task StreamOutgoingAsync(TcpClient localClient, TcpConnection tcpC private async IAsyncEnumerable> StreamLocalTcpAsync(TcpClient localClient, TcpConnection tcpConnection, [EnumeratorCancellation] CancellationToken cancellationToken) { - const int chunkSize = 32 * 1024; + const int chunkSize = 16 * 1024; byte[] buffer = ArrayPool.Shared.Rent(chunkSize); diff --git a/src/Tunnelite.Server/TcpTunnel/TcpTunnelHub.cs b/src/Tunnelite.Server/TcpTunnel/TcpTunnelHub.cs index 8bf4e4f..e67f5bf 100644 --- a/src/Tunnelite.Server/TcpTunnel/TcpTunnelHub.cs +++ b/src/Tunnelite.Server/TcpTunnel/TcpTunnelHub.cs @@ -71,15 +71,16 @@ public async IAsyncEnumerable> StreamIncomingAsync(TcpConne yield break; } - const int chunkSize = 32 * 1024; + const int chunkSize = 16 * 1024; byte[] buffer = ArrayPool.Shared.Rent(chunkSize); + int bytesRead; + try { var stream = tcpClient.GetStream(); - int bytesRead; while (!Context.ConnectionAborted.IsCancellationRequested && (bytesRead = await stream.ReadAsync(buffer, Context.ConnectionAborted)) > 0) diff --git a/test/Test.TcpClient/instructions.txt b/test/Test.TcpClient/instructions.txt new file mode 100644 index 0000000..9715dd0 --- /dev/null +++ b/test/Test.TcpClient/instructions.txt @@ -0,0 +1,3 @@ +.\Test.TcpServer.exe 5000 file.mp4 +.\Test.TcpClient.exe localhost 62340 "files" +.\Tunnelite.Client.exe tcp://localhost:5000 --publicUrl https://localhost:7193/ --log Debug \ No newline at end of file