[#24] Client: Implement pool part1

first iteration - base classes and methods

Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
Pavel Gross 2024-10-21 10:48:00 +03:00
parent d1271df207
commit c9a75ea025
72 changed files with 2786 additions and 468 deletions

View file

@ -0,0 +1,48 @@
using System;
using System.Buffers;
using System.Security.Cryptography;
using Grpc.Net.Client;
namespace FrostFS.SDK.ClientV2;
public class EnvironmentContext(FrostFSClient client, ECDsa? key, FrostFsOwner? owner, GrpcChannel channel, FrostFsVersion version) : IDisposable
{
private ArrayPool<byte>? _arrayPool;
internal FrostFsOwner? Owner { get; } = owner;
internal GrpcChannel Channel { get; private set; } = channel;
internal FrostFsVersion Version { get; } = version;
internal NetworkSettings? NetworkSettings { get; set; }
internal FrostFSClient Client { get; } = client;
internal ClientKey? Key { get; } = key != null ? new ClientKey(key) : null;
/// <summary>
/// Custom pool is used for predefined sizes of buffers like grpc chunk
/// </summary>
internal ArrayPool<byte> GetArrayPool(int size)
{
_arrayPool ??= ArrayPool<byte>.Create(size, 256);
return _arrayPool;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
Channel?.Dispose();
}
}
}