Amp\Artax\SocketPool::checkoutExistingSocket PHP Method

checkoutExistingSocket() private method

private checkoutExistingSocket ( $uri, $options )
    private function checkoutExistingSocket($uri, $options)
    {
        if (empty($this->sockets[$uri])) {
            return null;
        }
        $needsRebind = false;
        foreach ($this->sockets[$uri] as $socketId => $poolStruct) {
            if (!$poolStruct->isAvailable) {
                continue;
            } elseif ($this->isSocketDead($poolStruct->resource)) {
                unset($this->sockets[$uri][$socketId]);
            } elseif (($bindToIp = @stream_context_get_options($poolStruct->resource)['socket']['bindto']) && $bindToIp == $options[self::OP_BINDTO]) {
                $poolStruct->isAvailable = false;
                \Amp\disable($poolStruct->idleWatcher);
                return $poolStruct->resource;
            } elseif ($bindToIp) {
                $needsRebind = true;
            } else {
                $poolStruct->isAvailable = false;
                \Amp\disable($poolStruct->idleWatcher);
                return $poolStruct->resource;
            }
        }
        $this->needsRebind = $needsRebind;
        return null;
    }