/**
  * Custom hacky buffer-complete check to avoid potential infinite loops
  * in the standard XMPPHP library.
  * 
  * {@inheritdoc}
  */
 protected function bufferComplete($buff)
 {
     $complete = parent::bufferComplete($buff);
     // TODO: Submit fixes to XMPPHP
     if (!$complete) {
         // Fix the bug on disconnect
         if ($this->sent_disconnect) {
             if ($buff === $this->stream_end) {
                 $complete = true;
             }
         }
     }
     if (!$complete && $this->numIncomplete > 0 && $this->numIncomplete % $this->expensiveIterations === 0) {
         // Check for a complete but stuck buffer
         $complete = $this->isMultipleElements($buff);
     }
     if (!$complete && $this->numIncomplete > $this->maxIncompleteIterations) {
         // Hack to bail out if the buffer is disconnected
         throw new Exception\TimeoutException("Incomplete buffer after " . $this->maxIncompleteIterations . " polling iterations.");
     }
     // Reset or advance our running tally of iterations
     if ($complete || $buff !== $this->prevBuffer) {
         $this->numIncomplete = 0;
     } else {
         $this->numIncomplete++;
     }
     // Store the current buffer so we can compare to the next one received
     $this->prevBuffer = $buff;
     return $complete;
 }