public function read()
    {
        if ($this->socket === null) {
            return false;
        }

        if (feof($this->socket)) {
            return false;
        }

        $received = fread($this->socket, 4096);
        if ($received === false) {
            return false;
        }
        $this->incomingData .= $received;

        // Workaround for issue #8.
        $metadata = stream_get_meta_data($this->socket);
        if ($metadata['stream_type'] == 'tcp_socket/ssl' && !feof($this->socket)) {
            $blocking = (int) $metadata['blocked'];
            stream_set_blocking($this->socket, 0);
            $received = fread($this->socket, 4096);
            stream_set_blocking($this->socket, $blocking);

            if ($received !== false) {
                $this->incomingData .= $received;
            }
        }

        // Read all messages currently in the input buffer.
        while ($this->getLine()) {
            ; // Nothing more to do.
        }
        return true;
    }