Added processFragmentedFrame2 method, to replace the processFragmentedFrame method with this
This commit is contained in:
parent
058d952970
commit
82077d321c
@ -79,14 +79,17 @@ namespace WebSocketSharp
|
|||||||
private bool _enableRedirection;
|
private bool _enableRedirection;
|
||||||
private string _extensions;
|
private string _extensions;
|
||||||
private AutoResetEvent _exitReceiving;
|
private AutoResetEvent _exitReceiving;
|
||||||
|
private Opcode _fopcode;
|
||||||
private object _forConn;
|
private object _forConn;
|
||||||
private object _forEvent;
|
private object _forEvent;
|
||||||
private object _forMessageEventQueue;
|
private object _forMessageEventQueue;
|
||||||
private object _forSend;
|
private object _forSend;
|
||||||
|
private MemoryStream _fragmentsBuffer;
|
||||||
private const string _guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
private const string _guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||||
private Func<WebSocketContext, string>
|
private Func<WebSocketContext, string>
|
||||||
_handshakeRequestChecker;
|
_handshakeRequestChecker;
|
||||||
private bool _ignoreExtensions;
|
private bool _ignoreExtensions;
|
||||||
|
private bool _inContinuation;
|
||||||
private volatile Logger _logger;
|
private volatile Logger _logger;
|
||||||
private Queue<MessageEventArgs> _messageEventQueue;
|
private Queue<MessageEventArgs> _messageEventQueue;
|
||||||
private uint _nonceCount;
|
private uint _nonceCount;
|
||||||
@ -656,6 +659,8 @@ namespace WebSocketSharp
|
|||||||
? "A frame from the server is masked."
|
? "A frame from the server is masked."
|
||||||
: !_client && !masked
|
: !_client && !masked
|
||||||
? "A frame from a client isn't masked."
|
? "A frame from a client isn't masked."
|
||||||
|
: _inContinuation && frame.IsData
|
||||||
|
? "A data frame has been received while receiving the fragmented data."
|
||||||
: frame.IsCompressed && _compression == CompressionMethod.None
|
: frame.IsCompressed && _compression == CompressionMethod.None
|
||||||
? "A compressed frame is without the available decompression method."
|
? "A compressed frame is without the available decompression method."
|
||||||
: null;
|
: null;
|
||||||
@ -707,6 +712,11 @@ namespace WebSocketSharp
|
|||||||
(sent && _exitReceiving != null && _exitReceiving.WaitOne (timeout));
|
(sent && _exitReceiving != null && _exitReceiving.WaitOne (timeout));
|
||||||
|
|
||||||
release ();
|
release ();
|
||||||
|
if (_fragmentsBuffer != null) {
|
||||||
|
_fragmentsBuffer.Dispose ();
|
||||||
|
_fragmentsBuffer = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (_receivePong != null) {
|
if (_receivePong != null) {
|
||||||
_receivePong.Close ();
|
_receivePong.Close ();
|
||||||
_receivePong = null;
|
_receivePong = null;
|
||||||
@ -1017,6 +1027,34 @@ namespace WebSocketSharp
|
|||||||
return frame.IsContinuation || processFragments (frame);
|
return frame.IsContinuation || processFragments (frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool processFragmentedFrame2 (WebSocketFrame frame)
|
||||||
|
{
|
||||||
|
if (!_inContinuation) {
|
||||||
|
if (frame.IsContinuation)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
_fopcode = frame.Opcode;
|
||||||
|
_fragmentsBuffer = new MemoryStream ();
|
||||||
|
_inContinuation = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_fragmentsBuffer.WriteBytes (frame.PayloadData.ApplicationData);
|
||||||
|
if (frame.IsFinal) {
|
||||||
|
using (_fragmentsBuffer) {
|
||||||
|
var data = _compression != CompressionMethod.None
|
||||||
|
? _fragmentsBuffer.DecompressToArray (_compression)
|
||||||
|
: _fragmentsBuffer.ToArray ();
|
||||||
|
|
||||||
|
enqueueToMessageEventQueue (new MessageEventArgs (_fopcode, data));
|
||||||
|
}
|
||||||
|
|
||||||
|
_fragmentsBuffer = null;
|
||||||
|
_inContinuation = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private bool processFragments (WebSocketFrame first)
|
private bool processFragments (WebSocketFrame first)
|
||||||
{
|
{
|
||||||
using (var buff = new MemoryStream ()) {
|
using (var buff = new MemoryStream ()) {
|
||||||
@ -1441,7 +1479,7 @@ namespace WebSocketSharp
|
|||||||
if (processReceivedFrame (frame) && _readyState != WebSocketState.Closed) {
|
if (processReceivedFrame (frame) && _readyState != WebSocketState.Closed) {
|
||||||
receive ();
|
receive ();
|
||||||
|
|
||||||
if (!frame.IsData)
|
if (frame.IsControl || !frame.IsFinal)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock (_forEvent) {
|
lock (_forEvent) {
|
||||||
|
Loading…
Reference in New Issue
Block a user