This commit is contained in:
Christian Köllner 2020-04-21 22:23:08 +02:00
parent 87575f12bf
commit 4f76073ee5
3 changed files with 22 additions and 9 deletions

View File

@ -7,8 +7,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" /> <PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
<PackageReference Include="Capnp.Net.Runtime" Version="1.3.93-g73bd1de241" /> <PackageReference Include="Capnp.Net.Runtime" Version="1.3.94-g87575f12bf" />
<PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.2.138" /> <PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.3.94-g87575f12bf" />
<PackageReference Include="Google.Protobuf" Version="3.11.3" /> <PackageReference Include="Google.Protobuf" Version="3.11.3" />
<PackageReference Include="Grpc.Net.Client" Version="2.27.0" /> <PackageReference Include="Grpc.Net.Client" Version="2.27.0" />
<PackageReference Include="Grpc.Tools" Version="2.27.0"> <PackageReference Include="Grpc.Tools" Version="2.27.0">

View File

@ -6,7 +6,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Capnp.Net.Runtime" Version="1.3.93-g73bd1de241" /> <PackageReference Include="Capnp.Net.Runtime" Version="1.3.94-g87575f12bf" />
<PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.3.92-gdb2d6bce2e" /> <PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.3.92-gdb2d6bce2e" />
</ItemGroup> </ItemGroup>

View File

@ -7,15 +7,24 @@ namespace Capnp.Util
{ {
internal class AsyncNetworkStreamAdapter : Stream internal class AsyncNetworkStreamAdapter : Stream
{ {
readonly NetworkStream _stream; // Async I/O pays off for large payloads. Perf. profiling gave a threshold around 200kB
readonly object _reentrancyBlocker = new object(); const int DefaultAsyncThreshold = 200000;
//Exception? _bufferedException;
public AsyncNetworkStreamAdapter(Stream stream) readonly NetworkStream _stream;
readonly int _asyncThreshold;
readonly object _reentrancyBlocker = new object();
Exception? _bufferedException;
public AsyncNetworkStreamAdapter(Stream stream, int asyncThreshold)
{ {
_asyncThreshold = asyncThreshold;
_stream = stream as NetworkStream ?? throw new ArgumentException("stream argument must be a NetworkStream"); _stream = stream as NetworkStream ?? throw new ArgumentException("stream argument must be a NetworkStream");
} }
public AsyncNetworkStreamAdapter(Stream stream): this(stream, DefaultAsyncThreshold)
{
}
public override bool CanRead => true; public override bool CanRead => true;
public override bool CanSeek => false; public override bool CanSeek => false;
@ -32,7 +41,8 @@ namespace Capnp.Util
public override void Flush() public override void Flush()
{ {
_stream.Flush(); _stream.FlushAsync();
//_stream.Flush();
} }
public override int Read(byte[] buffer, int offset, int count) public override int Read(byte[] buffer, int offset, int count)
@ -73,7 +83,10 @@ namespace Capnp.Util
// throw exception; // throw exception;
//} //}
//_stream.BeginWrite(buffer, offset, count, WriteCallback, null); //if (count >= _asyncThreshold)
// _stream.BeginWrite(buffer, offset, count, WriteCallback, null);
//else
// _stream.Write(buffer, offset, count);
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)