Refactored WebSocket.cs

This commit is contained in:
sta 2014-02-24 19:59:46 +09:00
parent 673d7225bd
commit 2a8a9ca061
2 changed files with 44 additions and 30 deletions

View File

@ -481,7 +481,7 @@ namespace WebSocketSharp
: code == CloseStatusCode.INCONSISTENT_DATA
? "An inconsistent data has been received."
: code == CloseStatusCode.POLICY_VIOLATION
? "A policy violation data has been received."
? "A policy violation has occurred."
: code == CloseStatusCode.TOO_BIG
? "A too big data has been received."
: code == CloseStatusCode.IGNORE_EXTENSION

View File

@ -810,38 +810,52 @@ namespace WebSocketSharp
private bool concatenateFragmentsInto (Stream dest)
{
var frame = _stream.ReadFrame ();
while (true) {
var frame = _stream.ReadFrame ();
// MORE & CONT
if (!frame.IsFinal && frame.IsContinuation) {
dest.WriteBytes (frame.PayloadData.ApplicationData);
return concatenateFragmentsInto (dest);
if (frame.IsFinal) {
// FINAL
// CONT
if (frame.IsContinuation) {
dest.WriteBytes (frame.PayloadData.ApplicationData);
break;
}
// PING
if (frame.IsPing) {
acceptPingFrame (frame);
continue;
}
// PONG
if (frame.IsPong) {
acceptPongFrame (frame);
continue;
}
// CLOSE
if (frame.IsClose)
return acceptCloseFrame (frame);
}
else {
// MORE
// CONT
if (frame.IsContinuation) {
dest.WriteBytes (frame.PayloadData.ApplicationData);
continue;
}
}
// ?
return acceptUnsupportedFrame (
frame,
CloseStatusCode.INCORRECT_DATA,
"An incorrect data has been received while receiving fragmented data.");
}
// FINAL & CONT
if (frame.IsFinal && frame.IsContinuation) {
dest.WriteBytes (frame.PayloadData.ApplicationData);
return true;
}
// FINAL & PING
if (frame.IsFinal && frame.IsPing) {
acceptPingFrame (frame);
return concatenateFragmentsInto (dest);
}
// FINAL & PONG
if (frame.IsFinal && frame.IsPong) {
acceptPongFrame (frame);
return concatenateFragmentsInto (dest);
}
// FINAL & CLOSE
if (frame.IsFinal && frame.IsClose)
return acceptCloseFrame (frame);
// ?
return acceptUnsupportedFrame (frame, CloseStatusCode.INCORRECT_DATA, null);
return true;
}
private bool connect ()