/// <summary> /// Create a new <see cref="ConnectionMultiplexer"/> instance that connects to a Sentinel server. /// </summary> /// <param name="configuration">The configuration options to use for this multiplexer.</param> /// <param name="log">The <see cref="TextWriter"/> to log to.</param> public static Task <ConnectionMultiplexer> SentinelConnectAsync(ConfigurationOptions configuration, TextWriter log = null) { SocketConnection.AssertDependencies(); return(ConnectImplAsync(configuration, log, ServerType.Sentinel)); }
static async Task Main() { using var server = new EchoServer(Port); await Task.Yield(); SocketConnection.AssertDependencies(); Log("Connecting..."); using var connection = await SocketConnection.ConnectAsync(new IPEndPoint (IPAddress.Loopback, Port)); Log("Connected"); Guid guid = Guid.NewGuid(); Log($"Writing '{guid}'..."); var output = connection.Output; var memory = output.GetMemory(30); if (!Utf8Formatter.TryFormat(guid, memory.Span, out var bytes)) { throw new FormatException(); } output.Advance(bytes); //Log($"Flushing..."); //var flushResult = await output.FlushAsync(); //Log($"IsCompleted:{flushResult.IsCompleted}, IsCanceled:{flushResult.IsCanceled}"); //Log($"Reading..."); //var input = connection.Input; //while (true) //{ // Log($"Reading..."); // var readResult = await input.ReadAsync(); // Log($"IsCompleted:{readResult.IsCompleted}, IsCanceled:{readResult.IsCanceled}, Length:{readResult.Buffer.Length}"); // if (readResult.IsCompleted || readResult.IsCanceled) break; // if (readResult.Buffer.Length >= 36) // { // var buffer = readResult.Buffer; // var len = checked((int)buffer.Length); // var arr = ArrayPool<byte>.Shared.Rent(len); // try // { // buffer.CopyTo(arr); // var s = Encoding.UTF8.GetString(arr, 0, len); // Log($"Received: '{s}'"); // } // finally // { // ArrayPool<byte>.Shared.Return(arr); // } // input.AdvanceTo(readResult.Buffer.End); // break; // } // else // { // input.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End); // } //} //Log($"Closing output..."); //output.Complete(); }
public void CanCheckDependencies() { SocketConnection.AssertDependencies(); }