[Modify] Polish it

This commit is contained in:
sta 2017-12-30 16:42:57 +09:00
parent 86a473caef
commit 29cdd3b169

View File

@ -586,23 +586,25 @@ namespace WebSocketSharp.Net
} }
} }
// Returns true is the stream could be reused.
internal bool FlushInput () internal bool FlushInput ()
{ {
if (!HasEntityBody) if (!HasEntityBody)
return true; return true;
var len = 2048; var len = 2048;
if (_contentLength > 0) if (_contentLength > 0 && _contentLength < len)
len = (int) Math.Min (_contentLength, (long) len); len = (int) _contentLength;
var buff = new byte[len]; var buff = new byte[len];
while (true) { while (true) {
// TODO: Test if MS has a timeout when doing this.
try { try {
var ares = InputStream.BeginRead (buff, 0, len, null, null); var ares = InputStream.BeginRead (buff, 0, len, null, null);
if (!ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne (100)) if (!ares.IsCompleted) {
return false; var timeout = 100;
if (!ares.AsyncWaitHandle.WaitOne (timeout))
return false;
}
if (InputStream.EndRead (ares) <= 0) if (InputStream.EndRead (ares) <= 0)
return true; return true;