From c3927a497027f4e80a1edeb1ed7e35770d528ae7 Mon Sep 17 00:00:00 2001 From: sta Date: Thu, 4 Feb 2021 19:40:29 +0900 Subject: [PATCH] [Modify] Polish it --- websocket-sharp/Net/RequestStream.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/websocket-sharp/Net/RequestStream.cs b/websocket-sharp/Net/RequestStream.cs index 6bac41bf..44f96fe5 100644 --- a/websocket-sharp/Net/RequestStream.cs +++ b/websocket-sharp/Net/RequestStream.cs @@ -173,13 +173,15 @@ namespace WebSocketSharp.Net #region Public Methods public override IAsyncResult BeginRead ( - byte[] buffer, int offset, int count, AsyncCallback callback, object state) + byte[] buffer, int offset, int count, AsyncCallback callback, object state + ) { if (_disposed) throw new ObjectDisposedException (GetType ().ToString ()); var nread = fillFromBuffer (buffer, offset, count); - if (nread > 0 || nread == -1) { + + if (nread != 0) { var ares = new HttpStreamAsyncResult (callback, state); ares.Buffer = buffer; ares.Offset = offset; @@ -190,8 +192,7 @@ namespace WebSocketSharp.Net return ares; } - // Avoid reading past the end of the request to allow for HTTP pipelining. - if (_bodyLeft >= 0 && count > _bodyLeft) + if (_bodyLeft >= 0 && _bodyLeft < count) count = (int) _bodyLeft; return _stream.BeginRead (buffer, offset, count, callback, state);