[WebSocket] Messaging
Fluent interface on MessageInterface::addFrame RFC6455 Message unit tests RFC handling TCP concatenation (refs #31)
This commit is contained in:
parent
0326ac99bd
commit
8e30b861c7
@ -21,13 +21,17 @@ class MessageParser {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Check frame
|
||||
// If is control frame, do your thing
|
||||
// Else, add to message
|
||||
// Control frames (ping, pong, close) can be sent in between a fragmented message
|
||||
|
||||
$nextFrame = $from->WebSocket->version->newFrame();
|
||||
$nextFrame->addBuffer($from->WebSocket->frame->extractOverflow());
|
||||
|
||||
$from->WebSocket->message->addFrame($from->WebSocket->frame);
|
||||
unset($from->WebSocket->frame);
|
||||
$from->WebSocket->frame = $nextFrame;
|
||||
}
|
||||
|
||||
if ($from->WebSocket->message->isCoalesced()) {
|
||||
|
@ -36,6 +36,8 @@ class Message implements MessageInterface {
|
||||
}
|
||||
|
||||
$this->_frame = $fragment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,7 @@ interface MessageInterface {
|
||||
|
||||
/**
|
||||
* @param FragmentInterface
|
||||
* @return MessageInterface
|
||||
*/
|
||||
function addFrame(FrameInterface $fragment);
|
||||
|
||||
|
@ -35,7 +35,6 @@ class Frame implements FrameInterface {
|
||||
* @param bool Mask the payload
|
||||
* @return Frame
|
||||
* @throws InvalidArgumentException If the payload is not a valid UTF-8 string
|
||||
* @throws BadMethodCallException If there is a problem with miss-matching parameters
|
||||
* @throws LengthException If the payload is too big
|
||||
*/
|
||||
public static function create($payload, $final = true, $opcode = 1, $mask = false) {
|
||||
@ -45,10 +44,6 @@ class Frame implements FrameInterface {
|
||||
throw new \InvalidArgumentException("Payload is not a valid UTF-8 string");
|
||||
}
|
||||
|
||||
if (false === (boolean)$final && $opcode !== static::OP_CONTINUE) {
|
||||
throw new \BadMethodCallException("opcode MUST be 'continue' if the frame is not final");
|
||||
}
|
||||
|
||||
$raw = (int)(boolean)$final . sprintf('%07b', (int)$opcode);
|
||||
|
||||
$plLen = strlen($payload);
|
||||
|
@ -39,6 +39,8 @@ class Message implements MessageInterface {
|
||||
*/
|
||||
public function addFrame(FrameInterface $fragment) {
|
||||
$this->_frames->push($fragment);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,6 +64,7 @@ class Message implements MessageInterface {
|
||||
try {
|
||||
$len += $frame->getPayloadLength();
|
||||
} catch (\UnderflowException $e) {
|
||||
// Not an error, want the current amount buffered
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +76,7 @@ class Message implements MessageInterface {
|
||||
*/
|
||||
public function getPayload() {
|
||||
if (!$this->isCoalesced()) {
|
||||
throw new \UnderflowMessage('Message has not been put back together yet');
|
||||
throw new \UnderflowException('Message has not been put back together yet');
|
||||
}
|
||||
|
||||
$buffer = '';
|
||||
|
Loading…
Reference in New Issue
Block a user