[Spice-devel] [PATCH 2/2] dispatcher: remove receive_data and send_data functions

Jonathon Jongsma jjongsma at redhat.com
Fri Nov 6 12:33:33 PST 2015


ACK

On Fri, 2015-11-06 at 14:23 +0000, Frediano Ziglio wrote:
> From: Marc-André Lureau <marcandre.lureau at gmail.com>
> 
> Use read_safe/write_safe instead which do the same stuff
> ---
>  server/dispatcher.c     |  6 +++---
>  server/red_dispatcher.h | 32 --------------------------------
>  2 files changed, 3 insertions(+), 35 deletions(-)
> 
> diff --git a/server/dispatcher.c b/server/dispatcher.c
> index d334117..945edba 100644
> --- a/server/dispatcher.c
> +++ b/server/dispatcher.c
> @@ -32,7 +32,6 @@
>  #include "common/mem.h"
>  #include "common/spice_common.h"
>  #include "dispatcher.h"
> -#include "red_dispatcher.h"
>  
>  //#define DEBUG_DISPATCHER
>  
> @@ -203,12 +202,13 @@ unlock:
>  
>  uint32_t dispatcher_read_message(Dispatcher *dispatcher)
>  {
> -    uint32_t message;
> +    uint32_t message = 0;
>  
>      spice_return_val_if_fail(dispatcher, 0);
>      spice_return_val_if_fail(dispatcher->send_fd != -1, 0);
>  
> -    receive_data(dispatcher->send_fd, &message, sizeof(message));
> +    if (read_safe(dispatcher->send_fd, (uint8_t*)&message,
> sizeof(message), 1) == -1)
> +        spice_warn_if_reached();
>  
>      return message;
>  }
> diff --git a/server/red_dispatcher.h b/server/red_dispatcher.h
> index fde965d..02337b8 100644
> --- a/server/red_dispatcher.h
> +++ b/server/red_dispatcher.h
> @@ -45,38 +45,6 @@ void
> red_dispatcher_client_monitors_config(VDAgentMonitorsConfig
> *monitors_confi
>  
>  typedef uint32_t RedWorkerMessage;
>  
> -static inline void send_data(int fd, void *in_buf, int n)
> -{
> -    uint8_t *buf = in_buf;
> -    do {
> -        int now;
> -        if ((now = write(fd, buf, n)) == -1) {
> -            if (errno == EINTR) {
> -                continue;
> -            }
> -            spice_error("%s", strerror(errno));
> -        }
> -        buf += now;
> -        n -= now;
> -    } while (n);
> -}
> -
> -static inline void receive_data(int fd, void *in_buf, int n)
> -{
> -    uint8_t *buf = in_buf;
> -    do {
> -        int now;
> -        if ((now = read(fd, buf, n)) == -1) {
> -            if (errno == EINTR) {
> -                continue;
> -            }
> -            spice_error("%s", strerror(errno));
> -        }
> -        buf += now;
> -        n -= now;
> -    } while (n);
> -}
> -
>  /* Keep message order, only append new messages!
>   * Replay code store enum values into save files.
>   */


More information about the Spice-devel mailing list