Skip to content

Commit

Permalink
Merge pull request #9 from voryx/ab-tests
Browse files Browse the repository at this point in the history
Fixed problem with PING payload getting added to message. Passes more tests
  • Loading branch information
cboden committed Sep 4, 2014
2 parents 4719a2a + 48b5542 commit fd3b817
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/WebSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,47 +91,53 @@ private function handleData($data) {
$this->_message = new Message;
}
if (!$this->_frame) {
$this->_frame = new Frame;
$this->_message->addFrame($this->_frame);
$frame = new Frame();
} else {
$frame = $this->_frame;
}

$this->_frame->addBuffer($data);
$frame->addBuffer($data);

if ($this->_frame->isCoalesced()) {
$opcode = $this->_frame->getOpcode();
if ($frame->isCoalesced()) {
$opcode = $frame->getOpcode();

if ($opcode > 2) {
if ($this->_frame->getPayloadLength() > 125 || !$this->_frame->isFinal()) {
if ($frame->getPayloadLength() > 125 || !$frame->isFinal()) {
$this->close(Frame::CLOSE_PROTOCOL);
return;
}

switch ($opcode) {
case Frame::OP_CLOSE:
$this->close($this->_frame->getPayload());
$this->close($frame->getPayload());

return;
case Frame::OP_PING:
$this->send(new Frame($this->_frame->getPayload(), true, Frame::OP_PONG));
$this->send(new Frame($frame->getPayload(), true, Frame::OP_PONG));
break;
case Frame::OP_PONG:
$this->emit('pong', [$this->_frame, $this]);
$this->emit('pong', [$frame, $this]);
break;
default:
$this->close($this->_frame->getPayload());
$this->close($frame->getPayload());
return;
}
}

$overflow = $this->_frame->extractOverflow();
$overflow = $frame->extractOverflow();

$this->_frame = null;

// if this is a control frame, then we aren't going to be coalescing
// any message, just handle overflowing stuff now and return
if ($opcode > 2) {
$this->handleData($overflow);
return;
} else {
$this->_message->addFrame($frame);
}
} else {
$this->_frame = $frame;
}

if (!$this->_message->isCoalesced()) {
Expand Down

0 comments on commit fd3b817

Please sign in to comment.