Created
June 7, 2015 18:09
-
-
Save benedmunds/b6f532e331cf9577aaec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function onData($data, MessageInterface $message = null, callable $onMessage, callable $onControl = null, $context = null) { | |
RECURSE: | |
$overflow = ''; | |
$onControl ?: $this->noop; | |
$message ?: $message = $this->newMessage(); | |
$prevFrame = null; | |
$frameCount = count($message); | |
if ($frameCount > 0) { | |
$frame = $message[$frameCount - 1]; | |
if ($frame->isCoalesced()) { | |
$prevFrame = $frame; | |
$frame = $this->newFrame(); | |
$message->addFrame($frame); | |
$frameCount++; | |
} elseif ($frameCount > 1) { | |
$prevFrame = $message[$frameCount - 2]; | |
} | |
} else { | |
$frame = $this->newFrame(); | |
$message->addFrame($frame); | |
$frameCount++; | |
} | |
$frame->addBuffer($data); | |
if ($frame->isCoalesced()) { | |
$frame = $this->frameCheck($frame, $prevFrame); | |
$opcode = $frame->getOpcode(); | |
if ($opcode > 2) { | |
$onControl($frame, $context); | |
unset($message[$frameCount - 1]); | |
$overflow = $frame->extractOverflow(); | |
if (strlen($overflow) > 0) { | |
$message = $this->onData($overflow, $message, $onMessage, $onControl, $context); | |
} | |
return $message; | |
} | |
$overflow = $frame->extractOverflow(); | |
$frame->unMaskPayload(); | |
} | |
if ($message->isCoalesced()) { | |
$msgCheck = $this->checkMessage($message); | |
if (true !== $msgCheck) { | |
$onControl($this->newCloseFrame($msgCheck), $context); | |
return $this->newMessage(); | |
} | |
$onMessage($message, $context); | |
$message = $this->newMessage(); | |
} | |
if (strlen($overflow) > 0) { | |
goto RECURSE; | |
//$this->onData($overflow, $message, $onMessage, $onControl, $context); | |
} | |
return $message; | |
} |
cboden
commented
Jun 7, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment