Fix for issue #16

This commit is contained in:
sta 2013-04-07 17:05:48 +09:00
parent 94cf881dcf
commit 57420387ff
20 changed files with 14 additions and 9 deletions

Binary file not shown.

View File

@ -313,17 +313,21 @@ namespace WebSocketSharp {
public static void ParseAsync(Stream stream, Action<WsFrame> completed) public static void ParseAsync(Stream stream, Action<WsFrame> completed)
{ {
ParseAsync(stream, true, completed); ParseAsync(stream, true, completed, null);
} }
public static void ParseAsync(Stream stream, bool unmask, Action<WsFrame> completed) public static void ParseAsync(Stream stream, Action<WsFrame> completed, Action<Exception> error)
{ {
var headerLen = 2; ParseAsync(stream, true, completed, error);
var header = new byte[headerLen]; }
AsyncCallback callback = (ar) => public static void ParseAsync(
Stream stream, bool unmask, Action<WsFrame> completed, Action<Exception> error)
{ {
WsFrame frame; var header = new byte[2];
AsyncCallback callback = ar =>
{
WsFrame frame = null;
try try
{ {
var readLen = stream.EndRead(ar); var readLen = stream.EndRead(ar);
@ -331,9 +335,10 @@ namespace WebSocketSharp {
? parse(header, stream, unmask) ? parse(header, stream, unmask)
: null; : null;
} }
catch catch (Exception ex)
{ {
frame = null; if (!error.IsNull())
error(ex);
} }
finally finally
{ {
@ -342,7 +347,7 @@ namespace WebSocketSharp {
} }
}; };
stream.BeginRead(header, 0, headerLen, callback, null); stream.BeginRead(header, 0, 2, callback, null);
} }
public void Print() public void Print()

Binary file not shown.