Skip to content
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

FFI connection without protobuf + C# #126

Open
wants to merge 15 commits into
base: csharp/integ_yuryf_connection
Choose a base branch
from
8 changes: 7 additions & 1 deletion benchmarks/csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

using StackExchange.Redis;

using static Glide.ConnectionConfiguration;

public static class MainClass
{
private enum ChosenAction { GET_NON_EXISTING, GET_EXISTING, SET };
Expand Down Expand Up @@ -292,7 +294,11 @@ private static async Task run_with_parameters(int total_commands,
{
var clients = await createClients(clientCount, () =>
{
var glide_client = new AsyncClient(host, PORT, useTLS);
var config = new StandaloneClientConfigurationBuilder()
.WithAddress(host, PORT)
.WithTlsMode(useTLS ? TlsMode.SecureTls : TlsMode.NoTls)
.Build();
var glide_client = new AsyncClient(config);
return Task.FromResult<(Func<string, Task<string?>>, Func<string, string, Task>, Action)>(
(async (key) => await glide_client.GetAsync(key),
async (key, value) => await glide_client.SetAsync(key, value),
Expand Down
11 changes: 8 additions & 3 deletions csharp/lib/AsyncClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@

using System.Runtime.InteropServices;

using static Glide.ConnectionConfiguration;

namespace Glide;

public class AsyncClient : IDisposable
{
#region public methods
public AsyncClient(string host, UInt32 port, bool useTLS)
public AsyncClient(StandaloneClientConfiguration config)
{
successCallbackDelegate = SuccessCallback;
var successCallbackPointer = Marshal.GetFunctionPointerForDelegate(successCallbackDelegate);
failureCallbackDelegate = FailureCallback;
var failureCallbackPointer = Marshal.GetFunctionPointerForDelegate(failureCallbackDelegate);
clientPointer = CreateClientFfi(host, port, useTLS, successCallbackPointer, failureCallbackPointer);
var configPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ConnectionRequest)));
Marshal.StructureToPtr(config.ToRequest(), configPtr, false);
clientPointer = CreateClientFfi(configPtr, successCallbackPointer, failureCallbackPointer);
Marshal.FreeHGlobal(configPtr);
if (clientPointer == IntPtr.Zero)
{
throw new Exception("Failed creating a client");
Expand Down Expand Up @@ -104,7 +109,7 @@ private void FailureCallback(ulong index)

private delegate void IntAction(IntPtr arg);
[DllImport("libglide_rs", CallingConvention = CallingConvention.Cdecl, EntryPoint = "create_client")]
private static extern IntPtr CreateClientFfi(String host, UInt32 port, bool useTLS, IntPtr successCallback, IntPtr failureCallback);
private static extern IntPtr CreateClientFfi(IntPtr config, IntPtr successCallback, IntPtr failureCallback);

[DllImport("libglide_rs", CallingConvention = CallingConvention.Cdecl, EntryPoint = "close_client")]
private static extern void CloseClientFfi(IntPtr client);
Expand Down
Loading
Loading