protected boolean start() throws IOException {
        final ClickHouseConfig f = (ClickHouseConfig) this.selectionKey.attachment();
        final long socketTimeout = f.getSocketTimeout();

        try (SocketChannel c = getSocketChannel(); Selector s = this.selectionKey.selector()) {
            while (c.isOpen()) {
                if (s.select(c.isConnected() ? socketTimeout : f.getConnectionTimeout()) < 1) {
                    LockSupport.parkNanos(1L);
                }

                final Iterator<SelectionKey> keysIterator = s.selectedKeys().iterator();
                while (keysIterator.hasNext()) {
                    final SelectionKey key = keysIterator.next();
                    keysIterator.remove();

                    final SocketChannel sc = (SocketChannel) key.channel();
                    if (key.isValid() && key.isConnectable()) {
                        onConnect(f, sc);
                    }

                    final SocketRequest req = request.get();
                    if (req == null) {
                        continue;
                    }

                    if (key.isValid() && key.isWritable()) {
                        final ClickHouseInputStream in = req.in;
                        // socket output buffer was full due to slow/jammed network
                        long offset = (long) in.getUserData("offset", 0L);
                        if ((offset = onWrite(req.config, sc, in, offset)) > 0L && in.available() > 0) {
                            // processRequest(in, socketTimeout);
                        } else {
                            in.close();
                            removeInterestOp(SelectionKey.OP_WRITE);
                        }
                        in.setUserData("offset", offset);
                    }

                    if (key.isValid() && key.isReadable()) {
                        final ClickHouseOutputStream out = req.out;
                        if (onRead(req.config, sc, out)) {
                            log.trace("Reset request holder: %s", request.compareAndSet(req, null));
                            out.close();
                        } else {
                            throw new ConnectException("Failed to read");
                        }
                    }
                }
            }
        } catch (Throwable t) {
            final SocketRequest req = request.get();
            if (req != null && !req.isDone()) {
                req.error.compareAndSet(null, t);
                throw t;
            } else if (t instanceof ClosedSelectorException) {
                log.info("Socket channel between [%s] and [%s] was closed", localAddress(), remoteAddress());
            }
        } finally {
            close();
        }

        return true;
    }
Reads byte from socket input buffer.

@param config non-null configuration
@param sc     socket channel
@param out    output stream
@return true if the read was a success; false otherwise
@throws IOException
clickhouse-client/src/main/java/com/clickhouse/client/AbstractSocketClient.java