[Modify] Polish it
This commit is contained in:
parent
9d514440bf
commit
39add76329
@ -942,31 +942,20 @@ namespace WebSocketSharp
|
||||
this Stream stream, byte[] bytes, int bufferLength, Action completed, Action<Exception> error)
|
||||
{
|
||||
var input = new MemoryStream (bytes);
|
||||
var buff = new byte[bufferLength];
|
||||
input.CopyToAsync (
|
||||
stream,
|
||||
bufferLength,
|
||||
() => {
|
||||
if (completed != null)
|
||||
completed ();
|
||||
|
||||
AsyncCallback callback = null;
|
||||
callback = ar => {
|
||||
try {
|
||||
var nread = input.EndRead (ar);
|
||||
if (nread <= 0) {
|
||||
if (completed != null)
|
||||
completed ();
|
||||
|
||||
input.Dispose ();
|
||||
return;
|
||||
}
|
||||
|
||||
stream.Write (buff, 0, nread);
|
||||
input.BeginRead (buff, 0, bufferLength, callback, null);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
input.Dispose ();
|
||||
},
|
||||
ex => {
|
||||
input.Dispose ();
|
||||
if (error != null)
|
||||
error (ex);
|
||||
}
|
||||
};
|
||||
|
||||
input.BeginRead (buff, 0, bufferLength, callback, null);
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
Loading…
Reference in New Issue
Block a user