Skip to content

Commit

Permalink
Refactored websocket frame logic to index arrays with size_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlalis committed Feb 16, 2024
1 parent 7926904 commit 4a22ed4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions source/handy_httpd/components/websocket/frame.d
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ WebSocketFrame receiveWebSocketFrame(S)(S stream) if (isByteInputStream!S) {
immutable bool payloadMasked = (maskAndLength & 128) > 0;
immutable ubyte initialPayloadLength = maskAndLength & 127;
debugF!"Websocket data frame Mask bit = %s, Initial payload length = %d"(payloadMasked, initialPayloadLength);
ulong payloadLength = readPayloadLength(initialPayloadLength, ptr);
size_t payloadLength = readPayloadLength(initialPayloadLength, ptr);
if (isControlFrame && payloadLength > 125) {
throw new WebSocketException("Control frame payload is too large.");
}
Expand Down Expand Up @@ -223,13 +223,13 @@ private bool validateOpcode(ubyte opcode) {
* stream = The stream to read from.
* Returns: The complete payload length.
*/
private ulong readPayloadLength(S)(ubyte initialLength, S stream) if (isByteInputStream!S) {
private size_t readPayloadLength(S)(ubyte initialLength, S stream) if (isByteInputStream!S) {
if (initialLength == 126) {
return readDataOrThrow!(ushort)(stream);
return cast(size_t) readDataOrThrow!(ushort)(stream);
} else if (initialLength == 127) {
return readDataOrThrow!(ulong)(stream);
return cast(size_t) readDataOrThrow!(ulong)(stream);
}
return initialLength;
return cast(size_t) initialLength;
}

/**
Expand All @@ -240,7 +240,7 @@ private ulong readPayloadLength(S)(ubyte initialLength, S stream) if (isByteInpu
* stream = The stream to read from.
* Returns: The payload data that was read.
*/
private ubyte[] readPayload(S)(ulong payloadLength, S stream) if (isByteInputStream!S) {
private ubyte[] readPayload(S)(size_t payloadLength, S stream) if (isByteInputStream!S) {
ubyte[] buffer = new ubyte[payloadLength];
StreamResult readResult = stream.readFromStream(buffer);
if (readResult.hasError) {
Expand Down

0 comments on commit 4a22ed4

Please sign in to comment.