-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
新增两个 send 方法 #599
base: master
Are you sure you want to change the base?
新增两个 send 方法 #599
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,10 @@ public abstract class ChannelBase<TPackageInfo> : IChannel<TPackageInfo>, IChann | |
|
||
public abstract ValueTask SendAsync(Action<PipeWriter> write); | ||
|
||
public abstract ValueTask<int> Send(ReadOnlyMemory<byte> buffer); | ||
|
||
public abstract ValueTask<int> Send<TPackage>(IPackageEncoder<TPackage> packageEncoder, TPackage package); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Send => SendAsync? |
||
|
||
public bool IsClosed { get; private set; } | ||
|
||
public EndPoint RemoteEndPoint { get; protected set; } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,11 @@ public interface IChannel | |
|
||
ValueTask SendAsync(Action<PipeWriter> write); | ||
|
||
ValueTask<int> Send(ReadOnlyMemory<byte> data); | ||
|
||
ValueTask<int> Send<TPackage>(IPackageEncoder<TPackage> packageEncoder, TPackage package); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line?> |
||
ValueTask CloseAsync(CloseReason closeReason); | ||
|
||
event EventHandler<CloseEventArgs> Closed; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,6 +358,20 @@ public override async ValueTask SendAsync(Action<PipeWriter> write) | |
} | ||
} | ||
|
||
public override async ValueTask<int> Send(ReadOnlyMemory<byte> buffer) | ||
{ | ||
return await SendOverIOAsync(new ReadOnlySequence<byte>(buffer), CancellationToken.None); | ||
} | ||
|
||
public override async ValueTask<int> Send<TPackage>(IPackageEncoder<TPackage> packageEncoder, TPackage package) | ||
{ | ||
ArrayBufferWriter<byte> arrayBufferWriter = new ArrayBufferWriter<byte>(); | ||
|
||
WritePackageWithEncoder(arrayBufferWriter, packageEncoder, package); | ||
|
||
return await SendOverIOAsync(new ReadOnlySequence<byte>(arrayBufferWriter.WrittenMemory), CancellationToken.None); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra space. |
||
} | ||
|
||
protected void WritePackageWithEncoder<TPackage>(IBufferWriter<byte> writer, IPackageEncoder<TPackage> packageEncoder, TPackage package) | ||
{ | ||
CheckChannelOpen(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Send => SendAsync?