Skip to content

Commit

Permalink
refactor: remove unsed argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ArachisH committed Mar 7, 2024
1 parent 0922170 commit 6ca55f9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Tanji.Core/Network/HConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,27 @@ private static async ValueTask<Socket> ConnectAsync(EndPoint remoteEndPoint, Can
}
return socket;
}
private static async Task WeldNodesAsync(HNode source, HNode destination, bool isOutbound, CancellationToken cancellationToken = default)
{
while (source.IsConnected && destination.IsConnected && !cancellationToken.IsCancellationRequested)
{
// Do not dispose 'bufferWriter' here, instead, dispose of it within the 'TransferPacketAsync' method
var bufferWriter = new ArrayPoolBufferWriter<byte>(source.ReceivePacketFormat.MinBufferSize);
_ = await source.ReceivePacketAsync(bufferWriter, cancellationToken).ConfigureAwait(false);

// Continuously attempt to receive packets from the node
_ = TransferPacketAsync(destination, bufferWriter, cancellationToken);
}
}
private static async Task TransferPacketAsync(HNode destination, ArrayPoolBufferWriter<byte> bufferWriter, CancellationToken cancellationToken = default)
{
try
{
if (bufferWriter.WrittenCount == 0) return;
Memory<byte> mutableBuffer = bufferWriter.DangerousGetArray();

await destination.SendPacketAsync(mutableBuffer, cancellationToken).ConfigureAwait(false);
}
finally { bufferWriter.Dispose(); }
}
}

0 comments on commit 6ca55f9

Please sign in to comment.