private void unplug () {
        assert (plugged);
        plugged = false;

        //  Cancel all fd subscriptions.
        if (io_enabled) {
            io_object.rm_fd (handle);
            io_enabled = false;
        }

        //  Disconnect from I/O threads poller object.
        io_object.unplug ();

        //  Disconnect from session object.
        if (encoder != null)
            encoder.set_msg_source (null);
        if (decoder != null)
            decoder.set_msg_sink (null);
        session = null;
    }