Gets an array of client connections whose sockets were read

@param array &$read an array of sockets that were read.

@return array an array of {@link Net_Notifier_WebSocket_Connection}
objects having sockets found in the given array of read
sockets.
502811
protected function &getReadClients(&$read)
    {
        $clients = array();

        foreach ($this->clients as $client) {
            if (in_array($client->getSocket()->getRawSocket(), $read)) {
                $clients[] = $client;
            }
        }

        return $clients;
    }
1371971
protected function getConnectionForClientSocket($socket): ?Connection
    {
        if (!isset($this->connections[$this->resourceId($socket)])) {
            return null;
        }
        return $this->connections[$this->resourceId($socket)];
    }
1265386
public function readStream($path) {
        $mapping = $this->mapper->get($path);

        if (!$mapping) {
            return false;
        }

        try {
            $file = $this->client->get($mapping['fid']);

            if (!$file) {
                return false;
            }

            return [
                'stream' => $file
            ];
        } catch (SeaweedFSException $e) {
            return false;
        }
    }
1188624
public function getReadConnection(Server $preferredServer = null) : IConnection
    {
        if ($preferredServer !== null) {
            $this->addServer('custom', $preferredServer);
            $this->setReadConnection($preferredServer);
        } elseif ($this->readConnection == null) {
            $this->setReadConnection();
        }

        return $this->readConnection;
    }
1214104
public function read()
    {
        $rarray = [];
        $count = 0;

        while ($data = fread($this->socket, 4)) {
            $data = unpack('V1Size', $data);

            if ($data['Size'] > 4096) {
                $packet = '';
                for ($i = 0; $i < 8; $i++) {
                    $packet .= "\x00";
                }
                $packet .= fread($this->socket, 4096);
            } else {
                $packet = fread($this->socket, $data['Size']);
            }

            $rarray[] = unpack('V1ID/V1Response/a*S1/a*S2', $packet);
        }

        return $rarray;
    }
949742
public function getStreamHeaders($connection = null)
    {
        if ($connection == null) {
            $connection = $this->httpFilePointer;
        }
        $headers = [];
        if ($connection !== false) {
            $metaData = stream_get_meta_data($connection);
            // The structure of this array differs depending on PHP compiled with
            // --enable-curlwrappers or not. Both cases are normally required.
            $rawHeaders = isset($metaData['wrapper_data']['headers'])
                ? $metaData['wrapper_data']['headers'] : $metaData['wrapper_data'];

            foreach ($rawHeaders as $lineContent) {
                // Extract header values
                if (preg_match('(^HTTP/(?P<version>\d+\.\d+)\s+(?P<status>\d+))S', $lineContent, $match)) {
                    $headers['version'] = $match['version'];
                    $headers['status'] = (int) $match['status'];
                } else {
                    list($key, $value) = explode(':', $lineContent, 2);
                    $headers[strtolower($key)] = ltrim($value);
                }
            }
        }

        return $headers;
    }
751428
private function readLinearRings($count)
    {
        $rings = array();

        for ($i = 0; $i < $count; $i++) {
            $rings[] = $this->readPoints($this->readCount());
        }

        return $rings;
    }
392591
async function getReadersUuids(channelName, paths) {
    paths = paths || getPaths(channelName);
    const readersPath = paths.readers;
    const files = await readdir(readersPath);

    return files
        .map(file => file.split('.'))
        .filter(split => split[1] === 'json') // do not scan .socket-files
        .map(split => split[0]);
}
568281
public function getSockets() {
        $sockets = array();
        $servers = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL,
            Mage::getStoreConfig('turpentine_varnish/servers/server_list'));
        $key = str_replace('\n', PHP_EOL,
            Mage::getStoreConfig('turpentine_varnish/servers/auth_key'));
        $version = Mage::getStoreConfig('turpentine_varnish/servers/version');
        if ($version == 'auto') {
            $version = null;
        }
        foreach ($servers as $server) {
            $parts = explode(':', $server);
            $sockets[] = $this->getSocket($parts[0], $parts[1], $key, $version);
        }
        return $sockets;
    }
843739
public function readMany($keys)
    {
        $cacheKeys = [];
        foreach ($keys as $key) {
            $cacheKeys[] = $this->_key($key);
        }

        $values = $this->_Memcached->getMulti($cacheKeys);
        $return = [];
        foreach ($keys as &$key) {
            $return[$key] = array_key_exists($this->_key($key), $values) ?
                $values[$this->_key($key)] : false;
        }

        return $return;
    }
503359
protected function getGrantedNodes(array $nodes)
    {
        /**
         * @var ReadNodeInterface $node
         */
        foreach ($nodes as $key => $node) {
            if (!$this->isGrantedNode($node)) {
                unset($nodes[$key]);
            }
        }

        return $nodes;
    }
321610
protected function connectSocket(array $host)
    {
        $this->activeHost = $host;
        $errNo = null;
        $errStr = null;

        $context = stream_context_create($this->context);
        $flags = STREAM_CLIENT_CONNECT;
        if ($this->persistentConnection) {
            $flags |= STREAM_CLIENT_PERSISTENT;
        }
        $socket = @stream_socket_client(
            $host['scheme'] . '://' . $host['host'] . ':' . $host['port'],
            $errNo,
            $errStr,
            $this->connectTimeout,
            $flags,
            $context
        );


        if (!is_resource($socket)) {
            throw new ConnectionException(sprintf('Failed to connect. (%s: %s)', $errNo, $errStr), $host);
        }

        if (!@stream_set_blocking($socket, false)) {
            throw new ConnectionException('Failed to set non blocking mode for stream.', $host);
        }
        $this->host = $host['host'];
        return $socket;
    }
703748
public function getResponses(array $sockets, $timeout, $stream_timeout)
    {

        // Set the loop to active
        $loop_active = true;

        // Will hold the responses read from the sockets
        $responses = [];

        // To store the sockets
        $sockets_tmp = [];

        // Loop and pull out all the actual sockets we need to listen on
        foreach ($sockets as $socket_id => $socket_data) {
            // Get the socket
            /* @var $socket \GameQ\Query\Core */
            $socket = $socket_data['socket'];

            // Append the actual socket we are listening to
            $sockets_tmp[$socket_id] = $socket->get();

            unset($socket);
        }

        // Init some variables
        $read = $sockets_tmp;
        $write = null;
        $except = null;

        // Check to see if $read is empty, if so stream_select() will throw a warning
        if (empty($read)) {
            return $responses;
        }

        // This is when it should stop
        $time_stop = microtime(true) + $timeout;

        // Let's loop until we break something.
        while ($loop_active && microtime(true) < $time_stop) {
            // Check to make sure $read is not empty, if so we are done
            if (empty($read)) {
                break;
            }

            // Now lets listen for some streams, but do not cross the streams!
            $streams = stream_select($read, $write, $except, 0, $stream_timeout);

            // We had error or no streams left, kill the loop
            if ($streams === false || ($streams <= 0)) {
                break;
            }

            // Loop the sockets that received data back
            foreach ($read as $socket) {
                /* @var $socket resource */

                // See if we have a response
                if (($response = fread($socket, 8192)) === false) {
                    continue; // No response yet so lets continue.
                }

                // Check to see if the response is empty, if so we are done with this server
                if (strlen($response) == 0) {
                    // Remove this server from any future read loops
                    unset($sockets_tmp[(int)$socket]);
                    continue;
                }

                // Add the response we got back
                $responses[(int)$socket][] = $response;
            }

            // Because stream_select modifies read we need to reset it each time to the original array of sockets
            $read = $sockets_tmp;
        }

        // Free up some memory
        unset($streams, $read, $write, $except, $sockets_tmp, $time_stop, $response);

        // Return all of the responses, may be empty if something went wrong
        return $responses;
    }
1356206
private AsyncConnections getConnections(Iterable<RedisNodeDescription> nodes) {

        List<RedisNodeDescription> nodeList = LettuceLists.newList(nodes);
        AsyncConnections connections = new AsyncConnections(nodeList);

        for (RedisNodeDescription node : nodeList) {

            RedisURI redisURI = node.getUri();
            String message = String.format("Unable to connect to %s", redisURI);
            try {
                CompletableFuture<StatefulRedisConnection<String, String>> connectionFuture = nodeConnectionFactory
                        .connectToNodeAsync(CODEC, redisURI);

                CompletableFuture<StatefulRedisConnection<String, String>> sync = new CompletableFuture<>();

                connectionFuture.whenComplete((connection, throwable) -> {

                    if (throwable != null) {

                        if (throwable instanceof RedisConnectionException) {
                            if (logger.isDebugEnabled()) {
                                logger.debug(throwable.getMessage(), throwable);
                            } else {
                                logger.warn(throwable.getMessage());
                            }
                        } else {
                            logger.warn(message, throwable);
                        }

                        sync.completeExceptionally(new RedisConnectionException(message, throwable));
                    } else {
                        connection.async().clientSetname("lettuce#MasterSlaveTopologyRefresh");
                        sync.complete(connection);
                    }
                });

                connections.addConnection(redisURI, sync);
            } catch (RuntimeException e) {
                logger.warn(String.format(message, redisURI), e);
            }
        }

        return connections;
    }
957828
protected function readSocket($compress = true)
    {
        $buffer = '';
        $overload = strlen('000000:000:000:');
        do {
            $buf = $this->socket->read($overload + self::BLOCK_SIZE, PHP_BINARY_READ);
            if (false === $buf) {
                throw new SocketReadException($this->socket->lastErrorAsString());
            }

            if (!trim($buf)) {
                return '';
            }

            if (substr_count($buf, ":") < 3) {
                throw new SignatureSocketException('error in format');
            }

            list($size, $block, $blocks) = explode(":", $buf);

            $aux = substr($buf, $overload);

            $this->sprintfIfDebug("%d/%d blocks (start of block %s)\n", $block, $blocks, substr($aux, 0, 10));

            $this->output->write('R');

            if ($size == strlen($aux)) {
                $this->send(self::ACK);
            } else {
                $this->send(self::NO_ACK);
                throw new BlockSizeSocketException(
                    sprintf(
                        'error in size (block %d of %d): informed %d vs %d read',
                        $block, $blocks, $size, strlen($aux)
                    )
                );
            }

            $buffer .= $aux;
        } while ($block < $blocks);

        $result = $compress ? $this->uncompress($buffer) : $buffer;

        if ($this->debug) {
            $aux = json_decode($result, true);
            if (isset($aux['data'])) {
                $this->output->writeln("received %d keys", count($aux['data']));
            }
        }

        return $result;
    }
1301243
public function mGet(array $keyArray)
    {
        if (empty($keyArray)) return [];

        $keyArray = array_values($keyArray);

        $result     = [];
        $redisServer    = $this->redisServer;
        if (1 == $redisServer->getServerCount()) {
            $dataArray      = $redisServer->getDefaultClient()->getMultiple($keyArray);
            foreach ($dataArray as $k => $v) {
                if (false !== $v) {
                    $result[$keyArray[$k]] = is_numeric($v) ? $v : unserialize($v);
                }
            }
        } else {
            $clientKeyArray = [];
            foreach ($keyArray as $key) {
                $name   = $redisServer->getHashClientName($key);
                // factory key array for redis
                if (isset($clientKeyArray[$name])) {
                    $clientKeyArray[$name][] = $key;
                } else {
                    $clientKeyArray[$name] = [$key];
                }
            }

            foreach ($clientKeyArray as $name => $keyArray) {
                $dataArray = $redisServer->getClient($name)->mget($keyArray);
                foreach ($dataArray as $k => $v) {
                    if (false !== $v) {
                        $result[$keyArray[$k]] = is_numeric($v) ? $v : unserialize($v);
                    }
                }
            }
        }

        return $result;
    }
721059
protected function _rawread($n)
    {
        if ($this->_bufferedInput) {
            $result = '';
            $read = 0;
            while ($read < $n && !feof($this->_bufferedInput->realSock()) &&
                   (false !== ($buffer = fread($this->_bufferedInput->realSock(), $n - $read)))
            ) {
                // get status of socket to determine whether or not it has timed out
                $info = stream_get_meta_data($this->_bufferedInput->realSock());
                if($info['timed_out']) {
                    throw new \Exception('Error reading data. Socket connection timed out');
                }

                $read += strlen($buffer);
                $result .= $buffer;
            }

            if (strlen($result) != $n) {
                throw new \Exception(
                    sprintf(
                            'Error reading data. Recevived %d instead of '.
                            'expected %d bytes', strlen($result), $n
                         )
                    );
            }

            $this->_offset += $n;
        } else {
            if (strlen($this->_str) < $n) {
                throw new \Exception(
                    sprintf(
                        'Error reading data. Requested %d bytes while string '.
                        'buffer has only %s', $n, strlen($this->_str)
                    )
                );
            }
            $result = substr($this->_str, 0, $n);
            $this->_str = substr($this->_str, $n);
            $this->_offset += $n;
        }
        return $result;
    }