Commit c9bbbd19 authored by Honfika's avatar Honfika

do not throw exception in fillbuffer (only when it called on an already closed stream)

parent efae2199
...@@ -159,6 +159,11 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -159,6 +159,11 @@ namespace Titanium.Web.Proxy.Examples.Wpf
{ {
e.HttpClient.Request.KeepBody = true; e.HttpClient.Request.KeepBody = true;
await e.GetRequestBody(); await e.GetRequestBody();
if (item == SelectedSession)
{
await Dispatcher.InvokeAsync(selectedSessionChanged);
}
} }
} }
...@@ -185,6 +190,10 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -185,6 +190,10 @@ namespace Titanium.Web.Proxy.Examples.Wpf
await e.GetResponseBody(); await e.GetResponseBody();
await Dispatcher.InvokeAsync(() => { item.Update(); }); await Dispatcher.InvokeAsync(() => { item.Update(); });
if (item == SelectedSession)
{
await Dispatcher.InvokeAsync(selectedSessionChanged);
}
} }
} }
} }
......
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -450,7 +451,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network ...@@ -450,7 +451,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
{ {
if (closed) if (closed)
{ {
return false; throw new Exception("Stream is already closed");
} }
if (bufferLength > 0) if (bufferLength > 0)
...@@ -462,17 +463,23 @@ namespace Titanium.Web.Proxy.StreamExtended.Network ...@@ -462,17 +463,23 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
bufferPos = 0; bufferPos = 0;
int readBytes = baseStream.Read(streamBuffer, bufferLength, streamBuffer.Length - bufferLength); bool result = false;
bool result = readBytes > 0; try
if (result)
{ {
OnDataRead(streamBuffer, bufferLength, readBytes); int readBytes = baseStream.Read(streamBuffer, bufferLength, streamBuffer.Length - bufferLength);
bufferLength += readBytes; result = readBytes > 0;
if (result)
{
OnDataRead(streamBuffer, bufferLength, readBytes);
bufferLength += readBytes;
}
} }
else finally
{ {
closed = true; if (!result)
throw new EndOfStreamException(); {
closed = true;
}
} }
return result; return result;
...@@ -488,7 +495,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network ...@@ -488,7 +495,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
{ {
if (closed) if (closed)
{ {
return false; throw new Exception("Stream is already closed");
} }
if (bufferLength > 0) if (bufferLength > 0)
...@@ -506,18 +513,23 @@ namespace Titanium.Web.Proxy.StreamExtended.Network ...@@ -506,18 +513,23 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
bufferPos = 0; bufferPos = 0;
int readBytes = await baseStream.ReadAsync(streamBuffer, bufferLength, bytesToRead, cancellationToken); bool result = false;
bool result = readBytes > 0; try
if (result)
{ {
OnDataRead(streamBuffer, bufferLength, readBytes); int readBytes = await baseStream.ReadAsync(streamBuffer, bufferLength, bytesToRead, cancellationToken);
bufferLength += readBytes; result = readBytes > 0;
if (result)
{
OnDataRead(streamBuffer, bufferLength, readBytes);
bufferLength += readBytes;
}
} }
else finally
{ {
closed = true; if (!result)
{
// do not throw exception here closed = true;
}
} }
return result; return result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment