From 998fcbd7dc0d3542975765e5af9b973a3c1e0c6f Mon Sep 17 00:00:00 2001 From: Mirko Da Corte Date: Sun, 6 Oct 2024 18:25:03 +0200 Subject: [PATCH] add SendChunkAsync() method receiving only payload --- src/BeeNet.Core/Models/ChunkUploaderWebSocket.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/BeeNet.Core/Models/ChunkUploaderWebSocket.cs b/src/BeeNet.Core/Models/ChunkUploaderWebSocket.cs index bf4d020..67e5890 100644 --- a/src/BeeNet.Core/Models/ChunkUploaderWebSocket.cs +++ b/src/BeeNet.Core/Models/ChunkUploaderWebSocket.cs @@ -59,14 +59,12 @@ await webSocket.CloseOutputAsync( } public virtual async Task SendChunkAsync( - SwarmChunk chunk, + byte[] chunkPayload, CancellationToken cancellationToken) { - ArgumentNullException.ThrowIfNull(chunk, nameof(chunk)); - - var chunkBytes = chunk.GetSpanAndData(); + ArgumentNullException.ThrowIfNull(chunkPayload, nameof(chunkPayload)); - await webSocket.SendAsync(chunkBytes, WebSocketMessageType.Binary, true, cancellationToken).ConfigureAwait(false); + await webSocket.SendAsync(chunkPayload, WebSocketMessageType.Binary, true, cancellationToken).ConfigureAwait(false); var response = await webSocket.ReceiveAsync(responseBuffer, CancellationToken.None).ConfigureAwait(false); if (response.MessageType == WebSocketMessageType.Close) @@ -74,6 +72,14 @@ public virtual async Task SendChunkAsync( $"Connection closed by server, message: {response.CloseStatusDescription}"); } + public virtual Task SendChunkAsync( + SwarmChunk chunk, + CancellationToken cancellationToken) + { + ArgumentNullException.ThrowIfNull(chunk, nameof(chunk)); + return SendChunkAsync(chunk.GetSpanAndData(), cancellationToken); + } + public virtual async Task SendChunksAsync( SwarmChunk[] chunkBatch, CancellationToken cancellationToken = default)