internal ArraySegment<byte> ConvertNativeBuffer(WebSocketProtocolComponent.Action action,
Interop.WebSocket.Buffer buffer,
WebSocketProtocolComponent.BufferType bufferType)
{
ThrowIfDisposed();
IntPtr bufferData;
uint bufferLength;
UnwrapWebSocketBuffer(buffer, bufferType, out bufferData, out bufferLength);
if (bufferData == IntPtr.Zero)
{
return WebSocketValidate.EmptyPayload;
}
if (this.IsNativeBuffer(bufferData, bufferLength))
{
return new ArraySegment<byte>(_internalBuffer.Array,
this.GetOffset(bufferData),
(int)bufferLength);
}
Debug.Assert(false, "'buffer' MUST reference a memory segment within the pinned InternalBuffer.");
// Indicates a violation in the contract with native Websocket.dll and could indicate
// memory corruption because the internal buffer is shared between managed and native code
throw new AccessViolationException();
}