static int vnc_update_client(VncState *vs, int has_dirty)

{

    if (vs->need_update && vs->csock != -1) {

        VncDisplay *vd = vs->vd;

        int y;

        int n_rectangles;

        int saved_offset;

        int n;



        if (vs->output.offset && !vs->audio_cap && !vs->force_update)

            /* kernel send buffers are full -> drop frames to throttle */

            return 0;



        if (!has_dirty && !vs->audio_cap && !vs->force_update)

            return 0;



        /*

         * Send screen updates to the vnc client using the server

         * surface and server dirty map.  guest surface updates

         * happening in parallel don't disturb us, the next pass will

         * send them to the client.

         */

        n_rectangles = 0;

        vnc_write_u8(vs, VNC_MSG_SERVER_FRAMEBUFFER_UPDATE);

        vnc_write_u8(vs, 0);

        saved_offset = vs->output.offset;

        vnc_write_u16(vs, 0);



        for (y = 0; y < vd->server->height; y++) {

            int x;

            int last_x = -1;

            for (x = 0; x < vd->server->width / 16; x++) {

                if (vnc_get_bit(vs->dirty[y], x)) {

                    if (last_x == -1) {

                        last_x = x;

                    }

                    vnc_clear_bit(vs->dirty[y], x);

                } else {

                    if (last_x != -1) {

                        int h = find_and_clear_dirty_height(vs, y, last_x, x);

                        n = send_framebuffer_update(vs, last_x * 16, y,

                                                    (x - last_x) * 16, h);

                        n_rectangles += n;

                    }

                    last_x = -1;

                }

            }

            if (last_x != -1) {

                int h = find_and_clear_dirty_height(vs, y, last_x, x);

                n = send_framebuffer_update(vs, last_x * 16, y,

                                            (x - last_x) * 16, h);

                n_rectangles += n;

            }

        }

        vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF;

        vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF;

        vnc_flush(vs);

        vs->force_update = 0;

        return n_rectangles;

    }



    if (vs->csock == -1)

        vnc_disconnect_finish(vs);



    return 0;

}

static int vnc_update_client(VncState *vs, int has_dirty)

{

    if (vs->need_update && vs->csock != -1) {

        VncDisplay *vd = vs->vd;

        int y;

        int n_rectangles;

        int saved_offset;

        int n;



        if (vs->output.offset && !vs->audio_cap && !vs->force_update)

            

            return 0;



        if (!has_dirty && !vs->audio_cap && !vs->force_update)

            return 0;



        











        n_rectangles = 0;

        vnc_write_u8(vs, VNC_MSG_SERVER_FRAMEBUFFER_UPDATE);

        vnc_write_u8(vs, 0);

        saved_offset = vs->output.offset;

        vnc_write_u16(vs, 0);



        for (y = 0; y < vd->server->height; y++) {

            int x;

            int last_x = -1;

            for (x = 0; x < vd->server->width / 16; x++) {

                if (vnc_get_bit(vs->dirty[y], x)) {

                    if (last_x == -1) {

                        last_x = x;

                    }

                    vnc_clear_bit(vs->dirty[y], x);

                } else {

                    if (last_x != -1) {

                        int h = find_and_clear_dirty_height(vs, y, last_x, x);

                        n = send_framebuffer_update(vs, last_x * 16, y,

                                                    (x - last_x) * 16, h);

                        n_rectangles += n;

                    }

                    last_x = -1;

                }

            }

            if (last_x != -1) {

                int h = find_and_clear_dirty_height(vs, y, last_x, x);

                n = send_framebuffer_update(vs, last_x * 16, y,

                                            (x - last_x) * 16, h);

                n_rectangles += n;

            }

        }

        vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF;

        vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF;

        vnc_flush(vs);

        vs->force_update = 0;

        return n_rectangles;

    }



    if (vs->csock == -1)

        vnc_disconnect_finish(vs);



    return 0;

}

static int FUNC_0(VncState *VAR_0, int VAR_1)

{

    if (VAR_0->need_update && VAR_0->csock != -1) {

        VncDisplay *vd = VAR_0->vd;

        int VAR_2;

        int VAR_3;

        int VAR_4;

        int VAR_5;



        if (VAR_0->output.offset && !VAR_0->audio_cap && !VAR_0->force_update)

            

            return 0;



        if (!VAR_1 && !VAR_0->audio_cap && !VAR_0->force_update)

            return 0;



        











        VAR_3 = 0;

        vnc_write_u8(VAR_0, VNC_MSG_SERVER_FRAMEBUFFER_UPDATE);

        vnc_write_u8(VAR_0, 0);

        VAR_4 = VAR_0->output.offset;

        vnc_write_u16(VAR_0, 0);



        for (VAR_2 = 0; VAR_2 < vd->server->height; VAR_2++) {

            int x;

            int last_x = -1;

            for (x = 0; x < vd->server->width / 16; x++) {

                if (vnc_get_bit(VAR_0->dirty[VAR_2], x)) {

                    if (last_x == -1) {

                        last_x = x;

                    }

                    vnc_clear_bit(VAR_0->dirty[VAR_2], x);

                } else {

                    if (last_x != -1) {

                        int h = find_and_clear_dirty_height(VAR_0, VAR_2, last_x, x);

                        VAR_5 = send_framebuffer_update(VAR_0, last_x * 16, VAR_2,

                                                    (x - last_x) * 16, h);

                        VAR_3 += VAR_5;

                    }

                    last_x = -1;

                }

            }

            if (last_x != -1) {

                int h = find_and_clear_dirty_height(VAR_0, VAR_2, last_x, x);

                VAR_5 = send_framebuffer_update(VAR_0, last_x * 16, VAR_2,

                                            (x - last_x) * 16, h);

                VAR_3 += VAR_5;

            }

        }

        VAR_0->output.buffer[VAR_4] = (VAR_3 >> 8) & 0xFF;

        VAR_0->output.buffer[VAR_4 + 1] = VAR_3 & 0xFF;

        vnc_flush(VAR_0);

        VAR_0->force_update = 0;

        return VAR_3;

    }



    if (VAR_0->csock == -1)

        vnc_disconnect_finish(VAR_0);



    return 0;

}

static int FUNC_0(VncState *VAR_0, int VAR_1)
{ if (VAR_0->need_update && VAR_0->csock != -1) { VncDisplay *vd = VAR_0->vd; int VAR_2; int VAR_3; int VAR_4; int VAR_5; if (VAR_0->output.offset && !VAR_0->audio_cap && !VAR_0->force_update)
return 0; if (!VAR_1 && !VAR_0->audio_cap && !VAR_0->force_update)
return 0; VAR_3 = 0; vnc_write_u8(VAR_0, VNC_MSG_SERVER_FRAMEBUFFER_UPDATE); vnc_write_u8(VAR_0, 0); VAR_4 = VAR_0->output.offset; vnc_write_u16(VAR_0, 0); for (VAR_2 = 0; VAR_2 < vd->server->height; VAR_2++) { int x; int last_x = -1; for (x = 0; x < vd->server->width / 16; x++) { if (vnc_get_bit(VAR_0->dirty[VAR_2], x)) { if (last_x == -1) { last_x = x; } vnc_clear_bit(VAR_0->dirty[VAR_2], x); } else { if (last_x != -1) { int h = find_and_clear_dirty_height(VAR_0, VAR_2, last_x, x); VAR_5 = send_framebuffer_update(VAR_0, last_x * 16, VAR_2,
(x - last_x) * 16, h); VAR_3 += VAR_5; } last_x = -1; } } if (last_x != -1) { int h = find_and_clear_dirty_height(VAR_0, VAR_2, last_x, x); VAR_5 = send_framebuffer_update(VAR_0, last_x * 16, VAR_2,
(x - last_x) * 16, h); VAR_3 += VAR_5; } } VAR_0->output.buffer[VAR_4] = (VAR_3 >> 8) & 0xFF; VAR_0->output.buffer[VAR_4 + 1] = VAR_3 & 0xFF; vnc_flush(VAR_0); VAR_0->force_update = 0; return VAR_3; } if (VAR_0->csock == -1)
vnc_disconnect_finish(VAR_0); return 0; }