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 : code == CloseStatusCode.INCONSISTENT_DATA
? "An inconsistent data has been received." ? "An inconsistent data has been received."
: code == CloseStatusCode.POLICY_VIOLATION : code == CloseStatusCode.POLICY_VIOLATION
? "A policy violation data has been received." ? "A policy violation has occurred."
: code == CloseStatusCode.TOO_BIG : code == CloseStatusCode.TOO_BIG
? "A too big data has been received." ? "A too big data has been received."
: code == CloseStatusCode.IGNORE_EXTENSION : code == CloseStatusCode.IGNORE_EXTENSION

View File

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