Table of Contents

Class WebSocketFrameReader

Namespace
Alis.Core.Network.Internal
Assembly
Alis.dll

Reads a WebSocket frame see http://tools.ietf.org/html/rfc6455 for specification

internal static class WebSocketFrameReader

Inheritance

Inherited Members

Methods

CalculateNumBytesToRead(int, int)

Calculates the num bytes to read using the specified num bytes letf to read

internal static int CalculateNumBytesToRead(int numBytesLetfToRead, int bufferSize)

Parameters

numBytesLetfToRead int

The num bytes letf to read

bufferSize int

The buffer size

Returns

int

The num bytes letf to read

DecodeCloseFrame(bool, WebSocketOpCode, int, ArraySegment<byte>, ArraySegment<byte>)

Extracts close status and close description information from the web socket frame

internal static WebSocketFrame DecodeCloseFrame(bool isFinBitSet, WebSocketOpCode opCode, int count, ArraySegment<byte> buffer, ArraySegment<byte> maskKey)

Parameters

isFinBitSet bool
opCode WebSocketOpCode
count int
buffer ArraySegment<byte>
maskKey ArraySegment<byte>

Returns

WebSocketFrame

GetInitialLength(byte)

Gets the initial length using the specified byte 2

internal static uint GetInitialLength(byte byte2)

Parameters

byte2 byte

The byte

Returns

uint

The uint

ReadAsync(Stream, ArraySegment<byte>, CancellationToken)

Read a WebSocket frame from the stream

public static Task<WebSocketReadCursor> ReadAsync(Stream fromStream, ArraySegment<byte> intoBuffer, CancellationToken cancellationToken)

Parameters

fromStream Stream

The stream to read from

intoBuffer ArraySegment<byte>

The buffer to read into

cancellationToken CancellationToken

the cancellation token

Returns

Task<WebSocketReadCursor>

A websocket frame

ReadFromCursorAsync(Stream, ArraySegment<byte>, WebSocketReadCursor, CancellationToken)

The last read could not be completed because the read buffer was too small. We need to continue reading bytes off the stream. Not to be confused with a continuation frame

public static Task<WebSocketReadCursor> ReadFromCursorAsync(Stream fromStream, ArraySegment<byte> intoBuffer, WebSocketReadCursor readCursor, CancellationToken cancellationToken)

Parameters

fromStream Stream

The stream to read from

intoBuffer ArraySegment<byte>

The buffer to read into

readCursor WebSocketReadCursor

The previous partial websocket frame read plus cursor information

cancellationToken CancellationToken

the cancellation token

Returns

Task<WebSocketReadCursor>

A websocket frame

ReadLength(byte, ArraySegment<byte>, Stream, CancellationToken)

Reads the length of the payload according to the contents of byte2

internal static Task<uint> ReadLength(byte byte2, ArraySegment<byte> smallBuffer, Stream fromStream, CancellationToken cancellationToken)

Parameters

byte2 byte
smallBuffer ArraySegment<byte>
fromStream Stream
cancellationToken CancellationToken

Returns

Task<uint>

ReadLongLength(Stream, ArraySegment<byte>, CancellationToken)

Reads the long length using the specified from stream

internal static Task<uint> ReadLongLength(Stream fromStream, ArraySegment<byte> smallBuffer, CancellationToken cancellationToken)

Parameters

fromStream Stream

The from stream

smallBuffer ArraySegment<byte>

The small buffer

cancellationToken CancellationToken

The cancellation token

Returns

Task<uint>

A task containing the uint

ReadShortLength(Stream, ArraySegment<byte>, CancellationToken)

Reads the short length using the specified from stream

internal static Task<uint> ReadShortLength(Stream fromStream, ArraySegment<byte> smallBuffer, CancellationToken cancellationToken)

Parameters

fromStream Stream

The from stream

smallBuffer ArraySegment<byte>

The small buffer

cancellationToken CancellationToken

The cancellation token

Returns

Task<uint>

A task containing the uint

ValidateLength(uint)

Validates the length using the specified len

internal static void ValidateLength(uint len)

Parameters

len uint

The len

Exceptions

ArgumentOutOfRangeException

Payload length out of range. Min 0 max 2GB. Actual {len:#,##0} bytes.