Private
Public Access
1
0

pingpong prevent superclass from handling rest of ping frame

This commit is contained in:
2025-06-13 14:50:13 -07:00
parent e1ec237053
commit d706435103

View File

@@ -126,6 +126,7 @@
payload = [unmaskedPayload copy];
}
NSLog(@"Sending pong response to ping with payload length: %lu", (unsigned long)[payload length]);
[self sendPongWithPayload:payload socket:sock];
// Continue reading the next frame
@@ -133,23 +134,22 @@
return;
}
// Intercept after masking key is read for ping/pong frames
if (tag == TAG_MSG_MASKING_KEY && (nextOpCode == WS_OP_PING || nextOpCode == WS_OP_PONG)) {
// Store the masking key
maskingKey = [data copy];
// We need to determine the payload length and read it
// The parent class should have stored this somewhere, but we'll need to track it
// For now, let's assume short payload and read what was scheduled
// Let parent handle TAG_PAYLOAD_PREFIX first to set nextOpCode
if (tag == TAG_PAYLOAD_PREFIX) {
[super socket:sock didReadData:data withTag:tag];
return;
}
// Intercept the payload length phase for ping/pong frames
if (tag == TAG_PAYLOAD_LENGTH && (nextOpCode == WS_OP_PING || nextOpCode == WS_OP_PONG)) {
// Now intercept ping/pong handling after nextOpCode is set
if (nextOpCode == WS_OP_PING || nextOpCode == WS_OP_PONG) {
if (tag == TAG_PAYLOAD_LENGTH) {
UInt8 frame = *(UInt8 *)[data bytes];
BOOL masked = (frame & 0x80) != 0;
NSUInteger length = frame & 0x7F;
nextFrameMasked = masked;
NSLog(@"Processing ping/pong frame, masked: %d, length: %lu", masked, (unsigned long)length);
if (length <= 125) {
if (nextFrameMasked) {
[asyncSocket readDataToLength:4 withTimeout:TIMEOUT_NONE tag:TAG_MSG_MASKING_KEY];
@@ -165,18 +165,17 @@
return;
}
// Handle extended length for ping/pong
if ((tag == TAG_PAYLOAD_LENGTH16 || tag == TAG_PAYLOAD_LENGTH64) && (nextOpCode == WS_OP_PING || nextOpCode == WS_OP_PONG)) {
NSUInteger length = 0;
if (tag == TAG_PAYLOAD_LENGTH16) {
UInt8 *pFrame = (UInt8 *)[data bytes];
length = ((NSUInteger)pFrame[0] << 8) | (NSUInteger)pFrame[1];
} else {
// For 64-bit length, this is complex - for now just close
[self didClose];
if (tag == TAG_MSG_MASKING_KEY) {
// Store the masking key
maskingKey = [data copy];
NSLog(@"Stored masking key for ping/pong frame");
return;
}
if (tag == TAG_PAYLOAD_LENGTH16) {
UInt8 *pFrame = (UInt8 *)[data bytes];
NSUInteger length = ((NSUInteger)pFrame[0] << 8) | (NSUInteger)pFrame[1];
if (nextFrameMasked) {
[asyncSocket readDataToLength:4 withTimeout:TIMEOUT_NONE tag:TAG_MSG_MASKING_KEY];
}
@@ -184,9 +183,15 @@
return;
}
if (tag == TAG_PAYLOAD_LENGTH64) {
// For 64-bit length, this is too complex for ping frames - just close
[self didClose];
return;
}
}
// For all other cases, call the parent implementation
[super socket:sock didReadData:data withTag:tag];
}