Example #1
0
 /**
  * Dispatches the next response in queue.
  * 
  * Dispatches the next response in queue, i.e. it executes the associated
  * callback if there is one, or places the response in the response buffer.
  * 
  * @param int $sTimeout  If a response is not immediatly available, wait
  *     this many seconds. If NULL, wait indefinetly.
  * @param int $usTimeout Microseconds to add to the waiting time.
  * 
  * @throws SocketException When there's no response within the time limit.
  * @return Response The dispatched response.
  */
 protected function dispatchNextResponse($sTimeout = 0, $usTimeout = 0)
 {
     $response = new Response($this->com, $this->_streamingResponses, $sTimeout, $usTimeout, $this->registry);
     if ($response->getType() === Response::TYPE_FATAL) {
         $this->pendingRequestsCount = 0;
         $this->com->close();
         return $response;
     }
     $tag = $response->getTag();
     $isLastForRequest = $response->getType() === Response::TYPE_FINAL;
     if ($isLastForRequest) {
         $this->pendingRequestsCount--;
     }
     if ('' != $tag) {
         if ($this->isRequestActive($tag, self::FILTER_CALLBACK)) {
             if ($this->callbacks[$tag]($response, $this)) {
                 $this->cancelRequest($tag);
             } elseif ($isLastForRequest) {
                 unset($this->callbacks[$tag]);
             }
         } else {
             $this->responseBuffer[$tag][] = $response;
         }
     }
     return $response;
 }