diff options
author | Marc-André Lureau <marcandre.lureau@gmail.com> | 2013-09-02 17:37:56 +0200 |
---|---|---|
committer | Jonathon Jongsma <jjongsma@redhat.com> | 2014-12-17 17:06:31 -0600 |
commit | 9cd81a52b487debbc4bfaa443fa2ff5e3a76af12 (patch) | |
tree | 1f636fd651245cc62b96e094767e1899fdbc7505 | |
parent | 69f3f86ff79360d208f6f31e4914fbe3f0a14f61 (diff) |
server/util: replace receive/send with xread/xwritereplay-start
They are just utils functions around read and write, let's not use
different naming.
-rw-r--r-- | server/red_dispatcher.c | 4 | ||||
-rw-r--r-- | server/red_worker.c | 4 | ||||
-rw-r--r-- | server/red_worker.h | 37 | ||||
-rw-r--r-- | server/spice_server_utils.h | 35 |
4 files changed, 42 insertions, 38 deletions
diff --git a/server/red_dispatcher.c b/server/red_dispatcher.c index d8389bc5..e9c50cb1 100644 --- a/server/red_dispatcher.c +++ b/server/red_dispatcher.c @@ -1047,7 +1047,7 @@ static RedChannel *red_dispatcher_display_channel_create(RedDispatcher *dispatch dispatcher_send_message(&dispatcher->dispatcher, RED_WORKER_MESSAGE_DISPLAY_CHANNEL_CREATE, &payload); - receive_data(dispatcher->dispatcher.send_fd, &display_channel, sizeof(RedChannel *)); + xread(dispatcher->dispatcher.send_fd, &display_channel, sizeof(RedChannel *)); return display_channel; } @@ -1059,7 +1059,7 @@ static RedChannel *red_dispatcher_cursor_channel_create(RedDispatcher *dispatche dispatcher_send_message(&dispatcher->dispatcher, RED_WORKER_MESSAGE_CURSOR_CHANNEL_CREATE, &payload); - receive_data(dispatcher->dispatcher.send_fd, &cursor_channel, sizeof(RedChannel *)); + xread(dispatcher->dispatcher.send_fd, &cursor_channel, sizeof(RedChannel *)); return cursor_channel; } diff --git a/server/red_worker.c b/server/red_worker.c index a18987a6..b8212d05 100644 --- a/server/red_worker.c +++ b/server/red_worker.c @@ -11603,7 +11603,7 @@ void handle_dev_display_channel_create(void *opaque, void *payload) // TODO: handle seemless migration. Temp, setting migrate to FALSE display_channel_create(worker, FALSE); red_channel = &worker->display_channel->common.base; - send_data(worker->channel, &red_channel, sizeof(RedChannel *)); + xwrite(worker->channel, &red_channel, sizeof(RedChannel *)); } void handle_dev_display_connect(void *opaque, void *payload) @@ -11686,7 +11686,7 @@ void handle_dev_cursor_channel_create(void *opaque, void *payload) // TODO: handle seemless migration. Temp, setting migrate to FALSE cursor_channel_create(worker, FALSE); red_channel = &worker->cursor_channel->common.base; - send_data(worker->channel, &red_channel, sizeof(RedChannel *)); + xwrite(worker->channel, &red_channel, sizeof(RedChannel *)); } void handle_dev_cursor_connect(void *opaque, void *payload) diff --git a/server/red_worker.h b/server/red_worker.h index 272661f4..b9d90801 100644 --- a/server/red_worker.h +++ b/server/red_worker.h @@ -20,6 +20,7 @@ #include <unistd.h> #include <errno.h> +#include "spice_server_utils.h" #include "red_common.h" enum { @@ -107,46 +108,14 @@ typedef struct WorkerInitData { void *red_worker_main(void *arg); -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 write_message(int fd, RedWorkerMessage *message) { - send_data(fd, message, sizeof(RedWorkerMessage)); -} - -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); + xwrite(fd, message, sizeof(RedWorkerMessage)); } static inline void read_message(int fd, RedWorkerMessage *message) { - receive_data(fd, message, sizeof(RedWorkerMessage)); + xread(fd, message, sizeof(RedWorkerMessage)); } #endif diff --git a/server/spice_server_utils.h b/server/spice_server_utils.h index b3ddc27e..3f53ca82 100644 --- a/server/spice_server_utils.h +++ b/server/spice_server_utils.h @@ -2,6 +2,9 @@ #define H_SPICE_SERVER_UTIL #include <unistd.h> +#include <errno.h> +#include <string.h> +#include "common/log.h" static inline void set_bit(int index, uint32_t *addr) { @@ -20,4 +23,36 @@ static inline int test_bit(int index, uint32_t val) return val & (1u << index); } +static inline void xwrite(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 xread(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); +} + #endif |