Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,7 @@ public abstract class DataPackageHandlerBase : IDataPackageHandler
/// <param name="data"></param>
/// <param name="token"></param>
/// <returns></returns>
public virtual ValueTask<ReadOnlyMemory<byte>> SendAsync(ReadOnlyMemory<byte> data, CancellationToken token = default)
{
return ValueTask.FromResult(data);
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="data"></param>
/// <param name="token"></param>
/// <returns></returns>
public virtual ValueTask ReceiveAsync(ReadOnlyMemory<byte> data, CancellationToken token = default)
{
return ValueTask.CompletedTask;
}
public abstract ValueTask ReceiveAsync(ReadOnlyMemory<byte> data, CancellationToken token = default);

/// <summary>
/// Handles the processing of a sticky package by adjusting the provided buffer and length.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ public interface IDataPackageHandler
/// </summary>
Func<ReadOnlyMemory<byte>, ValueTask>? ReceivedCallBack { get; set; }

/// <summary>
/// Sends the specified data asynchronously to the target destination.
/// </summary>
/// <remarks>The method performs an asynchronous operation to send the provided data. The caller must
/// ensure that the data is valid and non-empty. The returned memory block may contain a response or acknowledgment
/// depending on the implementation of the target destination.</remarks>
/// <param name="data">The data to be sent, represented as a block of memory.</param>
/// <param name="token">An optional <see cref="CancellationToken"/> to observe while waiting for the operation to complete.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a <see cref="Memory{T}"/> of <see
/// cref="byte"/> representing the response or acknowledgment received from the target destination.</returns>
ValueTask<ReadOnlyMemory<byte>> SendAsync(ReadOnlyMemory<byte> data, CancellationToken token = default);

/// <summary>
/// Asynchronously receives data and processes it.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async ValueTask<bool> ConnectAsync(IPEndPoint endPoint, CancellationToken
public async ValueTask<bool> SendAsync(ReadOnlyMemory<byte> data, CancellationToken token = default)
{
var ret = false;
if (_client is { Connected: true })
if (_client != null)
{
var stream = _client.GetStream();
await stream.WriteAsync(data, token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ public virtual async ValueTask<Memory<byte>> ReceiveAsync(CancellationToken toke

private async ValueTask AutoReceiveAsync()
{
// 自动接收方法
_receiveCancellationTokenSource ??= new();
while (_receiveCancellationTokenSource is { IsCancellationRequested: false })
while (true)
{
if (SocketClientProvider is not { IsConnected: true })
{
Expand All @@ -197,6 +198,7 @@ private async ValueTask AutoReceiveAsync()
var len = await ReceiveCoreAsync(SocketClientProvider, buffer, _receiveCancellationTokenSource.Token);
if (len == 0)
{
// 远端关闭或者 DisposeAsync 方法被调用时退出
break;
}
}
Expand Down
Loading
Loading