Refactored WebSocket.cs
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -810,38 +810,52 @@ namespace WebSocketSharp | ||||
|  | ||||
|     private bool concatenateFragmentsInto (Stream dest) | ||||
|     { | ||||
|       while (true) { | ||||
|         var frame = _stream.ReadFrame (); | ||||
|  | ||||
|       // MORE & CONT | ||||
|       if (!frame.IsFinal && frame.IsContinuation) { | ||||
|         if (frame.IsFinal) { | ||||
|           // FINAL | ||||
|  | ||||
|           // CONT | ||||
|           if (frame.IsContinuation) { | ||||
|             dest.WriteBytes (frame.PayloadData.ApplicationData); | ||||
|         return concatenateFragmentsInto (dest); | ||||
|             break; | ||||
|           } | ||||
|  | ||||
|       // FINAL & CONT | ||||
|       if (frame.IsFinal && frame.IsContinuation) { | ||||
|         dest.WriteBytes (frame.PayloadData.ApplicationData); | ||||
|         return true; | ||||
|       } | ||||
|  | ||||
|       // FINAL & PING | ||||
|       if (frame.IsFinal && frame.IsPing) { | ||||
|           // PING | ||||
|           if (frame.IsPing) { | ||||
|             acceptPingFrame (frame); | ||||
|         return concatenateFragmentsInto (dest); | ||||
|             continue; | ||||
|           } | ||||
|  | ||||
|       // FINAL & PONG | ||||
|       if (frame.IsFinal && frame.IsPong) { | ||||
|           // PONG | ||||
|           if (frame.IsPong) { | ||||
|             acceptPongFrame (frame); | ||||
|         return concatenateFragmentsInto (dest); | ||||
|             continue; | ||||
|           } | ||||
|  | ||||
|       // FINAL & CLOSE | ||||
|       if (frame.IsFinal && frame.IsClose) | ||||
|           // 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, null); | ||||
|         return acceptUnsupportedFrame ( | ||||
|           frame, | ||||
|           CloseStatusCode.INCORRECT_DATA, | ||||
|           "An incorrect data has been received while receiving fragmented data."); | ||||
|       } | ||||
|  | ||||
|       return true; | ||||
|     } | ||||
|  | ||||
|     private bool connect () | ||||
|   | ||||
		Reference in New Issue
	
	Block a user