Skip to content

Commit 33f6427

Browse files
Martin LercherMartin Lercher
authored andcommitted
We need to make the ProcessInputStream() synchronous, because we have (and keep) a named thread for that.
1 parent 91b1961 commit 33f6427

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/JsonRpc/InputHandler.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ public void Start()
5353
_scheduler.Start();
5454
}
5555

56-
private async void ProcessInputStream()
56+
// don't be async: We already allocated a seperate thread for this.
57+
private void ProcessInputStream()
5758
{
59+
// some time to attach a debugger
60+
// System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
61+
5862
// header is encoded in ASCII
5963
// "Content-Length: 0" counts bytes for the following content
6064
// content is encoded in UTF-8
@@ -63,13 +67,13 @@ private async void ProcessInputStream()
6367
if (_inputThread == null) return;
6468

6569
var buffer = new byte[300];
66-
var current = await _input.ReadAsync(buffer, 0, MinBuffer);
70+
var current = _input.Read(buffer, 0, MinBuffer);
6771
if (current == 0) return; // no more _input
6872
while (current < MinBuffer ||
6973
buffer[current - 4] != CR || buffer[current - 3] != LF ||
7074
buffer[current - 2] != CR || buffer[current - 1] != LF)
7175
{
72-
var n = await _input.ReadAsync(buffer, current, 1);
76+
var n = _input.Read(buffer, current, 1);
7377
if (n == 0) return; // no more _input, mitigates endless loop here.
7478
current += n;
7579
}
@@ -99,7 +103,7 @@ private async void ProcessInputStream()
99103
var received = 0;
100104
while (received < length)
101105
{
102-
var n = await _input.ReadAsync(requestBuffer, received, requestBuffer.Length - received);
106+
var n = _input.Read(requestBuffer, received, requestBuffer.Length - received);
103107
if (n == 0) return; // no more _input
104108
received += n;
105109
}

0 commit comments

Comments
 (0)