Modified receiving frame

This commit is contained in:
sta
2013-10-18 23:07:43 +09:00
parent f6610352e2
commit 0e54f96aea
3 changed files with 65 additions and 70 deletions

View File

@@ -822,8 +822,9 @@ namespace WebSocketSharp
private void open ()
{
_readyState = WebSocketState.OPEN;
startReceiving ();
OnOpen.Emit (this, EventArgs.Empty);
startReceiving ();
}
private bool processAbnormalFrame ()
@@ -1230,28 +1231,29 @@ namespace WebSocketSharp
_exitReceiving = new AutoResetEvent (false);
_receivePong = new AutoResetEvent (false);
Action<WsFrame> completed = null;
completed = frame =>
{
try {
Action receive = null;
receive = () => _stream.ReadFrameAsync (
frame =>
{
if (processFrame (frame))
_stream.ReadFrameAsync (completed);
receive ();
else
_exitReceiving.Set ();
}
catch (WebSocketException ex) {
},
ex =>
{
_logger.Fatal (ex.ToString ());
error ("An exception has occured.");
close (ex.Code, ex.Message, false);
}
catch (Exception ex) {
_logger.Fatal (ex.ToString ());
error ("An exception has occured.");
close (CloseStatusCode.ABNORMAL, null, false);
}
};
if (ex.GetType () == typeof (WebSocketException))
{
var wsex = (WebSocketException) ex;
close (wsex.Code, wsex.Message, false);
}
else
close (CloseStatusCode.ABNORMAL, null, false);
});
_stream.ReadFrameAsync (completed);
receive ();
}
// As server