[Modify] Polish it
This commit is contained in:
parent
4d5add5e8d
commit
f518dd717c
@ -170,25 +170,21 @@ namespace WebSocketSharp
|
|||||||
Action<byte[]> completed,
|
Action<byte[]> completed,
|
||||||
Action<Exception> error)
|
Action<Exception> error)
|
||||||
{
|
{
|
||||||
AsyncCallback callback = ar => {
|
AsyncCallback callback = null;
|
||||||
|
callback = ar => {
|
||||||
try {
|
try {
|
||||||
var nread = stream.EndRead (ar);
|
var nread = stream.EndRead (ar);
|
||||||
if (nread < 1) {
|
if (nread <= 0 || nread == count) {
|
||||||
// EOF/Disconnect before reading specified number of bytes.
|
|
||||||
if (completed != null)
|
if (completed != null)
|
||||||
completed (buffer.SubArray (0, offset));
|
completed (buffer.SubArray (0, nread > 0 ? offset + nread : offset));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nread < count) {
|
offset += nread;
|
||||||
// Need to read more.
|
count -= nread;
|
||||||
stream.readBytesAsync (buffer, offset + nread, count - nread, completed, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (completed != null)
|
stream.BeginRead (buffer, offset, count, callback, null);
|
||||||
completed (buffer);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
if (error != null)
|
if (error != null)
|
||||||
@ -196,7 +192,13 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
stream.BeginRead (buffer, offset, count, callback, null);
|
try {
|
||||||
|
stream.BeginRead (buffer, offset, count, callback, null);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
if (error != null)
|
||||||
|
error (ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void times (this ulong n, Action action)
|
private static void times (this ulong n, Action action)
|
||||||
|
Loading…
Reference in New Issue
Block a user