public Msg read()
    {
        if (!in_active || (state != State.active && state != State.pending))
            return null;

        Msg msg_ = inpipe.read ();

        if (msg_ == null) {
            in_active = false;
            return null;
        }

        //  If delimiter was read, start termination process of the pipe.
        if (msg_.is_delimiter ()) {
            delimit ();
            return null;
        }

        if (!msg_.has_more())
            msgs_read++;

        if (lwm > 0 && msgs_read % lwm == 0)
            send_activate_write (peer, msgs_read);

        return msg_;
    }