private final boolean message_ready ()
    {
        //  Destroy content of the old message.
        //in_progress.close ();

        //  Read new message. If there is none, return false.
        //  Note that new state is set only if write is successful. That way
        //  unsuccessful write will cause retry on the next state machine
        //  invocation.
        
        if (msg_source == null)
            return false;
        
        in_progress = msg_source.pull_msg ();
        if (in_progress == null) {
            return false;
        }

        //  Get the message size.
        int size = in_progress.size ();

        //  Account for the 'flags' byte.
        size++;

        //  For messages less than 255 bytes long, write one byte of message size.
        //  For longer messages write 0xff escape character followed by 8-byte
        //  message size. In both cases 'flags' field follows.
        
        if (size < 255) {
            tmpbuf[0] = (byte)size;
            tmpbuf[1] = (byte) (in_progress.flags () & Msg.more);
            next_step (tmpbuf, 2, size_ready, false);
        }
        else {
            ByteBuffer b = ByteBuffer.wrap(tmpbuf);
            b.put((byte)0xff);
            b.putLong(size);
            b.put((byte) (in_progress.flags () & Msg.more));
            next_step (tmpbuf, 10, size_ready, false);
        }
        
        return true;
    }