From 29cdd3b169b2a2a443c23129151e0838d81be2b6 Mon Sep 17 00:00:00 2001 From: sta Date: Sat, 30 Dec 2017 16:42:57 +0900 Subject: [PATCH] [Modify] Polish it --- websocket-sharp/Net/HttpListenerRequest.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/websocket-sharp/Net/HttpListenerRequest.cs b/websocket-sharp/Net/HttpListenerRequest.cs index 6955e760..df6d4e88 100644 --- a/websocket-sharp/Net/HttpListenerRequest.cs +++ b/websocket-sharp/Net/HttpListenerRequest.cs @@ -586,23 +586,25 @@ namespace WebSocketSharp.Net } } - // Returns true is the stream could be reused. internal bool FlushInput () { if (!HasEntityBody) return true; var len = 2048; - if (_contentLength > 0) - len = (int) Math.Min (_contentLength, (long) len); + if (_contentLength > 0 && _contentLength < len) + len = (int) _contentLength; var buff = new byte[len]; + while (true) { - // TODO: Test if MS has a timeout when doing this. try { var ares = InputStream.BeginRead (buff, 0, len, null, null); - if (!ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne (100)) - return false; + if (!ares.IsCompleted) { + var timeout = 100; + if (!ares.AsyncWaitHandle.WaitOne (timeout)) + return false; + } if (InputStream.EndRead (ares) <= 0) return true;