[Modify] Polish it
This commit is contained in:
parent
6e6bab85af
commit
6833c2b014
@ -140,45 +140,6 @@ namespace WebSocketSharp
|
||||
}
|
||||
}
|
||||
|
||||
private static void readBytesAsync (
|
||||
this Stream stream,
|
||||
byte[] buffer,
|
||||
int offset,
|
||||
int count,
|
||||
Action<byte[]> completed,
|
||||
Action<Exception> error)
|
||||
{
|
||||
AsyncCallback callback = null;
|
||||
callback = ar => {
|
||||
try {
|
||||
var nread = stream.EndRead (ar);
|
||||
if (nread == 0 || nread == count) {
|
||||
if (completed != null)
|
||||
completed (buffer.SubArray (0, offset + nread));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
offset += nread;
|
||||
count -= nread;
|
||||
|
||||
stream.BeginRead (buffer, offset, count, callback, null);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (error != null)
|
||||
error (ex);
|
||||
}
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
for (ulong i = 0; i < n; i++)
|
||||
@ -668,14 +629,15 @@ namespace WebSocketSharp
|
||||
if (len < bufferLength)
|
||||
bufferLength = (int) len;
|
||||
|
||||
stream.readBytesAsync (
|
||||
stream.BeginRead (
|
||||
buff,
|
||||
0,
|
||||
bufferLength,
|
||||
bytes => {
|
||||
var nread = bytes.Length;
|
||||
ar => {
|
||||
try {
|
||||
var nread = stream.EndRead (ar);
|
||||
if (nread > 0)
|
||||
dest.Write (bytes, 0, nread);
|
||||
dest.Write (buff, 0, nread);
|
||||
|
||||
if (nread == 0 || nread == len) {
|
||||
if (completed != null) {
|
||||
@ -688,16 +650,25 @@ namespace WebSocketSharp
|
||||
}
|
||||
|
||||
read (len - nread);
|
||||
},
|
||||
ex => {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
dest.Dispose ();
|
||||
if (error != null)
|
||||
error (ex);
|
||||
});
|
||||
}
|
||||
},
|
||||
null);
|
||||
};
|
||||
|
||||
try {
|
||||
read (length);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
dest.Dispose ();
|
||||
if (error != null)
|
||||
error (ex);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string RemovePrefix (this string value, params string[] prefixes)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user