summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2017-11-21 17:46:55 +0000
committerFrediano Ziglio <fziglio@redhat.com>2017-11-23 11:39:01 +0000
commit3d2699ec83122e00eef0c523c084aa9952515280 (patch)
treef42ba3e84b173f11a139080a5e483c5562da163d
parent922b17ccc6db2a4992841b1901afb3a0f7fbe6e8 (diff)
Move write_all into a new utility module
-rw-r--r--src/Makefile.am2
-rw-r--r--src/file-util.c32
-rw-r--r--src/file-util.h21
-rw-r--r--src/spice-streaming-agent.cpp22
4 files changed, 56 insertions, 21 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8d5c5bd..35efa49 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,6 +31,8 @@ noinst_LIBRARIES = libstreaming-utils.a
libstreaming_utils_a_SOURCES = \
hexdump.c \
hexdump.h \
+ file-util.c \
+ file-util.h \
$(NULL)
spice_streaming_agent_LDFLAGS = \
diff --git a/src/file-util.c b/src/file-util.c
new file mode 100644
index 0000000..5df5d0c
--- /dev/null
+++ b/src/file-util.c
@@ -0,0 +1,32 @@
+/* File utility
+ *
+ * \copyright
+ * Copyright 2017 Red Hat Inc. All rights reserved.
+ */
+#include <config.h>
+#include <stdint.h>
+#include <errno.h>
+#include <unistd.h>
+#include <syslog.h>
+
+#include "file-util.h"
+
+size_t
+write_all(int fd, const void *buf, const size_t len)
+{
+ size_t written = 0;
+ while (written < len) {
+ int l = write(fd, (const char *) buf + written, len - written);
+ if (l < 0 && errno == EINTR) {
+ continue;
+ }
+ if (l < 0) {
+ syslog(LOG_ERR, "write failed - %m");
+ return l;
+ }
+ written += l;
+ }
+ syslog(LOG_DEBUG, "write_all -- %u bytes written\n", (unsigned)written);
+ return written;
+}
+
diff --git a/src/file-util.h b/src/file-util.h
new file mode 100644
index 0000000..f107029
--- /dev/null
+++ b/src/file-util.h
@@ -0,0 +1,21 @@
+/* File utility
+ *
+ * \copyright
+ * Copyright 2017 Red Hat Inc. All rights reserved.
+ */
+#ifndef STREAMING_AGENT_FILE_UTIL_H_
+#define STREAMING_AGENT_FILE_UTIL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+
+size_t write_all(int fd, const void *buf, const size_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
index 461ccc0..7e2ec54 100644
--- a/src/spice-streaming-agent.cpp
+++ b/src/spice-streaming-agent.cpp
@@ -33,6 +33,7 @@
#include <spice-streaming-agent/plugin.hpp>
#include "hexdump.h"
+#include "file-util.h"
#include "concrete-agent.hpp"
using namespace std;
@@ -52,8 +53,6 @@ struct SpiceStreamDataMessage
StreamMsgData msg;
};
-static size_t write_all(int fd, const void *buf, const size_t len);
-
class SpiceStream
{
public:
@@ -206,25 +205,6 @@ static int read_command(SpiceStream &stream, bool blocking)
return n;
}
-static size_t
-write_all(int fd, const void *buf, const size_t len)
-{
- size_t written = 0;
- while (written < len) {
- int l = write(fd, (const char *) buf + written, len - written);
- if (l < 0 && errno == EINTR) {
- continue;
- }
- if (l < 0) {
- syslog(LOG_ERR, "write failed - %m");
- return l;
- }
- written += l;
- }
- syslog(LOG_DEBUG, "write_all -- %u bytes written\n", (unsigned)written);
- return written;
-}
-
int SpiceStream::send_format(unsigned w, unsigned h, unsigned c)
{