private void clean_pipes() 
    {
        if (pipe != null) {

            //  Get rid of half-processed messages in the out pipe. Flush any
            //  unflushed messages upstream.
            pipe.rollback ();
            pipe.flush ();

            //  Remove any half-read message from the in pipe.
            while (incomplete_in) {
                Msg msg = pull_msg ();
                if (msg == null) {
                    assert (!incomplete_in);
                    break;
                }
                msg.close ();
            }
        }
    }