mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-13 07:11:44 +01:00
removed async. stream adapter - no benefit
This commit is contained in:
parent
4f76073ee5
commit
3ef9a60a7f
@ -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.94-g87575f12bf" />
|
<PackageReference Include="Capnp.Net.Runtime" Version="1.3.95-g4f76073ee5" />
|
||||||
<PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.3.94-g87575f12bf" />
|
<PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.3.95-g4f76073ee5" />
|
||||||
<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">
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Capnp.Net.Runtime" Version="1.3.94-g87575f12bf" />
|
<PackageReference Include="Capnp.Net.Runtime" Version="1.3.95-g4f76073ee5" />
|
||||||
<PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.3.92-gdb2d6bce2e" />
|
<PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.3.95-g4f76073ee5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -17,7 +17,7 @@ namespace Capnp.Rpc
|
|||||||
/// <param name="bufferSize">Buffer size (bytes). You should choose it according to the maximum expected raw capnp frame size</param>
|
/// <param name="bufferSize">Buffer size (bytes). You should choose it according to the maximum expected raw capnp frame size</param>
|
||||||
public static void AddBuffering(this ISupportsMidlayers obj, int bufferSize)
|
public static void AddBuffering(this ISupportsMidlayers obj, int bufferSize)
|
||||||
{
|
{
|
||||||
obj.InjectMidlayer(s => new Util.DuplexBufferedStream(new Util.AsyncNetworkStreamAdapter(s), bufferSize));
|
obj.InjectMidlayer(s => new Util.DuplexBufferedStream(s, bufferSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -27,7 +27,7 @@ namespace Capnp.Rpc
|
|||||||
/// <param name="obj"><see cref="TcpRpcServer"/> or <see cref="TcpRpcClient"/></param>
|
/// <param name="obj"><see cref="TcpRpcServer"/> or <see cref="TcpRpcClient"/></param>
|
||||||
public static void AddBuffering(this ISupportsMidlayers obj)
|
public static void AddBuffering(this ISupportsMidlayers obj)
|
||||||
{
|
{
|
||||||
obj.InjectMidlayer(s => new Util.DuplexBufferedStream(new Util.AsyncNetworkStreamAdapter(s)));
|
obj.InjectMidlayer(s => new Util.DuplexBufferedStream(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,111 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace Capnp.Util
|
|
||||||
{
|
|
||||||
internal class AsyncNetworkStreamAdapter : Stream
|
|
||||||
{
|
|
||||||
// Async I/O pays off for large payloads. Perf. profiling gave a threshold around 200kB
|
|
||||||
const int DefaultAsyncThreshold = 200000;
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
public AsyncNetworkStreamAdapter(Stream stream): this(stream, DefaultAsyncThreshold)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool CanRead => true;
|
|
||||||
|
|
||||||
public override bool CanSeek => false;
|
|
||||||
|
|
||||||
public override bool CanWrite => true;
|
|
||||||
|
|
||||||
public override long Length => 0;
|
|
||||||
|
|
||||||
public override long Position
|
|
||||||
{
|
|
||||||
get => 0;
|
|
||||||
set => throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Flush()
|
|
||||||
{
|
|
||||||
_stream.FlushAsync();
|
|
||||||
//_stream.Flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Read(byte[] buffer, int offset, int count)
|
|
||||||
{
|
|
||||||
return _stream.Read(buffer, offset, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override long Seek(long offset, SeekOrigin origin)
|
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SetLength(long value)
|
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
//void WriteCallback(IAsyncResult ar)
|
|
||||||
//{
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// _stream.EndWrite(ar);
|
|
||||||
// }
|
|
||||||
// catch (Exception exception)
|
|
||||||
// {
|
|
||||||
// Volatile.Write(ref _bufferedException, exception);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
public override void Write(byte[] buffer, int offset, int count)
|
|
||||||
{
|
|
||||||
_stream.WriteAsync(buffer, offset, count);
|
|
||||||
//var exception = Volatile.Read(ref _bufferedException);
|
|
||||||
|
|
||||||
//if (exception != null)
|
|
||||||
//{
|
|
||||||
// Dispose();
|
|
||||||
// throw exception;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//if (count >= _asyncThreshold)
|
|
||||||
// _stream.BeginWrite(buffer, offset, count, WriteCallback, null);
|
|
||||||
//else
|
|
||||||
// _stream.Write(buffer, offset, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing)
|
|
||||||
{
|
|
||||||
lock (_reentrancyBlocker)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_stream.Dispose();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user