From cf68c18dd2b5f6ae0daf946857263af10899c863 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 9 Oct 2016 02:34:42 -0700 Subject: [PATCH] Do async reads --- samples/SocketsSample/EndPoints/JsonRpcEndpoint.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/samples/SocketsSample/EndPoints/JsonRpcEndpoint.cs b/samples/SocketsSample/EndPoints/JsonRpcEndpoint.cs index 8e9d3f28a0..0286739f51 100644 --- a/samples/SocketsSample/EndPoints/JsonRpcEndpoint.cs +++ b/samples/SocketsSample/EndPoints/JsonRpcEndpoint.cs @@ -46,6 +46,12 @@ namespace SocketsSample while (true) { + // JSON.NET doesn't handle async reads so we wait for data here + var result = await connection.Channel.Input.ReadAsync(); + + // Don't advance the buffer so we parse sync + connection.Channel.Input.Advance(result.Buffer.Start); + while (!reader.Read()) { break; @@ -58,7 +64,6 @@ namespace SocketsSample } catch (Exception) { - var result = await connection.Channel.Input.ReadAsync(); if (result.IsCompleted) { break;