Skip to content

Commit 9dbdbed

Browse files
Updated fix issue with Http client timeout
1 parent 955fcf9 commit 9dbdbed

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/MTConnect.NET-HTTP/Clients/Rest/MTConnectHttpClientStream.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,11 @@ public async Task Run(CancellationToken cancellationToken)
168168
var contentLength = 0;
169169
string contentEncoding = null;
170170
var trimBytes = new byte[] { 10, 13 };
171+
string lineStr = null;
171172

172-
var b = stream.ReadByte();
173+
var readBuffer = new byte[1];
174+
await stream.ReadAsync(readBuffer, 0, readBuffer.Length, stop.Token);
175+
int b = readBuffer[0];
173176

174177
if (Timeout > 0)
175178
{
@@ -192,15 +195,15 @@ public async Task Run(CancellationToken cancellationToken)
192195
if (cr && lf)
193196
{
194197
// Trim CR and LF bytes from beginning and end
195-
var lineBytes = ObjectExtensions.TrimBytes(line.ToArray(), trimBytes);
198+
//var lineBytes = ObjectExtensions.TrimBytes(line.ToArray(), trimBytes);
196199

197200
// Get the current line as a UTF-8 string
198-
var lineStr = Encoding.UTF8.GetString(lineBytes);
201+
lineStr = Encoding.UTF8.GetString(line.ToArray());
199202

200203
if (headerActive)
201204
{
202205
// Add Header
203-
header.AddRange(lineBytes);
206+
header.AddRange(line.ToArray());
204207

205208
if (prevNewLine)
206209
{
@@ -244,7 +247,8 @@ public async Task Run(CancellationToken cancellationToken)
244247
prevByte = b;
245248

246249
// Read the next Byte
247-
b = stream.ReadByte();
250+
await stream.ReadAsync(readBuffer, 0, readBuffer.Length, stop.Token);
251+
b = readBuffer[0];
248252

249253
if (Timeout > 0)
250254
{

0 commit comments

Comments
 (0)