/**
  * Waits for a frame from the server
  *
  * @param int $timeout
  * @return array
  * @throws Exception
  * @throws PhpAmqpLib_Exception_AMQPTimeoutException
  * @throws PhpAmqpLib_Exception_AMQPRuntimeException
  */
 protected function wait_frame($timeout = 0)
 {
     if (is_null($this->input)) {
         $this->setIsConnected(false);
         throw new PhpAmqpLib_Exception_AMQPRuntimeException('Broken pipe or closed connection');
     }
     $currentTimeout = $this->input->getTimeout();
     $this->input->setTimeout($timeout);
     try {
         // frame_type + channel_id + size
         $this->wait_frame_reader->reuse($this->input->read(PhpAmqpLib_Wire_AMQPReader::OCTET + PhpAmqpLib_Wire_AMQPReader::SHORT + PhpAmqpLib_Wire_AMQPReader::LONG));
         $frame_type = $this->wait_frame_reader->read_octet();
         $channel = $this->wait_frame_reader->read_short();
         $size = $this->wait_frame_reader->read_long();
         // payload + ch
         $this->wait_frame_reader->reuse($this->input->read(PhpAmqpLib_Wire_AMQPReader::OCTET + (int) $size));
         $payload = $this->wait_frame_reader->read($size);
         $ch = $this->wait_frame_reader->read_octet();
     } catch (PhpAmqpLib_Exception_AMQPTimeoutException $e) {
         $this->input->setTimeout($currentTimeout);
         throw $e;
     }
     $this->input->setTimeout($currentTimeout);
     if ($ch != 0xce) {
         throw new PhpAmqpLib_Exception_AMQPRuntimeException(sprintf('Framing error, unexpected byte: %x', $ch));
     }
     return array($frame_type, $channel, $payload);
 }