Skip to content

Commit

Permalink
add SendChunkAsync() method receiving only payload
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Oct 6, 2024
1 parent 0db916c commit 998fcbd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/BeeNet.Core/Models/ChunkUploaderWebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,27 @@ 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)
throw new OperationCanceledException(
$"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)
Expand Down

0 comments on commit 998fcbd

Please sign in to comment.