Skip to content

Commit f34d7af

Browse files
author
Elad Zelingher
committed
Fixing bug when stream closed
1 parent c4d6e93 commit f34d7af

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/net45/Extensions/WampSharp.RawSocket/RawSocket/NetworkStreamExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.IO;
12
using System.Net.Sockets;
23
using System.Threading.Tasks;
34

@@ -18,6 +19,13 @@ public async static Task ReadExactAsync(this NetworkStream networkStream, byte[]
1819
while (readBytes != length)
1920
{
2021
int currentlyRead = await networkStream.ReadAsync(buffer, currentPosition, length - readBytes);
22+
23+
// If we read 0 bytes, we have reached the end of the stream.
24+
if (currentlyRead == 0)
25+
{
26+
throw new EndOfStreamException();
27+
}
28+
2129
readBytes += currentlyRead;
2230
currentPosition += currentlyRead;
2331
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
2-
<configuration>
3-
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5-
</startup>
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
66
</configuration>

0 commit comments

Comments
 (0)