[WebSocket] Re-scoped variable

Protecting Frame::$data to prevent overflow error
Correct frame contents is fetched from ::getContents()
This commit is contained in:
Chris Boden 2012-06-14 10:54:26 -04:00
parent 305865a938
commit 412f5c2d07
3 changed files with 14 additions and 11 deletions

View File

@ -177,7 +177,7 @@ class RFC6455 implements VersionInterface {
* @return string
*/
public function frame($message, $mask = true) {
return $this->newFrame($message)->data;
return $this->newFrame($message)->getContents();
}
/**

View File

@ -14,23 +14,18 @@ class Connection extends AbstractConnectionDecorator {
}
public function send($msg) {
if ($msg instanceof FrameInterface) {
$data = $msg->data;
} else {
$frame = new Frame($msg);
$data = $frame->data;
if (!($msg instanceof FrameInterface)) {
$msg = new Frame($msg);
}
$this->getConnection()->send($data);
$this->getConnection()->send($msg->getContents());
}
/**
* {@inheritdoc}
*/
public function close($code = 1000) {
$frame = new Frame($code, true, Frame::OP_CLOSE);
$this->send($frame->data);
$this->send(new Frame($code, true, Frame::OP_CLOSE));
$this->getConnection()->close();
}

View File

@ -29,7 +29,7 @@ class Frame implements FrameInterface {
* The contents of the frame
* @var string
*/
public $data = '';
protected $data = '';
/**
* Number of bytes received from the frame
@ -367,6 +367,14 @@ class Frame implements FrameInterface {
return $payload;
}
/**
* Get the raw contents of the frame
* @todo This is untested, make sure the substr is right - trying to return the frame w/o the overflow
*/
public function getContents() {
return substr($this->data, 0, $this->getPayloadStartingByte() + $this->getPayloadLength());
}
/**
* Sometimes clients will concatinate more than one frame over the wire
* This method will take the extra bytes off the end and return them