|
|
|
@ -573,42 +573,45 @@ namespace WebSocketSharp
|
|
|
|
|
|
|
|
|
|
|
|
public static WsFrame Parse (byte [] src)
|
|
|
|
public static WsFrame Parse (byte [] src)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Parse (src, true);
|
|
|
|
return Parse (src, true, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static WsFrame Parse (Stream stream)
|
|
|
|
public static WsFrame Parse (Stream stream)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Parse (stream, true);
|
|
|
|
return Parse (stream, true, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static WsFrame Parse (byte [] src, bool unmask)
|
|
|
|
public static WsFrame Parse (byte [] src, Action<Exception> error)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var stream = new MemoryStream (src))
|
|
|
|
return Parse (src, true, error);
|
|
|
|
{
|
|
|
|
|
|
|
|
return Parse (stream, unmask);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static WsFrame Parse (Stream stream, Action<Exception> error)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Parse (stream, true, error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static WsFrame Parse (Stream stream, bool unmask)
|
|
|
|
public static WsFrame Parse (byte [] src, bool unmask, Action<Exception> error)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Parse (stream, unmask, null);
|
|
|
|
using (var stream = new MemoryStream (src))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Parse (stream, unmask, error);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static WsFrame Parse (Stream stream, bool unmask, Action<Exception> error)
|
|
|
|
public static WsFrame Parse (Stream stream, bool unmask, Action<Exception> error)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
WsFrame frame = null;
|
|
|
|
WsFrame frame = null;
|
|
|
|
try
|
|
|
|
try {
|
|
|
|
{
|
|
|
|
|
|
|
|
var header = stream.ReadBytes (2);
|
|
|
|
var header = stream.ReadBytes (2);
|
|
|
|
frame = header.Length == 2
|
|
|
|
frame = header.Length == 2
|
|
|
|
? parse (header, stream, unmask)
|
|
|
|
? parse (header, stream, unmask)
|
|
|
|
: CreateCloseFrame (
|
|
|
|
: CreateCloseFrame (
|
|
|
|
Mask.UNMASK,
|
|
|
|
Mask.UNMASK,
|
|
|
|
CloseStatusCode.ABNORMAL,
|
|
|
|
CloseStatusCode.ABNORMAL,
|
|
|
|
"'Header' of a frame cannot be read from the data stream.");
|
|
|
|
"The header part of a frame cannot be read from the 'stream'.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex) {
|
|
|
|
{
|
|
|
|
|
|
|
|
if (error != null)
|
|
|
|
if (error != null)
|
|
|
|
error (ex);
|
|
|
|
error (ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -629,43 +632,25 @@ namespace WebSocketSharp
|
|
|
|
public static void ParseAsync (
|
|
|
|
public static void ParseAsync (
|
|
|
|
Stream stream, bool unmask, Action<WsFrame> completed, Action<Exception> error)
|
|
|
|
Stream stream, bool unmask, Action<WsFrame> completed, Action<Exception> error)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var header = new byte [2];
|
|
|
|
stream.ReadBytesAsync (
|
|
|
|
AsyncCallback callback = ar =>
|
|
|
|
2,
|
|
|
|
{
|
|
|
|
header =>
|
|
|
|
WsFrame frame = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var readLen = stream.EndRead (ar);
|
|
|
|
var frame = header.Length == 2
|
|
|
|
if (readLen == 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var tmp = stream.ReadByte ();
|
|
|
|
|
|
|
|
if (tmp > -1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
header [1] = (byte) tmp;
|
|
|
|
|
|
|
|
readLen++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
frame = readLen == 2
|
|
|
|
|
|
|
|
? parse (header, stream, unmask)
|
|
|
|
? parse (header, stream, unmask)
|
|
|
|
: CreateCloseFrame (
|
|
|
|
: CreateCloseFrame (
|
|
|
|
Mask.UNMASK,
|
|
|
|
Mask.UNMASK,
|
|
|
|
CloseStatusCode.ABNORMAL,
|
|
|
|
CloseStatusCode.ABNORMAL,
|
|
|
|
"'Header' of a frame cannot be read from the data stream.");
|
|
|
|
"The header part of a frame cannot be read from the 'stream'.");
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
if (completed != null)
|
|
|
|
|
|
|
|
completed (frame);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
ex =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (error != null)
|
|
|
|
if (error != null)
|
|
|
|
error (ex);
|
|
|
|
error (ex);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
finally
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (completed != null)
|
|
|
|
|
|
|
|
completed (frame);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stream.BeginRead (header, 0, 2, callback, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Print (bool dumped)
|
|
|
|
public void Print (bool dumped)
|
|
|
|
|