[WebSocket] Frame concatenation
If the server receives two frames that have been concatenated (RFC only) they're not separated properly
This commit is contained in:
parent
7c9b2ae227
commit
53354cd967
@ -75,4 +75,8 @@ class Frame implements FrameInterface {
|
|||||||
|
|
||||||
return substr($this->_data, 1, strlen($this->_data) - 2);
|
return substr($this->_data, 1, strlen($this->_data) - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function extractOverflow() {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
@ -38,7 +38,7 @@ class Frame implements FrameInterface {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $payload_length + $payload_start === $this->_bytes_rec;
|
return $this->_bytes_rec >= $payload_length + $payload_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -223,4 +223,26 @@ class Frame implements FrameInterface {
|
|||||||
|
|
||||||
return $payload;
|
return $payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sometimes clients will concatinate more than one frame over the wire
|
||||||
|
* This method will take the extra bytes off the end and return them
|
||||||
|
* @todo Consider returning new Frame
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function extractOverflow() {
|
||||||
|
if ($this->isCoalesced()) {
|
||||||
|
$endPoint = $this->getPayloadLength();
|
||||||
|
$endPoint += $this->getPayloadStartingByte();
|
||||||
|
|
||||||
|
if ($this->_bytes_rec > $endPoint) {
|
||||||
|
$overflow = substr($this->_data, $endPoint);
|
||||||
|
$this->_data = substr($this->_data, 0, $endPoint);
|
||||||
|
|
||||||
|
return $overflow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
@ -122,7 +122,10 @@ class WsServer implements MessageComponentInterface {
|
|||||||
// Control frames (ping, pong, close) can be sent in between a fragmented message
|
// Control frames (ping, pong, close) can be sent in between a fragmented message
|
||||||
|
|
||||||
$from->WebSocket->message->addFrame($from->WebSocket->frame);
|
$from->WebSocket->message->addFrame($from->WebSocket->frame);
|
||||||
|
$nextFrame = $from->WebSocket->version->newFrame();
|
||||||
|
$nextFrame->addBuffer($from->WebSocket->frame->extractOverflow());
|
||||||
unset($from->WebSocket->frame);
|
unset($from->WebSocket->frame);
|
||||||
|
$from->WebSocket->frame = $nextFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($from->WebSocket->message->isCoalesced()) {
|
if ($from->WebSocket->message->isCoalesced()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user