Esempio n. 1
0
 /**
  * Try to read a frame from the server.
  *
  * @return Frame|false when no frame to read
  * @throws ConnectionException
  * @throws ErrorFrameException
  */
 public function readFrame()
 {
     if ($this->parser->hasBufferedFrames()) {
         return $this->parser->getFrame();
     }
     if (!$this->hasDataToRead()) {
         return false;
     }
     // See if there are newlines waiting to be processed (some brokers send empty lines as heartbeat)
     $this->gobbleNewLines();
     do {
         $read = @stream_get_line($this->connection, 8192, Parser::FRAME_END);
         if ($read === false || $read === '') {
             throw new ConnectionException('Was not possible to read data from stream.', $this->activeHost);
         }
         $this->parser->addData($read);
         // Include zero-byte back at the end
         if (strlen($read) != 8192) {
             $this->parser->addData(Parser::FRAME_END);
         }
     } while (!$this->parser->parse());
     // See if there are newlines after the \0
     $this->gobbleNewLines();
     $frame = $this->parser->getFrame();
     if ($frame->isErrorFrame()) {
         throw new ErrorFrameException($frame);
     }
     return $frame;
 }
Esempio n. 2
0
 public function testParseFrameTransformsToFrameByDefault()
 {
     $body = 'var';
     $msg = "CMD\nheader1:value1\n\n\n" . $body . "";
     $parser = new Parser();
     $parser->addData($msg);
     $parser->parse();
     $result = $parser->getFrame();
     $this->assertInstanceOf('\\Stomp\\Frame', $result);
     $this->assertEquals('var', $result->body);
     $this->assertEquals('value1', $result->headers['header1']);
 }
Esempio n. 3
0
 public function testParseFrameTransformsToFrameZeroByteContent()
 {
     $body = "varvar2";
     $msg = "CMD\nheader1:value1\ncontent-length:" . strlen($body) . "\n\n" . $body . "";
     $parser = new Parser();
     $parser->addData($msg);
     $parser->parse();
     $result = $parser->getFrame();
     $this->assertInstanceOf('\\Stomp\\Frame', $result);
     $this->assertEquals($body, $result->body);
     $this->assertEquals('value1', $result->headers['header1']);
 }
Esempio n. 4
0
 /**
  * Try to read a frame from the server.
  *
  * @return Frame|false when no frame to read
  * @throws ConnectionException
  * @throws ErrorFrameException
  */
 public function readFrame()
 {
     if ($this->parser->hasBufferedFrames()) {
         return $this->parser->getFrame();
     }
     if (!$this->hasDataToRead()) {
         return false;
     }
     do {
         $read = @fread($this->connection, 1024);
         if ($read === false || $read === '') {
             throw new ConnectionException('Was not possible to read data from stream.', $this->activeHost);
         }
         $this->parser->addData($read);
     } while (!$this->parser->parse());
     $frame = $this->parser->getFrame();
     if ($frame->isErrorFrame()) {
         throw new ErrorFrameException($frame);
     }
     return $frame;
 }