Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored types in frame to use size_t (#fix 34) #35

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 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,11 +223,11 @@ 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);
} else if (initialLength == 127) {
return readDataOrThrow!(ulong)(stream);
return readDataOrThrow!(size_t)(stream);
Comment on lines +226 to +230
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specification requires that the payload length be encoded as 64 bits if the initial length is 127, so it's gotta stay as readDataOrThrow!(ulong)(stream). I guess the best thing to do would be return cast(size_t) readDataOrThrow!(ulong)(stream);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, the frame length could be 64bit, but if I use ulong in 32 arm the compiler complains. I could do a cast from ulong to uint, but if actually the package is bigger than uint it generates a conversion error.... I have to think more about it. Thanks for the great support

}
return 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 Expand Up @@ -288,4 +288,4 @@ private void unmaskData(ubyte[] buffer, ubyte[4] mask) {
for (size_t i = 0; i < buffer.length; i++) {
buffer[i] = buffer[i] ^ mask[i % 4];
}
}
}
Loading