[Modify] Polish it
This commit is contained in:
parent
40c993a2de
commit
33bbfddda6
@ -703,53 +703,58 @@ namespace WebSocketSharp
|
|||||||
long length,
|
long length,
|
||||||
int bufferLength,
|
int bufferLength,
|
||||||
Action<byte[]> completed,
|
Action<byte[]> completed,
|
||||||
Action<Exception> error)
|
Action<Exception> error
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var dest = new MemoryStream ();
|
var dest = new MemoryStream ();
|
||||||
var buff = new byte[bufferLength];
|
var buff = new byte[bufferLength];
|
||||||
var retry = 0;
|
var retry = 0;
|
||||||
|
|
||||||
Action<long> read = null;
|
Action<long> read = null;
|
||||||
read = len => {
|
read =
|
||||||
if (len < bufferLength)
|
len => {
|
||||||
bufferLength = (int) len;
|
if (len < bufferLength)
|
||||||
|
bufferLength = (int) len;
|
||||||
|
|
||||||
stream.BeginRead (
|
stream.BeginRead (
|
||||||
buff,
|
buff,
|
||||||
0,
|
0,
|
||||||
bufferLength,
|
bufferLength,
|
||||||
ar => {
|
ar => {
|
||||||
try {
|
try {
|
||||||
var nread = stream.EndRead (ar);
|
var nread = stream.EndRead (ar);
|
||||||
if (nread > 0)
|
if (nread > 0)
|
||||||
dest.Write (buff, 0, nread);
|
dest.Write (buff, 0, nread);
|
||||||
|
|
||||||
if (nread == 0 && retry < _retry) {
|
if (nread == 0 && retry < _retry) {
|
||||||
retry++;
|
retry++;
|
||||||
}
|
read (len);
|
||||||
else if (nread == 0 || nread == len) {
|
|
||||||
if (completed != null) {
|
return;
|
||||||
dest.Close ();
|
|
||||||
completed (dest.ToArray ());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dest.Dispose ();
|
if (nread == 0 || nread == len) {
|
||||||
return;
|
if (completed != null) {
|
||||||
}
|
dest.Close ();
|
||||||
else {
|
completed (dest.ToArray ());
|
||||||
retry = 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
read (len - nread);
|
dest.Dispose ();
|
||||||
}
|
return;
|
||||||
catch (Exception ex) {
|
}
|
||||||
dest.Dispose ();
|
|
||||||
if (error != null)
|
retry = 0;
|
||||||
error (ex);
|
read (len - nread);
|
||||||
}
|
}
|
||||||
},
|
catch (Exception ex) {
|
||||||
null);
|
dest.Dispose ();
|
||||||
};
|
if (error != null)
|
||||||
|
error (ex);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
null
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
read (length);
|
read (length);
|
||||||
|
Loading…
Reference in New Issue
Block a user