Patchwork [1/3] vnc: added buffer_advance function

login
register
mail settings
Submitter Tim Hardeck
Date Jan. 2, 2013, 1:29 p.m.
Message ID <1357133386-7643-2-git-send-email-thardeck@suse.de>
Download mbox | patch
Permalink /patch/209046/
State New
Headers show

Comments

Tim Hardeck - Jan. 2, 2013, 1:29 p.m.
Following Anthony Liguori's Websocket implementation I have added the
buffer_advance function to VNC and replaced all related buffer memmove
operations with it.

Signed-off-by: Tim Hardeck <thardeck@suse.de>
---
 ui/vnc.c |   13 +++++++++----
 ui/vnc.h |    1 +
 2 files changed, 10 insertions(+), 4 deletions(-)
Anthony Liguori - Jan. 7, 2013, 7:38 p.m.
Tim Hardeck <thardeck@suse.de> writes:

> Following Anthony Liguori's Websocket implementation I have added the
> buffer_advance function to VNC and replaced all related buffer memmove
> operations with it.
>
> Signed-off-by: Tim Hardeck <thardeck@suse.de>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>  ui/vnc.c |   13 +++++++++----
>  ui/vnc.h |    1 +
>  2 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/ui/vnc.c b/ui/vnc.c
> index 8912b78..ddf01f1 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -510,6 +510,13 @@ void buffer_append(Buffer *buffer, const void *data, size_t len)
>      buffer->offset += len;
>  }
>  
> +void buffer_advance(Buffer *buf, size_t len)
> +{
> +    memmove(buf->buffer, buf->buffer + len,
> +            (buf->offset - len));
> +    buf->offset -= len;
> +}
> +
>  static void vnc_desktop_resize(VncState *vs)
>  {
>      DisplayState *ds = vs->ds;
> @@ -1166,8 +1173,7 @@ static long vnc_client_write_plain(VncState *vs)
>      if (!ret)
>          return 0;
>  
> -    memmove(vs->output.buffer, vs->output.buffer + ret, (vs->output.offset - ret));
> -    vs->output.offset -= ret;
> +    buffer_advance(&vs->output, ret);
>  
>      if (vs->output.offset == 0) {
>          qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
> @@ -1313,8 +1319,7 @@ void vnc_client_read(void *opaque)
>          }
>  
>          if (!ret) {
> -            memmove(vs->input.buffer, vs->input.buffer + len, (vs->input.offset - len));
> -            vs->input.offset -= len;
> +            buffer_advance(&vs->input, len);
>          } else {
>              vs->read_handler_expect = ret;
>          }
> diff --git a/ui/vnc.h b/ui/vnc.h
> index 8b40f09..5059cbe 100644
> --- a/ui/vnc.h
> +++ b/ui/vnc.h
> @@ -510,6 +510,7 @@ void buffer_reserve(Buffer *buffer, size_t len);
>  void buffer_reset(Buffer *buffer);
>  void buffer_free(Buffer *buffer);
>  void buffer_append(Buffer *buffer, const void *data, size_t len);
> +void buffer_advance(Buffer *buf, size_t len);
>  
>  
>  /* Misc helpers */
> -- 
> 1.7.10.4

Patch

diff --git a/ui/vnc.c b/ui/vnc.c
index 8912b78..ddf01f1 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -510,6 +510,13 @@  void buffer_append(Buffer *buffer, const void *data, size_t len)
     buffer->offset += len;
 }
 
+void buffer_advance(Buffer *buf, size_t len)
+{
+    memmove(buf->buffer, buf->buffer + len,
+            (buf->offset - len));
+    buf->offset -= len;
+}
+
 static void vnc_desktop_resize(VncState *vs)
 {
     DisplayState *ds = vs->ds;
@@ -1166,8 +1173,7 @@  static long vnc_client_write_plain(VncState *vs)
     if (!ret)
         return 0;
 
-    memmove(vs->output.buffer, vs->output.buffer + ret, (vs->output.offset - ret));
-    vs->output.offset -= ret;
+    buffer_advance(&vs->output, ret);
 
     if (vs->output.offset == 0) {
         qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
@@ -1313,8 +1319,7 @@  void vnc_client_read(void *opaque)
         }
 
         if (!ret) {
-            memmove(vs->input.buffer, vs->input.buffer + len, (vs->input.offset - len));
-            vs->input.offset -= len;
+            buffer_advance(&vs->input, len);
         } else {
             vs->read_handler_expect = ret;
         }
diff --git a/ui/vnc.h b/ui/vnc.h
index 8b40f09..5059cbe 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -510,6 +510,7 @@  void buffer_reserve(Buffer *buffer, size_t len);
 void buffer_reset(Buffer *buffer);
 void buffer_free(Buffer *buffer);
 void buffer_append(Buffer *buffer, const void *data, size_t len);
+void buffer_advance(Buffer *buf, size_t len);
 
 
 /* Misc helpers */