コード例 #1
0
ファイル: Registry.php プロジェクト: brucewu16899/routeros
 /**
  * Add a response to the registry.
  * 
  * @param Response $response     The response to add. The caller of this
  *     function is responsible for ensuring that the ownership tag and the
  *     original tag are separated, so that only the original one remains in
  *     the response.
  * @param string   $ownershipTag The ownership tag that the response had.
  * 
  * @return bool TRUE if the request was added to its buffer, FALSE if
  *     this instance owns the response, and therefore doesn't need to add
  *     the response to its buffer.
  */
 public function add(Response $response, $ownershipTag)
 {
     if ($this->getOwnershipTag() === $ownershipTag || $this->isTaglessModeOwner() && $response->getType() !== Response::TYPE_FATAL) {
         return false;
     }
     if (null === $ownershipTag) {
         $this->shm->lock('taglessModeOwner');
         if ($this->shm->exists('taglessModeOwner') && $response->getType() !== Response::TYPE_FATAL) {
             $ownershipTag = $this->shm->get('taglessModeOwner');
             $this->shm->unlock('taglessModeOwner');
         } else {
             $this->shm->unlock('taglessModeOwner');
             foreach ($this->shm->getIterator('/^(responseBuffer\\_)/', true) as $targetBufferName) {
                 $this->_add($response, $targetBufferName);
             }
             return true;
         }
     }
     $this->_add($response, 'responseBuffer_' . $ownershipTag);
     return true;
 }
コード例 #2
0
ファイル: Client.php プロジェクト: brucewu16899/routeros
 /**
  * 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 $timeout_s  If a response is not immediatly available, wait
  *     this many seconds. If NULL, wait indefinetly.
  * @param int $timeout_us 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($timeout_s = 0, $timeout_us = 0)
 {
     $response = new Response($this->com, $this->_streamingResponses, $timeout_s, $timeout_us, $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;
 }