[Spice-devel] [PATCH spice-protocol] error_codes: Remove obsolete header file

2018-12-21 Thread Frediano Ziglio
This file was used by the old client to hold return error codes.

Signed-off-by: Frediano Ziglio 
---
 spice/Makefile.am   |  1 -
 spice/error_codes.h | 51 -
 spice/meson.build   |  1 -
 3 files changed, 53 deletions(-)
 delete mode 100644 spice/error_codes.h

diff --git a/spice/Makefile.am b/spice/Makefile.am
index e41f41d..69c9976 100644
--- a/spice/Makefile.am
+++ b/spice/Makefile.am
@@ -7,7 +7,6 @@ spice_protocol_include_HEADERS =\
controller_prot.h   \
end-packed.h\
enums.h \
-   error_codes.h   \
foreign_menu_prot.h \
ipc_ring.h  \
macros.h\
diff --git a/spice/error_codes.h b/spice/error_codes.h
deleted file mode 100644
index 9fcfe3f..000
--- a/spice/error_codes.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-   Copyright (C) 2009 Red Hat, Inc.
-
-   Redistribution and use in source and binary forms, with or without
-   modification, are permitted provided that the following conditions are
-   met:
-
-   * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-   * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
-   * Neither the name of the copyright holder nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
-   IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-   TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-   PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _H_SPICE_ERROR_CODES
-#define _H_SPICE_ERROR_CODES
-
-#define SPICEC_ERROR_CODE_SUCCESS 0
-#define SPICEC_ERROR_CODE_ERROR 1
-#define SPICEC_ERROR_CODE_GETHOSTBYNAME_FAILED 2
-#define SPICEC_ERROR_CODE_CONNECT_FAILED 3
-#define SPICEC_ERROR_CODE_SOCKET_FAILED 4
-#define SPICEC_ERROR_CODE_SEND_FAILED 5
-#define SPICEC_ERROR_CODE_RECV_FAILED 6
-#define SPICEC_ERROR_CODE_SSL_ERROR 7
-#define SPICEC_ERROR_CODE_NOT_ENOUGH_MEMORY 8
-#define SPICEC_ERROR_CODE_AGENT_TIMEOUT 9
-#define SPICEC_ERROR_CODE_AGENT_ERROR 10
-#define SPICEC_ERROR_CODE_VERSION_MISMATCH 11
-#define SPICEC_ERROR_CODE_PERMISSION_DENIED 12
-#define SPICEC_ERROR_CODE_INVALID_ARG 13
-#define SPICEC_ERROR_CODE_CMD_LINE_ERROR 14
-
-#endif /* _H_SPICE_ERROR_CODES */
-
diff --git a/spice/meson.build b/spice/meson.build
index 5b1ff30..05b2b28 100644
--- a/spice/meson.build
+++ b/spice/meson.build
@@ -3,7 +3,6 @@ spice_protocol_headers = [
   'controller_prot.h',
   'end-packed.h',
   'enums.h',
-  'error_codes.h',
   'foreign_menu_prot.h',
   'ipc_ring.h',
   'macros.h',
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 33/33] Add some notes for the Windows port

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 README.Windows | 18 ++
 1 file changed, 18 insertions(+)
 create mode 100644 README.Windows

diff --git a/README.Windows b/README.Windows
new file mode 100644
index ..2274eba4
--- /dev/null
+++ b/README.Windows
@@ -0,0 +1,18 @@
+SPICE server Windows support
+
+
+SPICE server was ported from Unix/Linux to Windows.
+
+Mainly feature are present beside some specific ones:
+- Unix sockets;
+- signal handling;
+- CLOEXEC flag (completely different handling on Windows);
+- IPTOS_LOWDELAY flag (Linux specific);
+- TCP_CORK (Linux/*BSD specific).
+
+Some feature could be ported too but currently are not:
+- statistics exported through mapped files. Disabled by default and mainly
+  used mainly for development;
+- filtering while recording (SPICE_WORKER_RECORD_FILTER environment).
+  Recording is used for debugging or development work;
+- TCP_KEEPIDLE setting. Default is used.
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 32/33] Use structure for socket_t type instead of just a typedef

2018-12-21 Thread Frediano Ziglio
Allows the compiler to catch errors mixing int and sockets.
Make easier to keep Windows port working.

Signed-off-by: Frediano Ziglio 
---
 server/sys-socket.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/sys-socket.h b/server/sys-socket.h
index 9dca563b..361845e2 100644
--- a/server/sys-socket.h
+++ b/server/sys-socket.h
@@ -26,7 +26,7 @@
 #ifndef _WIN32
 #  include 
 
-#if 0
+#if ENABLE_EXTRA_CHECKS
 typedef struct {
 int fd;
 } socket_t;
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 20/33] replay: Force binary mode on input on Windows

2018-12-21 Thread Frediano Ziglio
If input contains the binary record we can't have it modified
during read.

Signed-off-by: Frediano Ziglio 
---
 server/tests/replay.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/server/tests/replay.c b/server/tests/replay.c
index cbb1c195..c8e10d0a 100644
--- a/server/tests/replay.c
+++ b/server/tests/replay.c
@@ -392,6 +392,9 @@ int main(int argc, char **argv)
 
 if (strncmp(file[0], "-", 1) == 0) {
 fd = stdin;
+#ifdef _WIN32
+_setmode(fileno(fd), _O_BINARY);
+#endif
 } else {
 fd = fopen(file[0], "r");
 }
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 27/33] red-stream: Fix SSL connection for Windows

2018-12-21 Thread Frediano Ziglio
Set correctly errno to make callers handle correctly encrypted
traffic.

Signed-off-by: Frediano Ziglio 
---
 server/red-stream.c | 29 +
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/server/red-stream.c b/server/red-stream.c
index a6da8385..687d6ca2 100644
--- a/server/red-stream.c
+++ b/server/red-stream.c
@@ -158,15 +158,37 @@ static ssize_t stream_read_cb(RedStream *s, void *buf, 
size_t size)
 return socket_read(s->socket, buf, size);
 }
 
+static ssize_t stream_ssl_error(RedStream *s, int return_code)
+{
+SPICE_GNUC_UNUSED int ssl_error;
+
+ssl_error = SSL_get_error(s->priv->ssl, return_code);
+
+// OpenSSL can to return SSL_ERROR_WANT_READ if we attempt to read
+// data and the socket did not receive all SSL packet.
+// Under Windows errno is not set so potentially caller can detect
+// the wrong error so we need to set errno.
+#ifdef _WIN32
+if (ssl_error == SSL_ERROR_WANT_READ || ssl_error == SSL_ERROR_WANT_WRITE) 
{
+errno = EAGAIN;
+} else {
+errno = EPIPE;
+}
+#endif
+
+// red_peer_receive is expected to receive -1 on errors while
+// OpenSSL documentation just state a <0 value
+return -1;
+}
+
 static ssize_t stream_ssl_write_cb(RedStream *s, const void *buf, size_t size)
 {
 int return_code;
-SPICE_GNUC_UNUSED int ssl_error;
 
 return_code = SSL_write(s->priv->ssl, buf, size);
 
 if (return_code < 0) {
-ssl_error = SSL_get_error(s->priv->ssl, return_code);
+return stream_ssl_error(s, return_code);
 }
 
 return return_code;
@@ -175,12 +197,11 @@ static ssize_t stream_ssl_write_cb(RedStream *s, const 
void *buf, size_t size)
 static ssize_t stream_ssl_read_cb(RedStream *s, void *buf, size_t size)
 {
 int return_code;
-SPICE_GNUC_UNUSED int ssl_error;
 
 return_code = SSL_read(s->priv->ssl, buf, size);
 
 if (return_code < 0) {
-ssl_error = SSL_get_error(s->priv->ssl, return_code);
+return stream_ssl_error(s, return_code);
 }
 
 return return_code;
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 21/33] dispatcher: Port to Windows

2018-12-21 Thread Frediano Ziglio
Replace poll call with select.
As socket is set to non-blocking we must support it so if
we detect an EAGAIN error wait for data.

Signed-off-by: Frediano Ziglio 
---
 server/dispatcher.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/server/dispatcher.c b/server/dispatcher.c
index 4cd91f11..9a55a4c9 100644
--- a/server/dispatcher.c
+++ b/server/dispatcher.c
@@ -197,6 +197,7 @@ static int read_safe(socket_t fd, uint8_t *buf, size_t 
size, int block)
 }
 
 if (!block) {
+#ifndef _WIN32
 struct pollfd pollfd = {.fd = socket_get_raw(fd), .events = POLLIN, 
.revents = 0};
 while ((ret = poll(, 1, 0)) == -1) {
 if (errno == EINTR) {
@@ -209,6 +210,15 @@ static int read_safe(socket_t fd, uint8_t *buf, size_t 
size, int block)
 if (!(pollfd.revents & POLLIN)) {
 return 0;
 }
+#else
+struct timeval tv = { 0, 0 };
+fd_set fds;
+FD_ZERO();
+FD_SET(socket_get_raw(fd), );
+if (select(1, , NULL, NULL, ) < 1) {
+return 0;
+}
+#endif
 }
 while (read_size < size) {
 ret = socket_read(fd, buf + read_size, size - read_size);
@@ -217,6 +227,16 @@ static int read_safe(socket_t fd, uint8_t *buf, size_t 
size, int block)
 spice_debug("EINTR in read");
 continue;
 }
+#ifdef _WIN32
+// Windows turns this socket not-blocking
+if (errno == EAGAIN) {
+fd_set fds;
+FD_ZERO();
+FD_SET(socket_get_raw(fd), );
+select(1, , NULL, NULL, NULL);
+continue;
+}
+#endif
 return -1;
 }
 if (ret == 0) {
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 28/33] test-display-base: Port to Windows

2018-12-21 Thread Frediano Ziglio
Use GLib function to launch and wait process exit.

Signed-off-by: Frediano Ziglio 
---
 server/tests/regression-test.py  |  4 ++--
 server/tests/test-display-base.c | 37 +++-
 2 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/server/tests/regression-test.py b/server/tests/regression-test.py
index 5aad1a7b..81eaecf1 100755
--- a/server/tests/regression-test.py
+++ b/server/tests/regression-test.py
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 from subprocess import PIPE, Popen
-import Image
-import ImageChops
+from PIL import Image
+from PIL import ImageChops
 
 
 def spicy_screenshot():
diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
index 868521bc..ecf40e4a 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -91,17 +91,19 @@ static int has_automated_tests = 0; //automated test flag
 // between multiple threads so use a mutex
 static pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-__attribute__((noreturn))
-static void sigchld_handler(SPICE_GNUC_UNUSED int signal_num) // wait for the 
child process and exit
+// wait for the child process and exit
+static void child_exited(GPid pid, gint status, gpointer user_data)
 {
-int status;
-wait();
+g_spawn_close_pid(pid);
 exit(0);
 }
 
 static void regression_test(void)
 {
-pid_t pid;
+GPid pid;
+GError *error = NULL;
+gboolean retval;
+gchar **argv;
 
 if (--rects != 0) {
 return;
@@ -113,17 +115,17 @@ static void regression_test(void)
 return;
 }
 
-pid = fork();
-if (pid == 0) {
-char buf[PATH_MAX];
-char *argv[] = { NULL };
-char *envp[] = {buf, NULL};
+argv = g_strsplit("./regression-test.py", " ", -1);
+retval = g_spawn_async(NULL, argv, NULL, 
G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD,
+   NULL, NULL, , );
+g_strfreev(argv);
+g_assert(retval);
 
-snprintf(buf, sizeof(buf), "PATH=%s", getenv("PATH"));
-execve("regression-test.py", argv, envp);
-} else if (pid > 0) {
-return;
-}
+GSource *source = g_child_watch_source_new(pid);
+g_source_set_callback(source, (GSourceFunc)(void*)child_exited, NULL, 
NULL);
+guint id = g_source_attach(source, basic_event_loop_get_context());
+g_assert(id != 0);
+g_source_unref(source);
 }
 
 static void set_cmd(QXLCommandExt *ext, uint32_t type, QXLPHYSICAL data)
@@ -969,11 +971,6 @@ void test_destroy(Test *test)
 
 static void init_automated(void)
 {
-struct sigaction sa;
-
-memset(, 0, sizeof sa);
-sa.sa_handler = _handler;
-sigaction(SIGCHLD, , NULL);
 }
 
 static __attribute__((noreturn))
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 23/33] tests: Provide alarm replacement for Windows

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/tests/Makefile.am  |  2 +
 server/tests/test-channel.c   |  1 +
 server/tests/test-loop.c  |  1 +
 server/tests/test-stream-device.c |  1 +
 server/tests/win-alarm.c  | 65 +++
 server/tests/win-alarm.h  | 26 +
 6 files changed, 96 insertions(+)
 create mode 100644 server/tests/win-alarm.c
 create mode 100644 server/tests/win-alarm.h

diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am
index d7f7af9b..7668739f 100644
--- a/server/tests/Makefile.am
+++ b/server/tests/Makefile.am
@@ -35,6 +35,8 @@ libtest_a_SOURCES =   \
test-display-base.h \
test-glib-compat.c  \
test-glib-compat.h  \
+   win-alarm.c \
+   win-alarm.h \
$(NULL)
 
 LDADD =\
diff --git a/server/tests/test-channel.c b/server/tests/test-channel.c
index fef295a3..583cb522 100644
--- a/server/tests/test-channel.c
+++ b/server/tests/test-channel.c
@@ -28,6 +28,7 @@
 #include "red-client.h"
 #include "cursor-channel.h"
 #include "net-utils.h"
+#include "win-alarm.h"
 
 /*
  * Declare a RedTestChannel to be used for the test
diff --git a/server/tests/test-loop.c b/server/tests/test-loop.c
index 1e3b39e5..82af80ab 100644
--- a/server/tests/test-loop.c
+++ b/server/tests/test-loop.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include "basic-event-loop.h"
+#include "win-alarm.h"
 
 static SpiceCoreInterface *core = NULL;
 static GMainLoop *loop = NULL;
diff --git a/server/tests/test-stream-device.c 
b/server/tests/test-stream-device.c
index f1707d2f..e1868789 100644
--- a/server/tests/test-stream-device.c
+++ b/server/tests/test-stream-device.c
@@ -33,6 +33,7 @@
 #include "test-glib-compat.h"
 #include "stream-channel.h"
 #include "reds.h"
+#include "win-alarm.h"
 
 static SpiceCharDeviceInstance vmc_instance;
 
diff --git a/server/tests/win-alarm.c b/server/tests/win-alarm.c
new file mode 100644
index ..225d0709
--- /dev/null
+++ b/server/tests/win-alarm.c
@@ -0,0 +1,65 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2018 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see .
+*/
+
+#include 
+#include 
+
+#ifdef _WIN32
+#include 
+#include "win-alarm.h"
+
+static HANDLE alarm_cond = NULL;
+
+static DWORD WINAPI alarm_thread_proc(LPVOID arg)
+{
+unsigned int timeout = (uintptr_t) arg;
+switch (WaitForSingleObject(alarm_cond, timeout * 1000)) {
+case WAIT_OBJECT_0:
+return 0;
+}
+abort();
+return 0;
+}
+
+void alarm(unsigned int timeout)
+{
+static HANDLE thread = NULL;
+
+// create an event to stop the alarm thread
+if (alarm_cond == NULL) {
+alarm_cond = CreateEvent(NULL, TRUE, FALSE, NULL);
+g_assert(alarm_cond != NULL);
+}
+
+// stop old alarm
+if (thread) {
+SetEvent(alarm_cond);
+g_assert(WaitForSingleObject(thread, INFINITE) == WAIT_OBJECT_0);
+CloseHandle(thread);
+thread = NULL;
+}
+
+if (timeout) {
+ResetEvent(alarm_cond);
+
+// start alarm thread
+thread = CreateThread(NULL, 0, alarm_thread_proc, (LPVOID) (uintptr_t) 
timeout, 0, NULL);
+g_assert(thread);
+}
+}
+#endif
diff --git a/server/tests/win-alarm.h b/server/tests/win-alarm.h
new file mode 100644
index ..a7233a8f
--- /dev/null
+++ b/server/tests/win-alarm.h
@@ -0,0 +1,26 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2018 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this 

[Spice-devel] [PATCH spice-server 31/33] replay: Port to Windows

2018-12-21 Thread Frediano Ziglio
Client process termination did not work for Windows, used Win32
APIs.

Signed-off-by: Frediano Ziglio 
---
 server/tests/replay.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/server/tests/replay.c b/server/tests/replay.c
index c8e10d0a..58630711 100644
--- a/server/tests/replay.c
+++ b/server/tests/replay.c
@@ -210,15 +210,22 @@ static int req_display_notification(QXLInstance *qin)
 
 static void end_replay(void)
 {
-int child_status;
-
 /* FIXME: wait threads and end cleanly */
 spice_replay_free(replay);
 
 if (client_pid) {
 g_debug("kill %" G_PID_FORMAT, client_pid);
+#ifndef _WIN32
+int child_status;
+
 kill(client_pid, SIGINT);
 waitpid(client_pid, _status, 0);
+#else
+TerminateProcess(client_pid, 0);
+WaitForSingleObject(client_pid, INFINITE);
+#endif
+g_spawn_close_pid(client_pid);
+client_pid = 0;
 }
 }
 
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 26/33] test-stat: Adjust delay checks

2018-12-21 Thread Frediano Ziglio
usleep under Windows does not seem to have the required precision.
Use milliseconds and adjust check times according.

Signed-off-by: Frediano Ziglio 
---
 server/tests/stat-test.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/server/tests/stat-test.c b/server/tests/stat-test.c
index e4a83f4f..444ff7e3 100644
--- a/server/tests/stat-test.c
+++ b/server/tests/stat-test.c
@@ -57,13 +57,13 @@ void TEST_NAME(void)
 
 stat_init(, "test", CLOCK_MONOTONIC);
 stat_start_time_init(_time, );
-usleep(2);
+usleep(2000);
 stat_add(, start_time);
 
 #ifdef RED_WORKER_STAT
 g_assert_cmpuint(info.count, ==, 1);
 g_assert_cmpuint(info.min, ==, info.max);
-g_assert_cmpuint(info.min, >=, 2000);
+g_assert_cmpuint(info.min, >=, 200);
 g_assert_cmpuint(info.min, <, 1);
 #endif
 
@@ -71,17 +71,17 @@ void TEST_NAME(void)
 
 stat_compress_init(, "test", CLOCK_MONOTONIC);
 stat_start_time_init(_time, );
-usleep(2);
+usleep(2000);
 stat_compress_add(, start_time, 100, 50);
-usleep(1);
+usleep(1000);
 stat_compress_add(, start_time, 1000, 500);
 
 #ifdef COMPRESS_STAT
 g_assert_cmpuint(info.count, ==, 2);
 g_assert_cmpuint(info.min, !=, info.max);
-g_assert_cmpuint(info.min, >=, 2000);
+g_assert_cmpuint(info.min, >=, 200);
 g_assert_cmpuint(info.min, <, 1);
-g_assert_cmpuint(info.total, >=, 5000);
+g_assert_cmpuint(info.total, >=, 500);
 g_assert_cmpuint(info.orig_size, ==, 1100);
 g_assert_cmpuint(info.comp_size, ==, 550);
 #endif
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 29/33] reds: Explicitly include inttypes.h

2018-12-21 Thread Frediano Ziglio
MingW does not include this header while including stdint.h so
on Windows you need to include it.

Signed-off-by: Frediano Ziglio 
---
 server/reds.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/server/reds.h b/server/reds.h
index 8481d7c6..f192b563 100644
--- a/server/reds.h
+++ b/server/reds.h
@@ -19,6 +19,7 @@
 #define REDS_H_
 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 30/33] Disable recording filtering for Windows

2018-12-21 Thread Frediano Ziglio
Although this feature can be ported to Windows doing so would
require the usage of g_spawn_async_with_fds, which is only available
in GLib 2.58 or some specific Win32 code.

Signed-off-by: Frediano Ziglio 
---
 server/red-record-qxl.c| 8 ++--
 server/tests/test-record.c | 7 +--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/server/red-record-qxl.c b/server/red-record-qxl.c
index 30a3b0da..c9e84bfb 100644
--- a/server/red-record-qxl.c
+++ b/server/red-record-qxl.c
@@ -817,6 +817,7 @@ void red_record_qxl_command(RedRecord *record, 
RedMemSlotInfo *slots,
 pthread_mutex_unlock(>lock);
 }
 
+#ifndef _WIN32
 /**
  * Redirects child output to the file specified
  */
@@ -829,12 +830,12 @@ static void child_output_setup(gpointer user_data)
 }
 close(fd);
 }
+#endif
 
 RedRecord *red_record_new(const char *filename)
 {
 static const char header[] = "SPICE_REPLAY 1\n";
 
-const char *filter;
 FILE *f;
 RedRecord *record;
 
@@ -843,7 +844,9 @@ RedRecord *red_record_new(const char *filename)
 spice_error("failed to open recording file %s", filename);
 }
 
-filter = getenv("SPICE_WORKER_RECORD_FILTER");
+// TODO
+#ifndef _WIN32
+const char *filter = getenv("SPICE_WORKER_RECORD_FILTER");
 if (filter) {
 gint argc;
 gchar **argv = NULL;
@@ -871,6 +874,7 @@ RedRecord *red_record_new(const char *filename)
 close(fd_in);
 g_spawn_close_pid(child_pid);
 }
+#endif
 
 if (fwrite(header, sizeof(header)-1, 1, f) != 1) {
 spice_error("failed to write replay header");
diff --git a/server/tests/test-record.c b/server/tests/test-record.c
index de3c6f5b..8ee36ceb 100644
--- a/server/tests/test-record.c
+++ b/server/tests/test-record.c
@@ -35,9 +35,9 @@ test_record(bool compress)
 RedRecord *rec;
 const char *fn = OUTPUT_FILENAME;
 
-unsetenv("SPICE_WORKER_RECORD_FILTER");
+g_unsetenv("SPICE_WORKER_RECORD_FILTER");
 if (compress) {
-setenv("SPICE_WORKER_RECORD_FILTER", "gzip", 1);
+g_setenv("SPICE_WORKER_RECORD_FILTER", "gzip", 1);
 }
 
 // delete possible stale test output
@@ -95,6 +95,9 @@ int
 main(void)
 {
 test_record(false);
+// TODO implement on Windows
+#ifndef _WIN32
 test_record(true);
+#endif
 return 0;
 }
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 22/33] event-loop: Port to Windows

2018-12-21 Thread Frediano Ziglio
Use g_io_channel_win32_new_socket instead of g_io_channel_unix_new

Signed-off-by: Frediano Ziglio 
---
 server/event-loop.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/server/event-loop.c b/server/event-loop.c
index 56200ce5..72af9ab9 100644
--- a/server/event-loop.c
+++ b/server/event-loop.c
@@ -123,6 +123,7 @@ static gboolean watch_func(GIOChannel *source, GIOCondition 
condition,
gpointer data)
 {
 SpiceWatch *watch = data;
+// this works also under Windows despite the name
 int fd = g_io_channel_unix_get_fd(source);
 
 watch->func(fd, giocondition_to_spice_event(condition), watch->opaque);
@@ -162,7 +163,11 @@ static SpiceWatch *watch_add(const 
SpiceCoreInterfaceInternal *iface,
 
 watch = g_new0(SpiceWatch, 1);
 watch->context = iface->main_context;
+#ifndef _WIN32
 watch->channel = g_io_channel_unix_new(socket_get_raw(fd));
+#else
+watch->channel = g_io_channel_win32_new_socket(socket_get_raw(fd));
+#endif
 watch->func = func;
 watch->opaque = opaque;
 
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 24/33] test-listen: Exclude Unix sockets part under Windows

2018-12-21 Thread Frediano Ziglio
Windows does not support Unix sockets.

Signed-off-by: Frediano Ziglio 
---
 server/tests/test-listen.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/server/tests/test-listen.c b/server/tests/test-listen.c
index 640e8f12..2fd4b5a3 100644
--- a/server/tests/test-listen.c
+++ b/server/tests/test-listen.c
@@ -27,7 +27,9 @@
 #include 
 #include 
 #include 
+#ifndef _WIN32
 #include 
+#endif
 
 #include "test-glib-compat.h"
 
@@ -211,7 +213,11 @@ static GThread *fake_client_new(GThreadFunc thread_func,
 ThreadData *thread_data = g_new0(ThreadData, 1);
 
 if (port == -1) {
+#ifndef _WIN32
 thread_data->connectable = 
G_SOCKET_CONNECTABLE(g_unix_socket_address_new(hostname));
+#else
+g_assert_not_reached();
+#endif
 } else {
 g_assert_cmpuint(port, >, 0);
 g_assert_cmpuint(port, <, 65536);
@@ -317,6 +323,7 @@ static void test_connect_plain_and_tls(void)
 spice_server_destroy(server);
 }
 
+#ifndef _WIN32
 static void test_connect_unix(void)
 {
 GThread *thread;
@@ -342,6 +349,7 @@ static void test_connect_unix(void)
 test_event_loop_destroy(_loop);
 spice_server_destroy(server);
 }
+#endif
 
 static void test_connect_ko(void)
 {
@@ -365,7 +373,9 @@ int main(int argc, char **argv)
 g_test_add_func("/server/listen/connect_plain", test_connect_plain);
 g_test_add_func("/server/listen/connect_tls", test_connect_tls);
 g_test_add_func("/server/listen/connect_both", test_connect_plain_and_tls);
+#ifndef _WIN32
 g_test_add_func("/server/listen/connect_unix", test_connect_unix);
+#endif
 g_test_add_func("/server/listen/connect_ko", test_connect_ko);
 
 return g_test_run();
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 14/33] basic-event-loop: Use socket compatibility layer

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/tests/basic-event-loop.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/server/tests/basic-event-loop.c b/server/tests/basic-event-loop.c
index 607a5a5e..76b0580e 100644
--- a/server/tests/basic-event-loop.c
+++ b/server/tests/basic-event-loop.c
@@ -98,7 +98,8 @@ static void base_timer_remove(SpiceTimer *timer)
 
 static SpiceWatch *base_watch_add(int fd, int event_mask, SpiceWatchFunc func, 
void *opaque)
 {
-return base_core_interface.watch_add(_core_interface, fd, event_mask, 
func, opaque);
+return base_core_interface.watch_add(_core_interface, 
SOCKET_FROM_INT(fd), event_mask,
+ func, opaque);
 }
 
 static void base_watch_update_mask(SpiceWatch *watch, int event_mask)
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 17/33] test-stream: Use socket compatibility layer

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/tests/test-stream.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/server/tests/test-stream.c b/server/tests/test-stream.c
index d56109d1..54fbf259 100644
--- a/server/tests/test-stream.c
+++ b/server/tests/test-stream.c
@@ -113,9 +113,9 @@ int main(int argc, char *argv[])
 return -1;
 }
 
-st[0] = red_stream_new(server, sv[0]);
+st[0] = red_stream_new(server, SOCKET_FROM_INT(sv[0]));
 spice_assert(red_stream_is_plain_unix(st[0]));
-st[1] = red_stream_new(server, sv[1]);
+st[1] = red_stream_new(server, SOCKET_FROM_INT(sv[1]));
 spice_assert(red_stream_is_plain_unix(st[1]));
 
 /* send stdin, for the fun of it */
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 19/33] windows: Disable code not working on Windows

2018-12-21 Thread Frediano Ziglio
- global signals;
- CLOEXEC flag;
- mmap and statistics;
- IPTOS_LOWDELAY flag;
- Unix sockets;
- sharing file descriptors through Unix sockets;
- TCP_CORK flag.

Signed-off-by: Frediano Ziglio 
---
 server/red-channel-client.c |  2 ++
 server/red-stream.c | 11 ++-
 server/red-stream.h |  2 ++
 server/red-worker.c |  6 ++
 server/reds.c   |  4 
 server/sound.c  |  2 ++
 server/stat-file.c  |  2 ++
 server/tests/basic-event-loop.c |  2 ++
 server/tests/replay.c   |  2 ++
 tools/Makefile.am   |  2 ++
 10 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index 07f1988d..ac67efbb 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -627,6 +627,7 @@ static void 
red_channel_client_restore_main_sender(RedChannelClient *rcc)
 
 static void red_channel_client_msg_sent(RedChannelClient *rcc)
 {
+#ifndef _WIN32
 int fd;
 
 if (spice_marshaller_get_fd(rcc->priv->send_data.marshaller, )) {
@@ -640,6 +641,7 @@ static void red_channel_client_msg_sent(RedChannelClient 
*rcc)
 if (fd != -1)
 close(fd);
 }
+#endif
 
 red_channel_client_clear_sent_item(rcc);
 
diff --git a/server/red-stream.c b/server/red-stream.c
index 33086d99..a6da8385 100644
--- a/server/red-stream.c
+++ b/server/red-stream.c
@@ -41,7 +41,7 @@
 #include "reds.h"
 
 // compatibility for *BSD systems
-#ifndef TCP_CORK
+#if !defined(TCP_CORK) && !defined(_WIN32)
 #define TCP_CORK TCP_NOPUSH
 #endif
 
@@ -102,6 +102,7 @@ struct RedStreamPrivate {
 SpiceCoreInterfaceInternal *core;
 };
 
+#ifndef _WIN32
 /**
  * Set TCP_CORK on socket
  */
@@ -111,6 +112,12 @@ static int socket_set_cork(socket_t socket, int enabled)
 SPICE_VERIFY(sizeof(enabled) == sizeof(int));
 return socket_setopt(socket, IPPROTO_TCP, TCP_CORK, , 
sizeof(enabled));
 }
+#else
+static inline int socket_set_cork(socket_t socket, int enabled)
+{
+return -1;
+}
+#endif
 
 static ssize_t stream_write_cb(RedStream *s, const void *buf, size_t size)
 {
@@ -318,6 +325,7 @@ int red_stream_get_no_delay(RedStream *stream)
 return red_socket_get_no_delay(stream->socket);
 }
 
+#ifndef _WIN32
 int red_stream_send_msgfd(RedStream *stream, int fd)
 {
 struct msghdr msgh = { 0, };
@@ -360,6 +368,7 @@ int red_stream_send_msgfd(RedStream *stream, int fd)
 
 return r;
 }
+#endif
 
 ssize_t red_stream_writev(RedStream *s, const struct iovec *iov, int iovcnt)
 {
diff --git a/server/red-stream.h b/server/red-stream.h
index 52082f68..5d8cbb05 100644
--- a/server/red-stream.h
+++ b/server/red-stream.h
@@ -67,7 +67,9 @@ int red_stream_get_family(const RedStream *stream);
 bool red_stream_is_plain_unix(const RedStream *stream);
 bool red_stream_set_no_delay(RedStream *stream, bool no_delay);
 int red_stream_get_no_delay(RedStream *stream);
+#ifndef _WIN32
 int red_stream_send_msgfd(RedStream *stream, int fd);
+#endif
 
 /**
  * Set auto flush flag.
diff --git a/server/red-worker.c b/server/red-worker.c
index f016943a..10cabf00 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -1359,22 +1359,28 @@ static void *red_worker_main(void *arg)
 
 bool red_worker_run(RedWorker *worker)
 {
+#ifndef _WIN32
 sigset_t thread_sig_mask;
 sigset_t curr_sig_mask;
+#endif
 int r;
 
 spice_return_val_if_fail(worker, FALSE);
 spice_return_val_if_fail(!worker->thread, FALSE);
 
+#ifndef _WIN32
 sigfillset(_sig_mask);
 sigdelset(_sig_mask, SIGILL);
 sigdelset(_sig_mask, SIGFPE);
 sigdelset(_sig_mask, SIGSEGV);
 pthread_sigmask(SIG_SETMASK, _sig_mask, _sig_mask);
+#endif
 if ((r = pthread_create(>thread, NULL, red_worker_main, worker))) {
 spice_error("create thread failed %d", r);
 }
+#ifndef _WIN32
 pthread_sigmask(SIG_SETMASK, _sig_mask, NULL);
+#endif
 pthread_setname_np(worker->thread, "SPICE Worker");
 
 return r == 0;
diff --git a/server/reds.c b/server/reds.c
index 2897aecb..b3294357 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2529,6 +2529,7 @@ static socket_t reds_init_socket(const char *addr, int 
portnr, int family)
 socket_t slisten;
 
 if (family == AF_UNIX) {
+#ifndef _WIN32
 int len;
 struct sockaddr_un local = { 0, };
 
@@ -2549,6 +2550,9 @@ static socket_t reds_init_socket(const char *addr, int 
portnr, int family)
 }
 
 goto listen;
+#else
+return SOCKET_INVALID;
+#endif
 }
 
 memset(,0, sizeof(ai));
diff --git a/server/sound.c b/server/sound.c
index 00b473a8..482f4bc6 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -790,6 +790,7 @@ static bool 
snd_channel_client_config_socket(RedChannelClient *rcc)
 }
 #endif
 
+#ifdef IPTOS_LOWDELAY
 int tos = IPTOS_LOWDELAY;
 if (socket_setopt(stream->socket, IPPROTO_IP, IP_TOS, (void*), 
sizeof(tos)) == -1) {
 if (errno != ENOTSUP) {
@@ -798,6 

[Spice-devel] [PATCH spice-server 15/33] test-leaks: Use socket compatibility layer

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/tests/test-leaks.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/server/tests/test-leaks.c b/server/tests/test-leaks.c
index 64130c22..98f9cb67 100644
--- a/server/tests/test-leaks.c
+++ b/server/tests/test-leaks.c
@@ -35,6 +35,7 @@
 #include "test-glib-compat.h"
 #include "basic-event-loop.h"
 #include "test-display-base.h"
+#include "sys-socket.h"
 
 #define PKI_DIR SPICE_TOP_SRCDIR "/server/tests/pki/"
 
@@ -43,7 +44,7 @@ static void server_leaks(void)
 int result;
 SpiceCoreInterface *core;
 SpiceServer *server = spice_server_new();
-int sv[2];
+socket_t sv[2];
 
 g_assert_nonnull(server);
 
@@ -69,12 +70,12 @@ static void server_leaks(void)
 /* spice_server_add_ssl_client should not leak when it's given a 
disconnected socket */
 g_test_expect_message(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
   "*SSL_accept failed*");
-g_assert_cmpint(socketpair(AF_LOCAL, SOCK_STREAM, 0, sv), ==, 0);
-close(sv[1]);
-result = spice_server_add_ssl_client(server, sv[0], 1);
+g_assert_cmpint(socket_newpair(SOCK_STREAM, 0, sv), ==, 0);
+socket_close(sv[1]);
+result = spice_server_add_ssl_client(server, socket_get_raw(sv[0]), 1);
 g_assert_cmpint(result, ==, -1);
 /* if the function fails, it should not close the socket */
-g_assert_cmpint(close(sv[0]), ==, 0);
+g_assert_cmpint(socket_close(sv[0]), ==, 0);
 
 spice_server_destroy(server);
 basic_event_loop_destroy();
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 16/33] test-channel: Use socket compatibility layer

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/tests/test-channel.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/server/tests/test-channel.c b/server/tests/test-channel.c
index 1c9148df..fef295a3 100644
--- a/server/tests/test-channel.c
+++ b/server/tests/test-channel.c
@@ -152,7 +152,7 @@ 
red_test_channel_client_class_init(RedTestChannelClientClass *klass)
  * Main test part
  */
 typedef SpiceWatch *watch_add_t(const SpiceCoreInterfaceInternal *iface,
-int fd, int event_mask, SpiceWatchFunc func, 
void *opaque);
+socket_t fd, int event_mask, SpiceWatchFunc 
func, void *opaque);
 static watch_add_t *old_watch_add = NULL;
 static SpiceWatchFunc old_watch_func = NULL;
 
@@ -170,7 +170,7 @@ static void watch_func_inject(int fd, int event, void 
*opaque)
 
 static SpiceWatch *
 watch_add_inject(const SpiceCoreInterfaceInternal *iface,
- int fd, int event_mask, SpiceWatchFunc func, void *opaque)
+ socket_t fd, int event_mask, SpiceWatchFunc func, void 
*opaque)
 {
 g_assert_null(old_watch_func);
 old_watch_func = func;
@@ -178,9 +178,9 @@ watch_add_inject(const SpiceCoreInterfaceInternal *iface,
 return ret;
 }
 
-static int client_socket = -1;
+static socket_t client_socket = SOCKET_INVALID;
 
-static void send_ack_sync(int socket, uint32_t generation)
+static void send_ack_sync(socket_t socket, uint32_t generation)
 {
 struct {
 uint16_t dummy;
@@ -193,7 +193,7 @@ static void send_ack_sync(int socket, uint32_t generation)
 msg.len = GUINT32_TO_LE(sizeof(generation));
 msg.generation = GUINT32_TO_LE(generation);
 
-g_assert_cmpint(write(socket, , 10), ==, 10);
+g_assert_cmpint(socket_write(socket, , 10), ==, 10);
 }
 
 static SpiceTimer *waked_up_timer;
@@ -208,7 +208,7 @@ static void timer_wakeup(void *opaque)
 ssize_t len;
 alarm(1);
 char buffer[256];
-while ((len=recv(client_socket, buffer, sizeof(buffer), 0)) > 0)
+while ((len=socket_read(client_socket, buffer, sizeof(buffer))) > 0)
 got_data += len;
 alarm(0);
 
@@ -228,7 +228,7 @@ static void timeout_watch_count(void *opaque)
 // get all pending data
 alarm(1);
 char buffer[256];
-while (recv(client_socket, buffer, sizeof(buffer), 0) > 0)
+while (socket_read(client_socket, buffer, sizeof(buffer)) > 0)
 continue;
 alarm(0);
 
@@ -236,7 +236,7 @@ static void timeout_watch_count(void *opaque)
 watch_called_countdown = 20;
 
 // send ack reply, this should unblock data from RedChannelClient
-g_assert_cmpint(write(client_socket, "\2\0\0\0\0\0", 6), ==, 6);
+g_assert_cmpint(socket_write(client_socket, "\2\0\0\0\0\0", 6), ==, 6);
 
 // expect data soon
 waked_up_timer = core->timer_add(timer_wakeup, core);
@@ -244,10 +244,10 @@ static void timeout_watch_count(void *opaque)
 // TODO watch
 }
 
-static RedStream *create_dummy_stream(SpiceServer *server, int *p_socket)
+static RedStream *create_dummy_stream(SpiceServer *server, socket_t *p_socket)
 {
-int sv[2];
-g_assert_cmpint(socketpair(AF_LOCAL, SOCK_STREAM, 0, sv), ==, 0);
+socket_t sv[2];
+g_assert_cmpint(socket_newpair(SOCK_STREAM, 0, sv), ==, 0);
 if (p_socket) {
 *p_socket = sv[1];
 }
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 18/33] windows: Undefine some conflicting preprocessor macros

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/red-qxl.c | 1 +
 server/reds.c| 3 +++
 2 files changed, 4 insertions(+)

diff --git a/server/red-qxl.c b/server/red-qxl.c
index cec3eefb..886bf9f5 100644
--- a/server/red-qxl.c
+++ b/server/red-qxl.c
@@ -39,6 +39,7 @@
 
 #include "red-qxl.h"
 
+#undef interface
 
 struct QXLState {
 QXLWorker qxl_worker;
diff --git a/server/reds.c b/server/reds.c
index faa62ede..2897aecb 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -79,6 +79,9 @@
 #include "net-utils.h"
 #include "red-stream-device.h"
 
+#undef MAX_MONITORS
+#undef interface
+
 #define REDS_MAX_STAT_NODES 100
 
 static void reds_client_monitors_config(RedsState *reds, VDAgentMonitorsConfig 
*monitors_config);
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 08/33] reds: Use socket compatibility layer

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/red-common.h   |  4 +-
 server/reds-private.h |  4 +-
 server/reds.c | 94 +++
 server/reds.h |  2 +-
 4 files changed, 56 insertions(+), 48 deletions(-)

diff --git a/server/red-common.h b/server/red-common.h
index 181ed283..eb2fef96 100644
--- a/server/red-common.h
+++ b/server/red-common.h
@@ -35,6 +35,7 @@
 
 #include "spice.h"
 #include "utils.h"
+#include "sys-socket.h"
 
 #define SPICE_UPCAST(type, ptr) \
 (verify_expr(SPICE_OFFSETOF(type, base) == 0,SPICE_CONTAINEROF(ptr, type, 
base)))
@@ -47,7 +48,8 @@ struct SpiceCoreInterfaceInternal {
 void (*timer_cancel)(const SpiceCoreInterfaceInternal *iface, SpiceTimer 
*timer);
 void (*timer_remove)(const SpiceCoreInterfaceInternal *iface, SpiceTimer 
*timer);
 
-SpiceWatch *(*watch_add)(const SpiceCoreInterfaceInternal *iface, int fd, 
int event_mask, SpiceWatchFunc func, void *opaque);
+SpiceWatch *(*watch_add)(const SpiceCoreInterfaceInternal *iface, socket_t 
fd, int event_mask,
+ SpiceWatchFunc func, void *opaque);
 void (*watch_update_mask)(const SpiceCoreInterfaceInternal *iface, 
SpiceWatch *watch, int event_mask);
 void (*watch_remove)(const SpiceCoreInterfaceInternal *iface, SpiceWatch 
*watch);
 
diff --git a/server/reds-private.h b/server/reds-private.h
index 920edc5c..17e45caf 100644
--- a/server/reds-private.h
+++ b/server/reds-private.h
@@ -75,8 +75,8 @@ typedef struct RedServerConfig RedServerConfig;
 
 struct RedsState {
 RedServerConfig *config;
-int listen_socket;
-int secure_listen_socket;
+socket_t listen_socket;
+socket_t secure_listen_socket;
 SpiceWatch *listen_watch;
 SpiceWatch *secure_listen_watch;
 RedCharDeviceVDIPort *agent_dev;
diff --git a/server/reds.c b/server/reds.c
index 2874bd4c..faa62ede 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -106,9 +106,10 @@ static void adapter_timer_remove(const 
SpiceCoreInterfaceInternal *iface, SpiceT
 }
 
 static SpiceWatch *adapter_watch_add(const SpiceCoreInterfaceInternal *iface,
- int fd, int event_mask, SpiceWatchFunc 
func, void *opaque)
+ socket_t fd, int event_mask, 
SpiceWatchFunc func, void *opaque)
 {
-return iface->public_interface->watch_add(fd, event_mask, func, opaque);
+// note: Qemu API is fine having a SOCKET on Windows
+return iface->public_interface->watch_add(socket_get_raw(fd), event_mask, 
func, opaque);
 }
 
 static void adapter_watch_update_mask(const SpiceCoreInterfaceInternal *iface, 
SpiceWatch *watch, int event_mask)
@@ -168,7 +169,7 @@ struct RedServerConfig {
 
 int spice_port;
 int spice_secure_port;
-int spice_listen_socket_fd;
+socket_t spice_listen_socket_fd;
 char spice_addr[256];
 int spice_family;
 TicketAuthentication taTicket;
@@ -2383,7 +2384,7 @@ static void reds_handle_ssl_accept(int fd, int event, 
void *data)
 
 #define KEEPALIVE_TIMEOUT (10*60)
 
-static RedLinkInfo *reds_init_client_connection(RedsState *reds, int socket)
+static RedLinkInfo *reds_init_client_connection(RedsState *reds, socket_t 
socket)
 {
 RedLinkInfo *link;
 
@@ -2414,7 +2415,7 @@ error:
 }
 
 
-static RedLinkInfo *reds_init_client_ssl_connection(RedsState *reds, int 
socket)
+static RedLinkInfo *reds_init_client_ssl_connection(RedsState *reds, socket_t 
socket)
 {
 RedLinkInfo *link;
 RedStreamSslStatus ssl_status;
@@ -2447,7 +2448,7 @@ static RedLinkInfo 
*reds_init_client_ssl_connection(RedsState *reds, int socket)
 error:
 /* close the stream but do not close the socket, this API is
  * supposed to not close it if it fails */
-link->stream->socket = -1;
+link->stream->socket = SOCKET_INVALID;
 reds_link_free(link);
 return NULL;
 }
@@ -2459,11 +2460,12 @@ static void reds_accept_ssl_connection(int fd, int 
event, void *data)
 int socket;
 
 if ((socket = accept(fd, NULL, 0)) == -1) {
+socket_win32_set_errno();
 spice_warning("accept failed, %s", strerror(errno));
 return;
 }
 
-if (!(link = reds_init_client_ssl_connection(reds, socket))) {
+if (!(link = reds_init_client_ssl_connection(reds, 
SOCKET_FROM_INT(socket {
 close(socket);
 return;
 }
@@ -2476,6 +2478,7 @@ static void reds_accept(int fd, int event, void *data)
 int socket;
 
 if ((socket = accept(fd, NULL, 0)) == -1) {
+socket_win32_set_errno();
 spice_warning("accept failed, %s", strerror(errno));
 return;
 }
@@ -2489,7 +2492,7 @@ SPICE_GNUC_VISIBLE int 
spice_server_add_client(SpiceServer *reds, int socket, in
 {
 RedLinkInfo *link;
 
-if (!(link = reds_init_client_connection(reds, socket))) {
+if (!(link = reds_init_client_connection(reds, SOCKET_FROM_INT(socket {
 spice_warning("accept failed");
 return -1;
 }
@@ -2505,7 +2508,7 @@ 

[Spice-devel] [PATCH spice-server 06/33] sys-socket: Add socket_newpair utility

2018-12-21 Thread Frediano Ziglio
Allows to easier port socketpair.
Windows does not have this function, we need to create a pair
using 2 internet sockets and connecting one to the other.

Signed-off-by: Frediano Ziglio 
---
 server/sys-socket.c | 75 +
 server/sys-socket.h |  7 +
 2 files changed, 82 insertions(+)

diff --git a/server/sys-socket.c b/server/sys-socket.c
index 7ce5dab1..af2f0b83 100644
--- a/server/sys-socket.c
+++ b/server/sys-socket.c
@@ -209,4 +209,79 @@ SPICE_CONSTRUCTOR_FUNC(socket_win32_init)
 WSADATA wsaData;
 WSAStartup(MAKEWORD(2, 2), );
 }
+
+int socket_newpair(int type, int protocol, socket_t sv[2])
+{
+struct sockaddr_in sa, sa2;
+socklen_t addrlen;
+SOCKET s, pairs[2];
+
+if (!sv) {
+return -1;
+}
+
+/* create a listener */
+s = socket(AF_INET, type, 0);
+if (s == INVALID_SOCKET) {
+return -1;
+}
+
+pairs[1] = INVALID_SOCKET;
+
+pairs[0] = socket(AF_INET, type, 0);
+if (pairs[0] == INVALID_SOCKET) {
+goto cleanup;
+}
+
+/* bind to a random port */
+sa.sin_family = AF_INET;
+sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+sa.sin_port = 0;
+if (bind(s, (struct sockaddr*) , sizeof(sa)) < 0) {
+goto cleanup;
+}
+if (listen(s, 1) < 0) {
+goto cleanup;
+}
+
+/* connect to kernel choosen port */
+addrlen = sizeof(sa);
+if (getsockname(s, (struct sockaddr*) , ) < 0) {
+goto cleanup;
+}
+if (connect(pairs[0], (struct sockaddr*) , sizeof(sa)) < 0) {
+goto cleanup;
+}
+addrlen = sizeof(sa2);
+pairs[1] = accept(s, (struct sockaddr*) , );
+if (pairs[1] == INVALID_SOCKET) {
+goto cleanup;
+}
+
+/* check proper connection */
+addrlen = sizeof(sa);
+if (getsockname(pairs[0], (struct sockaddr*) , ) < 0) {
+goto cleanup;
+}
+addrlen = sizeof(sa2);
+if (getpeername(pairs[1], (struct sockaddr*) , ) < 0) {
+goto cleanup;
+}
+if (sa.sin_family != sa2.sin_family || sa.sin_port != sa2.sin_port
+|| sa.sin_addr.s_addr != sa2.sin_addr.s_addr) {
+goto cleanup;
+}
+
+closesocket(s);
+sv[0] = SOCKET_FROM_INT(pairs[0]);
+sv[1] = SOCKET_FROM_INT(pairs[1]);
+return 0;
+
+cleanup:
+socket_win32_set_errno();
+closesocket(s);
+closesocket(pairs[0]);
+closesocket(pairs[1]);
+return -1;
+}
 #endif
diff --git a/server/sys-socket.h b/server/sys-socket.h
index c21e9a69..9dca563b 100644
--- a/server/sys-socket.h
+++ b/server/sys-socket.h
@@ -56,6 +56,11 @@ static inline void socket_win32_set_errno(void)
 {
 }
 
+static inline int socket_newpair(int type, int protocol, socket_t sv[2])
+{
+return socketpair(AF_LOCAL, type, protocol, (int*) sv);
+}
+
 #define socket_read(sock, buf, len) read(socket_get_raw(sock), buf, len)
 #define socket_write(sock, buf, len) write(socket_get_raw(sock), buf, len)
 #define socket_writev(sock, iov, n) writev(socket_get_raw(sock), iov, n)
@@ -170,6 +175,8 @@ socket_listen(socket_t sock, int backlog)
 }
 return res;
 }
+
+int socket_newpair(int type, int protocol, socket_t sv[2]);
 #endif
 
 // common part
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 00/33] Port SPICE server to Windows

2018-12-21 Thread Frediano Ziglio
Mainly SPICE server uses lot of libraries to expose a TCP protocol.
As TCP is implemented with socket library which is quite portable was
not that hard to port.
Beside some minor feature (see REAME.Windows) all was ported.
During porting was choosen to keep Unix as the main platform, if a
change would require too much changes some Windows wrapper is
preferred instead. Not too complicated stuff, the main "wrapper" is
that Windows errors from socket are written back into errno to avoid
to change lot of code handling errors.

Frediano Ziglio (33):
  Use PRIxPTR constant for string formatting
  windows: Do not include headers not available on Windows
  build: Detect Windows build and change some definitions
  Avoids %m in formatting for Windows
  sys-socket: Introduce some utility to make sockets more portable
  sys-socket: Add socket_newpair utility
  net-utils: Use socket compatibility layer
  reds: Use socket compatibility layer
  red-stream: Use socket compatibility layer
  red-channel-client: Use socket compatibility layer
  dispatcher: Use socket compatibility layer
  event-loop: Use socket compatibility layer
  sound: Use socket compatibility layer
  basic-event-loop: Use socket compatibility layer
  test-leaks: Use socket compatibility layer
  test-channel: Use socket compatibility layer
  test-stream: Use socket compatibility layer
  windows: Undefine some conflicting preprocessor macros
  windows: Disable code not working on Windows
  replay: Force binary mode on input on Windows
  dispatcher: Port to Windows
  event-loop: Port to Windows
  tests: Provide alarm replacement for Windows
  test-listen: Exclude Unix sockets part under Windows
  tests: Exclude tests that cannot work on Windows
  test-stat: Adjust delay checks
  red-stream: Fix SSL connection for Windows
  test-display-base: Port to Windows
  reds: Explicitly include inttypes.h
  Disable recording filtering for Windows
  replay: Port to Windows
  Use structure for socket_t type instead of just a typedef
  Add some notes for the Windows port

 README.Windows|  18 ++
 configure.ac  |  18 +-
 server/Makefile.am|   3 +
 server/dispatcher.c   |  48 +++--
 server/dispatcher.h   |   2 +-
 server/event-loop.c   |  11 +-
 server/gstreamer-encoder.c|   2 +-
 server/net-utils.c|  35 ++--
 server/net-utils.h|  10 +-
 server/red-channel-client.c   |  12 +-
 server/red-channel.c  |   5 +-
 server/red-client.c   |   4 +-
 server/red-common.h   |   4 +-
 server/red-qxl.c  |   2 +-
 server/red-record-qxl.c   |   8 +-
 server/red-replay-qxl.c   |   4 +-
 server/red-stream.c   |  78 +---
 server/red-stream.h   |   6 +-
 server/red-worker.c   |   6 +
 server/reds-private.h |   4 +-
 server/reds.c | 124 +++--
 server/reds.h |   4 +-
 server/sound.c|  11 +-
 server/spice-core.h   |   6 +
 server/stat-file.c|   2 +
 server/sys-socket.c   | 287 ++
 server/sys-socket.h   | 195 
 server/tests/Makefile.am  |  11 +-
 server/tests/basic-event-loop.c   |   5 +-
 server/tests/regression-test.py   |   4 +-
 server/tests/replay.c |  18 +-
 server/tests/stat-test.c  |  12 +-
 server/tests/test-channel.c   |  23 +--
 server/tests/test-display-base.c  |  39 ++--
 server/tests/test-leaks.c |  11 +-
 server/tests/test-listen.c|  10 ++
 server/tests/test-loop.c  |   1 +
 server/tests/test-playback.c  |   1 -
 server/tests/test-record.c|   7 +-
 server/tests/test-stream-device.c |   1 +
 server/tests/test-stream.c|   4 +-
 server/tests/win-alarm.c  |  65 +++
 server/tests/win-alarm.h  |  26 +++
 tools/Makefile.am |   2 +
 44 files changed, 964 insertions(+), 185 deletions(-)
 create mode 100644 README.Windows
 create mode 100644 server/sys-socket.c
 create mode 100644 server/sys-socket.h
 create mode 100644 server/tests/win-alarm.c
 create mode 100644 server/tests/win-alarm.h

-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 11/33] dispatcher: Use socket compatibility layer

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/dispatcher.c | 26 +-
 server/dispatcher.h |  2 +-
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/server/dispatcher.c b/server/dispatcher.c
index 3e27f2c2..4cd91f11 100644
--- a/server/dispatcher.c
+++ b/server/dispatcher.c
@@ -50,8 +50,8 @@ G_DEFINE_TYPE(Dispatcher, dispatcher, G_TYPE_OBJECT)
 #define DISPATCHER_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), 
TYPE_DISPATCHER, DispatcherPrivate))
 
 struct DispatcherPrivate {
-int recv_fd;
-int send_fd;
+socket_t recv_fd;
+socket_t send_fd;
 pthread_t thread_id;
 pthread_mutex_t lock;
 DispatcherMessage *messages;
@@ -109,8 +109,8 @@ dispatcher_finalize(GObject *object)
 {
 Dispatcher *self = DISPATCHER(object);
 g_free(self->priv->messages);
-close(self->priv->send_fd);
-close(self->priv->recv_fd);
+socket_close(self->priv->send_fd);
+socket_close(self->priv->recv_fd);
 pthread_mutex_destroy(>priv->lock);
 g_free(self->priv->payload);
 G_OBJECT_CLASS(dispatcher_parent_class)->finalize(object);
@@ -119,14 +119,14 @@ dispatcher_finalize(GObject *object)
 static void dispatcher_constructed(GObject *object)
 {
 Dispatcher *self = DISPATCHER(object);
-int channels[2];
+socket_t channels[2];
 
 G_OBJECT_CLASS(dispatcher_parent_class)->constructed(object);
 
 #ifdef DEBUG_DISPATCHER
 setup_dummy_signal_handler();
 #endif
-if (socketpair(AF_LOCAL, SOCK_STREAM, 0, channels) == -1) {
+if (socket_newpair(SOCK_STREAM, 0, channels) == -1) {
 spice_error("socketpair failed %s", strerror(errno));
 return;
 }
@@ -187,7 +187,7 @@ dispatcher_new(size_t max_message_type)
  *if 0 poll first, return immediately if no bytes available, otherwise
  * read size in blocking mode.
  */
-static int read_safe(int fd, uint8_t *buf, size_t size, int block)
+static int read_safe(socket_t fd, uint8_t *buf, size_t size, int block)
 {
 int read_size = 0;
 int ret;
@@ -197,7 +197,7 @@ static int read_safe(int fd, uint8_t *buf, size_t size, int 
block)
 }
 
 if (!block) {
-struct pollfd pollfd = {.fd = fd, .events = POLLIN, .revents = 0};
+struct pollfd pollfd = {.fd = socket_get_raw(fd), .events = POLLIN, 
.revents = 0};
 while ((ret = poll(, 1, 0)) == -1) {
 if (errno == EINTR) {
 spice_debug("EINTR in poll");
@@ -211,7 +211,7 @@ static int read_safe(int fd, uint8_t *buf, size_t size, int 
block)
 }
 }
 while (read_size < size) {
-ret = read(fd, buf + read_size, size - read_size);
+ret = socket_read(fd, buf + read_size, size - read_size);
 if (ret == -1) {
 if (errno == EINTR) {
 spice_debug("EINTR in read");
@@ -232,13 +232,13 @@ static int read_safe(int fd, uint8_t *buf, size_t size, 
int block)
  * write_safe
  * @return -1 for error, otherwise number of written bytes. may be zero.
  */
-static int write_safe(int fd, uint8_t *buf, size_t size)
+static int write_safe(socket_t fd, uint8_t *buf, size_t size)
 {
 int written_size = 0;
 int ret;
 
 while (written_size < size) {
-ret = write(fd, buf + written_size, size - written_size);
+ret = socket_write(fd, buf + written_size, size - written_size);
 if (ret == -1) {
 if (errno != EINTR) {
 return -1;
@@ -310,7 +310,7 @@ void dispatcher_send_message(Dispatcher *dispatcher, 
uint32_t message_type,
 {
 DispatcherMessage *msg;
 uint32_t ack;
-int send_fd = dispatcher->priv->send_fd;
+socket_t send_fd = dispatcher->priv->send_fd;
 
 assert(dispatcher->priv->max_message_type > message_type);
 assert(dispatcher->priv->messages[message_type].handler);
@@ -393,7 +393,7 @@ void dispatcher_set_opaque(Dispatcher *self, void *opaque)
 self->priv->opaque = opaque;
 }
 
-int dispatcher_get_recv_fd(Dispatcher *dispatcher)
+socket_t dispatcher_get_recv_fd(Dispatcher *dispatcher)
 {
 return dispatcher->priv->recv_fd;
 }
diff --git a/server/dispatcher.h b/server/dispatcher.h
index bb968e56..bbc88224 100644
--- a/server/dispatcher.h
+++ b/server/dispatcher.h
@@ -155,7 +155,7 @@ void dispatcher_handle_recv_read(Dispatcher *);
  *
  * @return: receive file descriptor of the dispatcher
  */
-int dispatcher_get_recv_fd(Dispatcher *);
+socket_t dispatcher_get_recv_fd(Dispatcher *);
 
 /* dispatcher_set_opaque
  *
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 13/33] sound: Use socket compatibility layer

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/sound.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/server/sound.c b/server/sound.c
index 44b27dec..00b473a8 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -775,14 +775,13 @@ static void record_channel_send_item(RedChannelClient 
*rcc, G_GNUC_UNUSED RedPip
 
 static bool snd_channel_client_config_socket(RedChannelClient *rcc)
 {
-int tos;
 RedStream *stream = red_channel_client_get_stream(rcc);
 RedClient *red_client = red_channel_client_get_client(rcc);
 MainChannelClient *mcc = red_client_get_main(red_client);
 
 #ifdef SO_PRIORITY
 int priority = 6;
-if (setsockopt(stream->socket, SOL_SOCKET, SO_PRIORITY, (void*),
+if (socket_setopt(stream->socket, SOL_SOCKET, SO_PRIORITY, 
(void*),
sizeof(priority)) == -1) {
 if (errno != ENOTSUP) {
 red_channel_warning(red_channel_client_get_channel(rcc),
@@ -791,8 +790,8 @@ static bool 
snd_channel_client_config_socket(RedChannelClient *rcc)
 }
 #endif
 
-tos = IPTOS_LOWDELAY;
-if (setsockopt(stream->socket, IPPROTO_IP, IP_TOS, (void*), 
sizeof(tos)) == -1) {
+int tos = IPTOS_LOWDELAY;
+if (socket_setopt(stream->socket, IPPROTO_IP, IP_TOS, (void*), 
sizeof(tos)) == -1) {
 if (errno != ENOTSUP) {
 red_channel_warning(red_channel_client_get_channel(rcc),
 "setsockopt failed, %s",
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 09/33] red-stream: Use socket compatibility layer

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/red-stream.c | 32 +---
 server/red-stream.h |  4 ++--
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/server/red-stream.c b/server/red-stream.c
index 57034a64..33086d99 100644
--- a/server/red-stream.c
+++ b/server/red-stream.c
@@ -106,15 +106,15 @@ struct RedStreamPrivate {
  * Set TCP_CORK on socket
  */
 /* NOTE: enabled must be int */
-static int socket_set_cork(int socket, int enabled)
+static int socket_set_cork(socket_t socket, int enabled)
 {
 SPICE_VERIFY(sizeof(enabled) == sizeof(int));
-return setsockopt(socket, IPPROTO_TCP, TCP_CORK, , 
sizeof(enabled));
+return socket_setopt(socket, IPPROTO_TCP, TCP_CORK, , 
sizeof(enabled));
 }
 
 static ssize_t stream_write_cb(RedStream *s, const void *buf, size_t size)
 {
-return write(s->socket, buf, size);
+return socket_write(s->socket, buf, size);
 }
 
 static ssize_t stream_writev_cb(RedStream *s, const struct iovec *iov, int 
iovcnt)
@@ -132,7 +132,7 @@ static ssize_t stream_writev_cb(RedStream *s, const struct 
iovec *iov, int iovcn
 for (i = 0; i < tosend; i++) {
 expected += iov[i].iov_len;
 }
-n = writev(s->socket, iov, tosend);
+n = socket_writev(s->socket, iov, tosend);
 if (n <= expected) {
 if (n > 0)
 ret += n;
@@ -148,7 +148,7 @@ static ssize_t stream_writev_cb(RedStream *s, const struct 
iovec *iov, int iovcn
 
 static ssize_t stream_read_cb(RedStream *s, void *buf, size_t size)
 {
-return read(s->socket, buf, size);
+return socket_read(s->socket, buf, size);
 }
 
 static ssize_t stream_ssl_write_cb(RedStream *s, const void *buf, size_t size)
@@ -274,7 +274,7 @@ int red_stream_get_family(const RedStream *s)
 {
 spice_return_val_if_fail(s != NULL, -1);
 
-if (s->socket == -1)
+if (!socket_is_valid(s->socket))
 return -1;
 
 return s->priv->info->laddr_ext.ss_family;
@@ -355,7 +355,7 @@ int red_stream_send_msgfd(RedStream *stream, int fd)
 }
 
 do {
-r = sendmsg(stream->socket, , MSG_NOSIGNAL);
+r = sendmsg(socket_get_raw(stream->socket), , MSG_NOSIGNAL);
 } while (r < 0 && (errno == EINTR || errno == EAGAIN));
 
 return r;
@@ -404,7 +404,7 @@ void red_stream_free(RedStream *s)
 }
 
 red_stream_remove_watch(s);
-close(s->socket);
+socket_close(s->socket);
 
 g_free(s);
 }
@@ -416,21 +416,23 @@ void red_stream_push_channel_event(RedStream *s, int 
event)
 main_dispatcher_channel_event(md, event, s->priv->info);
 }
 
-static void red_stream_set_socket(RedStream *stream, int socket)
+static void red_stream_set_socket(RedStream *stream, socket_t socket)
 {
 stream->socket = socket;
 /* deprecated fields. Filling them for backward compatibility */
 stream->priv->info->llen = sizeof(stream->priv->info->laddr);
 stream->priv->info->plen = sizeof(stream->priv->info->paddr);
-getsockname(stream->socket, (struct 
sockaddr*)(>priv->info->laddr), >priv->info->llen);
-getpeername(stream->socket, (struct 
sockaddr*)(>priv->info->paddr), >priv->info->plen);
+socket_getsockname(stream->socket, (struct 
sockaddr*)(>priv->info->laddr),
+   >priv->info->llen);
+socket_getpeername(stream->socket, (struct 
sockaddr*)(>priv->info->paddr),
+   >priv->info->plen);
 
 stream->priv->info->flags |= SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT;
 stream->priv->info->llen_ext = sizeof(stream->priv->info->laddr_ext);
 stream->priv->info->plen_ext = sizeof(stream->priv->info->paddr_ext);
-getsockname(stream->socket, (struct 
sockaddr*)(>priv->info->laddr_ext),
+socket_getsockname(stream->socket, (struct 
sockaddr*)(>priv->info->laddr_ext),
 >priv->info->llen_ext);
-getpeername(stream->socket, (struct 
sockaddr*)(>priv->info->paddr_ext),
+socket_getpeername(stream->socket, (struct 
sockaddr*)(>priv->info->paddr_ext),
 >priv->info->plen_ext);
 }
 
@@ -446,7 +448,7 @@ void red_stream_set_channel(RedStream *stream, int 
connection_id,
 }
 }
 
-RedStream *red_stream_new(RedsState *reds, int socket)
+RedStream *red_stream_new(RedsState *reds, socket_t socket)
 {
 RedStream *stream;
 
@@ -513,7 +515,7 @@ RedStreamSslStatus red_stream_enable_ssl(RedStream *stream, 
SSL_CTX *ctx)
 BIO *sbio;
 
 // Handle SSL handshaking
-if (!(sbio = BIO_new_socket(stream->socket, BIO_NOCLOSE))) {
+if (!(sbio = BIO_new_socket(socket_get_raw(stream->socket), BIO_NOCLOSE))) 
{
 spice_warning("could not allocate ssl bio socket");
 return RED_STREAM_SSL_STATUS_ERROR;
 }
diff --git a/server/red-stream.h b/server/red-stream.h
index 9a7cc617..52082f68 100644
--- a/server/red-stream.h
+++ b/server/red-stream.h
@@ -30,7 +30,7 @@ typedef struct RedStream RedStream;
 typedef struct RedStreamPrivate RedStreamPrivate;
 
 struct RedStream {
-int socket;
+socket_t 

[Spice-devel] [PATCH spice-server 03/33] build: Detect Windows build and change some definitions

2018-12-21 Thread Frediano Ziglio
Windows needs some specific setting to use network.

Signed-off-by: Frediano Ziglio 
---
 configure.ac   | 18 +-
 server/Makefile.am |  1 +
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 96e4e66c..a2a81cef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -68,6 +68,18 @@ case $host_cpu in
 SPICE_WARNING([spice-server on non-x86_64 architectures has not been 
extensively tested])
 esac
 
+AC_MSG_CHECKING([for native Win32])
+case "$host_os" in
+ *mingw*|*cygwin*)
+os_win32=yes
+;;
+ *)
+os_win32=no
+;;
+esac
+AC_MSG_RESULT([$os_win32])
+AM_CONDITIONAL([OS_WIN32],[test "$os_win32" = "yes"])
+
 dnl =
 dnl Check optional features
 SPICE_CHECK_SMARTCARD
@@ -153,6 +165,9 @@ AC_CHECK_LIB(rt, clock_gettime, LIBRT="-lrt")
 AC_SUBST(LIBRT)
 
 AS_VAR_APPEND([SPICE_NONPKGCONFIG_LIBS], [" -pthread $LIBM $LIBRT"])
+AS_IF([test "x$os_win32" = "xyes"], [
+AS_VAR_APPEND([SPICE_NONPKGCONFIG_LIBS], [" -lws2_32"])
+])
 
 SPICE_REQUIRES=""
 
@@ -175,7 +190,8 @@ PKG_CHECK_MODULES([GOBJECT2], [gobject-2.0 >= 
$GLIB2_REQUIRED])
 AS_VAR_APPEND([SPICE_REQUIRES], [" gobject-2.0 >= $GLIB2_REQUIRED"])
 
 #used only by tests
-PKG_CHECK_MODULES([GIO_UNIX], [gio-unix-2.0 >= $GLIB2_REQUIRED])
+AS_IF([test "x$os_win32" != "xyes"],
+  PKG_CHECK_MODULES([GIO_UNIX], [gio-unix-2.0 >= $GLIB2_REQUIRED]))
 
 PIXMAN_REQUIRED=0.17.7
 PKG_CHECK_MODULES(PIXMAN, pixman-1 >= $PIXMAN_REQUIRED)
diff --git a/server/Makefile.am b/server/Makefile.am
index 34ec22ad..5009d197 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -6,6 +6,7 @@ check-valgrind:
 
 AM_CPPFLAGS =  \
-DSPICE_SERVER_INTERNAL \
+   -D_WIN32_WINNT=0x600\
$(COMMON_CFLAGS)\
$(GLIB2_CFLAGS) \
$(GOBJECT2_CFLAGS)  \
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 05/33] sys-socket: Introduce some utility to make sockets more portable

2018-12-21 Thread Frediano Ziglio
Between Unix and Windows socket are quite different:
- on Windows sockets have a different namespace from C file
  descriptors so you can't use read/write/close or similar functions;
- errors are not stored in errno but you must be read/write the
  errors with specific function;
- sometimes sockets are put in non-blocking mode automatically
  calling some functions;
- SOCKET type is 64 bit on Windows 64 which does not fit technically
  in an int (although many programs assume it and currently is true).

So encapsulate the socket APIs in some definition to make easier
and more safe to deal with them.
Where the portability to Windows would make to code more offuscated a Unix
style was preferred. For instance if errors are detected errno is set from
Windows socket error instead of changing all code handling.
Fortunately on Windows Qemu core interface accepts socket (but not
other types like C file descriptors!).

Signed-off-by: Frediano Ziglio 
---
 server/Makefile.am  |   2 +
 server/sys-socket.c | 212 
 server/sys-socket.h | 188 +++
 3 files changed, 402 insertions(+)
 create mode 100644 server/sys-socket.c
 create mode 100644 server/sys-socket.h

diff --git a/server/Makefile.am b/server/Makefile.am
index 5009d197..3c0ec0c0 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -167,6 +167,8 @@ libserver_la_SOURCES =  \
stat.h  \
stream-channel.c\
stream-channel.h\
+   sys-socket.h\
+   sys-socket.c\
red-stream-device.c \
red-stream-device.h \
sw-canvas.c \
diff --git a/server/sys-socket.c b/server/sys-socket.c
new file mode 100644
index ..7ce5dab1
--- /dev/null
+++ b/server/sys-socket.c
@@ -0,0 +1,212 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2018 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see .
+*/
+#ifdef HAVE_CONFIG_H
+#include 
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#ifndef _WIN32
+#include 
+#include 
+#include 
+#include 
+#include 
+#endif
+
+#include 
+
+#include "sys-socket.h"
+
+#ifdef _WIN32
+// Map Windows socket errors to standard C ones
+// See 
https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx
+void socket_win32_set_errno(void)
+{
+int err = EPIPE; // default
+switch (WSAGetLastError()) {
+case WSAEWOULDBLOCK:
+case WSAEINPROGRESS:
+err = EAGAIN;
+break;
+case WSAEINTR:
+err = EINTR;
+break;
+case WSAEBADF:
+err = EBADF;
+break;
+case WSA_INVALID_HANDLE:
+case WSA_INVALID_PARAMETER:
+case WSAEINVAL:
+err = EINVAL;
+break;
+case WSAENOTSOCK:
+err = ENOTSOCK;
+break;
+case WSA_NOT_ENOUGH_MEMORY:
+err = ENOMEM;
+break;
+case WSAEPROTONOSUPPORT:
+case WSAESOCKTNOSUPPORT:
+case WSAEOPNOTSUPP:
+case WSAEPFNOSUPPORT:
+case WSAEAFNOSUPPORT:
+case WSAVERNOTSUPPORTED:
+err = ENOTSUP;
+break;
+case WSAEFAULT:
+err = EFAULT;
+break;
+case WSAEACCES:
+err = EACCES;
+break;
+case WSAEMFILE:
+err = EMFILE;
+break;
+case WSAENAMETOOLONG:
+err = ENAMETOOLONG;
+break;
+case WSAENOTEMPTY:
+err = ENOTEMPTY;
+break;
+case WSA_OPERATION_ABORTED:
+case WSAECANCELLED:
+case WSA_E_CANCELLED:
+err = ECANCELED;
+break;
+case WSAEADDRINUSE:
+err = EADDRINUSE;
+break;
+case WSAENETDOWN:
+err = ENETDOWN;
+break;
+case WSAENETUNREACH:
+err = ENETUNREACH;
+break;
+case WSAENETRESET:
+err = ENETRESET;
+break;
+case WSAECONNABORTED:
+err = ECONNABORTED;
+break;
+case WSAECONNRESET:
+err = ECONNRESET;
+break;
+case WSAEISCONN:
+err = EISCONN;
+break;
+case WSAENOTCONN:
+err = ENOTCONN;
+break;
+case WSAETIMEDOUT:
+err = ETIMEDOUT;
+break;

[Spice-devel] [PATCH spice-server 10/33] red-channel-client: Use socket compatibility layer

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/red-channel-client.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index 375a60b3..07f1988d 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -697,7 +697,7 @@ static void red_channel_client_ping_timer(void *opaque)
 int so_unsent_size = 0;
 
 /* retrieving the occupied size of the socket's tcp snd buffer 
(unacked + unsent) */
-if (ioctl(rcc->priv->stream->socket, SIOCOUTQ, _unsent_size) == -1) 
{
+if (ioctl(socket_get_raw(rcc->priv->stream->socket), SIOCOUTQ, 
_unsent_size) == -1) {
 red_channel_warning(red_channel_client_get_channel(rcc),
 "ioctl(SIOCOUTQ) failed, %s", strerror(errno));
 }
@@ -1034,7 +1034,7 @@ void red_channel_client_shutdown(RedChannelClient *rcc)
 SpiceCoreInterfaceInternal *core = 
red_channel_get_core_interface(rcc->priv->channel);
 core->watch_remove(core, rcc->priv->stream->watch);
 rcc->priv->stream->watch = NULL;
-shutdown(rcc->priv->stream->socket, SHUT_RDWR);
+shutdown(socket_get_raw(rcc->priv->stream->socket), SHUT_RDWR);
 }
 }
 
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 12/33] event-loop: Use socket compatibility layer

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/event-loop.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/server/event-loop.c b/server/event-loop.c
index 413102e8..56200ce5 100644
--- a/server/event-loop.c
+++ b/server/event-loop.c
@@ -153,16 +153,16 @@ static void watch_update_mask(const 
SpiceCoreInterfaceInternal *iface,
 }
 
 static SpiceWatch *watch_add(const SpiceCoreInterfaceInternal *iface,
- int fd, int event_mask, SpiceWatchFunc func, void 
*opaque)
+ socket_t fd, int event_mask, SpiceWatchFunc func, 
void *opaque)
 {
 SpiceWatch *watch;
 
-spice_return_val_if_fail(fd != -1, NULL);
+spice_return_val_if_fail(socket_is_valid(fd), NULL);
 spice_return_val_if_fail(func != NULL, NULL);
 
 watch = g_new0(SpiceWatch, 1);
 watch->context = iface->main_context;
-watch->channel = g_io_channel_unix_new(fd);
+watch->channel = g_io_channel_unix_new(socket_get_raw(fd));
 watch->func = func;
 watch->opaque = opaque;
 
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 02/33] windows: Do not include headers not available on Windows

2018-12-21 Thread Frediano Ziglio
This is a preparatory patch for next portability patches

Signed-off-by: Frediano Ziglio 
---
 server/dispatcher.c  |  2 ++
 server/net-utils.c   |  2 ++
 server/red-channel-client.c  |  6 --
 server/red-qxl.c |  1 -
 server/red-stream.c  |  6 --
 server/reds.c| 12 
 server/reds.h|  1 -
 server/sound.c   |  2 ++
 server/spice-core.h  |  6 ++
 server/tests/replay.c|  2 ++
 server/tests/test-display-base.c |  2 ++
 server/tests/test-playback.c |  1 -
 12 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/server/dispatcher.c b/server/dispatcher.c
index 48dc915a..3e27f2c2 100644
--- a/server/dispatcher.c
+++ b/server/dispatcher.c
@@ -24,7 +24,9 @@
 #include 
 #include 
 #include 
+#ifndef _WIN32
 #include 
+#endif
 
 #include "dispatcher.h"
 
diff --git a/server/net-utils.c b/server/net-utils.c
index ca8a4e7f..802509a4 100644
--- a/server/net-utils.c
+++ b/server/net-utils.c
@@ -24,11 +24,13 @@
 #include 
 #include 
 #include 
+#ifndef _WIN32
 #include 
 #include 
 #include 
 #include 
 #include 
+#endif
 
 #include 
 
diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index b3a6ec12..375a60b3 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -22,12 +22,14 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 #include 
 #include 
+#ifndef _WIN32
+#include 
+#include 
 #include 
+#endif
 #ifdef HAVE_LINUX_SOCKIOS_H
 #include  /* SIOCOUTQ */
 #endif
diff --git a/server/red-qxl.c b/server/red-qxl.c
index 97940611..cec3eefb 100644
--- a/server/red-qxl.c
+++ b/server/red-qxl.c
@@ -24,7 +24,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include 
diff --git a/server/red-stream.c b/server/red-stream.c
index fd5b8cd1..57034a64 100644
--- a/server/red-stream.c
+++ b/server/red-stream.c
@@ -20,11 +20,13 @@
 #endif
 
 #include 
-#include 
 #include 
-#include 
 #include 
+#ifndef _WIN32
+#include 
+#include 
 #include 
+#endif
 
 #include 
 
diff --git a/server/reds.c b/server/reds.c
index 98a3435d..aa3f8ca7 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -22,16 +22,21 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
+#ifndef _WIN32
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
-#include 
+#include 
+#else
+#include 
+#endif
 
 #include 
 
@@ -40,7 +45,6 @@
 #endif
 
 #include 
-#include 
 
 #include 
 #include 
diff --git a/server/reds.h b/server/reds.h
index 9f17a5ec..106310eb 100644
--- a/server/reds.h
+++ b/server/reds.h
@@ -19,7 +19,6 @@
 #define REDS_H_
 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/server/sound.c b/server/sound.c
index 8cdb7d71..44b27dec 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -23,10 +23,12 @@
 #include 
 #include 
 #include 
+#ifndef _WIN32
 #include 
 #include 
 #include 
 #include 
+#endif
 
 #include 
 #include 
diff --git a/server/spice-core.h b/server/spice-core.h
index 3d5c83bf..d77c4f9e 100644
--- a/server/spice-core.h
+++ b/server/spice-core.h
@@ -23,7 +23,13 @@
 #endif
 
 #include 
+#ifndef _WIN32
 #include 
+#else
+#include 
+#include 
+typedef int socklen_t;
+#endif
 #include 
 #include 
 #include 
diff --git a/server/tests/replay.c b/server/tests/replay.c
index bd9420b8..b689044a 100644
--- a/server/tests/replay.c
+++ b/server/tests/replay.c
@@ -30,7 +30,9 @@
 #include 
 #include 
 #include 
+#ifndef _WIN32
 #include 
+#endif
 #include 
 #include 
 #include 
diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
index 3ca85f3a..868521bc 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -22,8 +22,10 @@
 #include 
 #include 
 #include 
+#ifndef _WIN32
 #include 
 #include 
+#endif
 #include 
 #include 
 #include 
diff --git a/server/tests/test-playback.c b/server/tests/test-playback.c
index 9b2dcc10..cbefb9b0 100644
--- a/server/tests/test-playback.c
+++ b/server/tests/test-playback.c
@@ -17,7 +17,6 @@
 */
 #include 
 #include 
-#include 
 #include 
 #include 
 
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 01/33] Use PRIxPTR constant for string formatting

2018-12-21 Thread Frediano Ziglio
These constants are meant to be used in format string for size_t
types. Use them for portability.

Signed-off-by: Frediano Ziglio 
---
 server/gstreamer-encoder.c | 2 +-
 server/red-channel.c   | 5 +++--
 server/red-client.c| 4 ++--
 server/red-replay-qxl.c| 4 ++--
 server/reds.c  | 4 ++--
 5 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/server/gstreamer-encoder.c b/server/gstreamer-encoder.c
index 04f0c02f..f81fa223 100644
--- a/server/gstreamer-encoder.c
+++ b/server/gstreamer-encoder.c
@@ -1080,7 +1080,7 @@ static void set_gstenc_bitrate(SpiceGstEncoder *encoder)
 break;
 }
 default:
-spice_warning("the %s property has an unsupported type %zu",
+spice_warning("the %s property has an unsupported type %" PRIuPTR,
   prop, param->value_type);
 }
 spice_debug("setting the GStreamer %s to %"PRIu64, prop, gst_bit_rate);
diff --git a/server/red-channel.c b/server/red-channel.c
index 448b690e..b94d26b7 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -190,7 +190,7 @@ red_channel_constructed(GObject *object)
 {
 RedChannel *self = RED_CHANNEL(object);
 
-red_channel_debug(self, "thread_id 0x%lx", self->priv->thread_id);
+red_channel_debug(self, "thread_id 0x%" PRIxPTR, self->priv->thread_id);
 
 RedChannelClass *klass = RED_CHANNEL_GET_CLASS(self);
 
@@ -468,7 +468,8 @@ void red_channel_remove_client(RedChannel *channel, 
RedChannelClient *rcc)
 g_return_if_fail(channel == red_channel_client_get_channel(rcc));
 
 if (!pthread_equal(pthread_self(), channel->priv->thread_id)) {
-red_channel_warning(channel, "channel->thread_id (0x%lx) != 
pthread_self (0x%lx)."
+red_channel_warning(channel,
+"channel->thread_id (0x%" PRIxPTR ") != 
pthread_self (0x%" PRIxPTR ")."
 "If one of the threads is != io-thread && != 
vcpu-thread, "
 "this might be a BUG",
 channel->priv->thread_id, pthread_self());
diff --git a/server/red-client.c b/server/red-client.c
index 7d14bd19..66bda8da 100644
--- a/server/red-client.c
+++ b/server/red-client.c
@@ -176,7 +176,7 @@ void red_client_migrate(RedClient *client)
 RedChannel *channel;
 
 if (!pthread_equal(pthread_self(), client->thread_id)) {
-spice_warning("client->thread_id (0x%lx) != pthread_self (0x%lx)."
+spice_warning("client->thread_id (0x%" PRIxPTR ") != pthread_self 
(0x%" PRIxPTR ")."
   "If one of the threads is != io-thread && != 
vcpu-thread,"
   " this might be a BUG",
   client->thread_id, pthread_self());
@@ -194,7 +194,7 @@ void red_client_destroy(RedClient *client)
 RedChannelClient *rcc;
 
 if (!pthread_equal(pthread_self(), client->thread_id)) {
-spice_warning("client->thread_id (0x%lx) != pthread_self (0x%lx)."
+spice_warning("client->thread_id (0x%" PRIxPTR ") != pthread_self 
(0x%" PRIxPTR ")."
   "If one of the threads is != io-thread && != 
vcpu-thread,"
   " this might be a BUG",
   client->thread_id,
diff --git a/server/red-replay-qxl.c b/server/red-replay-qxl.c
index 6958a495..b3c61769 100644
--- a/server/red-replay-qxl.c
+++ b/server/red-replay-qxl.c
@@ -227,7 +227,7 @@ static replay_t read_binary(SpiceReplay *replay, const char 
*prefix, size_t *siz
 uint8_t *zlib_buffer;
 z_stream strm;
 
-snprintf(template, sizeof(template), "binary %%d %s %%ld:%%n", prefix);
+snprintf(template, sizeof(template), "binary %%d %s %%" PRIdPTR ":%%n", 
prefix);
 replay_fscanf_check(replay, template, _zlib, size, >end_pos);
 if (replay->error) {
 return REPLAY_ERROR;
@@ -266,7 +266,7 @@ static replay_t read_binary(SpiceReplay *replay, const char 
*prefix, size_t *siz
 exit(1);
 }
 if ((ret = inflate(, Z_NO_FLUSH)) != Z_STREAM_END) {
-spice_error("inflate error %d (disc: %ld)", ret, *size - 
strm.total_out);
+spice_error("inflate error %d (disc: %" PRIdPTR ")", ret, *size - 
strm.total_out);
 if (ret == Z_DATA_ERROR) {
 /* last operation may be wrong. since we do the recording
  * in red_worker, when there is a shutdown from the vcpu/io 
thread
diff --git a/server/reds.c b/server/reds.c
index cdbb94cb..98a3435d 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -1149,7 +1149,7 @@ static void reds_on_main_agent_monitors_config(RedsState 
*reds,
 }
 spice_buffer_append(cmc, message, size);
 if (sizeof(VDAgentMessage) > cmc->offset) {
-spice_debug("not enough data yet. %zd", cmc->offset);
+spice_debug("not enough data yet. %" PRIdPTR, cmc->offset);
 return;
 }
 msg_header = (VDAgentMessage *)cmc->buffer;
@@ -1157,7 +1157,7 @@ static void 

[Spice-devel] [PATCH spice-server 04/33] Avoids %m in formatting for Windows

2018-12-21 Thread Frediano Ziglio
Not supported.

Signed-off-by: Frediano Ziglio 
--
TODO find a better solution
---
 server/reds.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/server/reds.c b/server/reds.c
index aa3f8ca7..2874bd4c 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3582,7 +3582,14 @@ static const char* parse_next_video_codec(const char 
*codecs, char **encoder,
 }
 int n;
 *encoder = *codec = NULL;
+#ifndef _WIN32
 if (sscanf(codecs, "%m[0-9a-zA-Z_]:%m[0-9a-zA-Z_]%n", encoder, codec, ) 
== 2) {
+#else
+char encoder_buf[130], codec_buf[130];
+if (sscanf(codecs, "%128[0-9a-zA-Z_]:%128[0-9a-zA-Z_]%n", encoder_buf, 
codec_buf, ) == 2) {
+*encoder = strdup(encoder_buf);
+*codec = strdup(codec_buf);
+#endif
 // this avoids accepting "encoder:codec" followed by garbage like "$%*"
 if (codecs[n] != ';' && codecs[n] != '\0') {
 free(*codec);
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 07/33] net-utils: Use socket compatibility layer

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/net-utils.c | 33 +
 server/net-utils.h | 10 ++
 2 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/server/net-utils.c b/server/net-utils.c
index 802509a4..8a5b62cb 100644
--- a/server/net-utils.c
+++ b/server/net-utils.c
@@ -43,11 +43,11 @@
  *
  * Returns: #true if the operation succeeded, #false otherwise.
  */
-bool red_socket_set_keepalive(int fd, bool enable, int timeout)
+bool red_socket_set_keepalive(socket_t sock, bool enable, int timeout)
 {
 int keepalive = !!enable;
 
-if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, , 
sizeof(keepalive)) == -1) {
+if (socket_setopt(sock, SOL_SOCKET, SO_KEEPALIVE,, 
sizeof(keepalive)) == -1) {
 if (errno != ENOTSUP) {
 g_warning("setsockopt for keepalive failed, %s", strerror(errno));
 return false;
@@ -59,7 +59,7 @@ bool red_socket_set_keepalive(int fd, bool enable, int 
timeout)
 }
 
 #ifdef HAVE_TCP_KEEPIDLE
-if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, , sizeof(timeout)) 
== -1) {
+if (socket_setopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, , 
sizeof(timeout)) == -1) {
 if (errno != ENOTSUP) {
 g_warning("setsockopt for keepalive timeout failed, %s", 
strerror(errno));
 return false;
@@ -77,12 +77,11 @@ bool red_socket_set_keepalive(int fd, bool enable, int 
timeout)
  *
  * Returns: #true if the operation succeeded, #false otherwise.
  */
-bool red_socket_set_no_delay(int fd, bool no_delay)
+bool red_socket_set_no_delay(socket_t sock, bool no_delay)
 {
 int optval = no_delay;
 
-if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
-   , sizeof(optval)) != 0) {
+if (socket_setopt(sock, IPPROTO_TCP, TCP_NODELAY, , sizeof(optval)) 
!= 0) {
 if (errno != ENOTSUP && errno != ENOPROTOOPT) {
 spice_warning("setsockopt failed, %s", strerror(errno));
 return false;
@@ -99,9 +98,11 @@ bool red_socket_set_no_delay(int fd, bool no_delay)
  *
  * Returns: #true if the operation succeeded, #false otherwise.
  */
-bool red_socket_set_non_blocking(int fd, bool non_blocking)
+bool red_socket_set_non_blocking(socket_t sock, bool non_blocking)
 {
+#ifndef _WIN32
 int flags;
+int fd = socket_get_raw(sock);
 
 if ((flags = fcntl(fd, F_GETFL)) == -1) {
 spice_warning("fnctl(F_GETFL) failed, %s", strerror(errno));
@@ -120,6 +121,15 @@ bool red_socket_set_non_blocking(int fd, bool non_blocking)
 }
 
 return true;
+#else
+u_long ioctl_nonblocking = 1;
+
+if (ioctlsocket(socket_get_raw(sock), FIONBIO, _nonblocking) != 0) {
+spice_warning("ioctlsocket(FIONBIO) failed, %d", WSAGetLastError());
+return false;
+}
+return true;
+#endif
 }
 
 /**
@@ -128,15 +138,14 @@ bool red_socket_set_non_blocking(int fd, bool 
non_blocking)
  *
  * Returns: The current value of TCP_NODELAY for @fd, -1 if an error occurred
  */
-int red_socket_get_no_delay(int fd)
+int red_socket_get_no_delay(socket_t sock)
 {
 int delay_val;
 socklen_t opt_size = sizeof(delay_val);
 
-if (getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, _val,
-   _size) == -1) {
-spice_warning("getsockopt failed, %s", strerror(errno));
-return -1;
+if (socket_getopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*) _val, 
_size) == -1) {
+spice_warning("getsockopt failed, %s", strerror(errno));
+return -1;
 }
 
 return delay_val;
diff --git a/server/net-utils.h b/server/net-utils.h
index f95d689a..89e48ea8 100644
--- a/server/net-utils.h
+++ b/server/net-utils.h
@@ -20,9 +20,11 @@
 
 #include 
 
-bool red_socket_set_keepalive(int fd, bool enable, int timeout);
-bool red_socket_set_no_delay(int fd, bool no_delay);
-int red_socket_get_no_delay(int fd);
-bool red_socket_set_non_blocking(int fd, bool non_blocking);
+#include "sys-socket.h"
+
+bool red_socket_set_keepalive(socket_t fd, bool enable, int timeout);
+bool red_socket_set_no_delay(socket_t fd, bool no_delay);
+int red_socket_get_no_delay(socket_t fd);
+bool red_socket_set_non_blocking(socket_t fd, bool non_blocking);
 
 #endif /* RED_NET_UTILS_H_ */
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [spice-gtk] gtk-session: do not request guest's clipboard data unnecessarily

2018-12-21 Thread Christophe Fergeau
On Thu, Dec 20, 2018 at 04:41:48PM -0500, james harvey wrote:
> On Thu, Dec 20, 2018 at 12:36 PM Christophe Fergeau  
> wrote:
> > Hey,
> >
> > With this patch applied, I cannot seem to be able to copy from client to
> > guest when using wayland.
> >
> > Christophe
> 
> I admit I only have a vague understanding of what Wayland is.  I'm
> using Xorg & Plasma on Arch Linux.  Some Wayland packages are
> installed (kwayland, kwayland-integration, wayland, wayland-protocols,
> xorg-server-xwayland) becuase they're dependencies for several things
> like gtk3, mesa, and vulkan-radeon.  If I understand correctly, that's
> just the protocol and library.  Weston isn't installed.  So, I'm not
> 100% positive if these few Wayland packages on my system are being
> used in any way, or if they sit unused since I'm not using Weston.

Yeah, at the moment you have Plasma running on top of Xorg, if you were
using wayland, Plasma would have to be ported to wayland, which means
turning it in a wayland compositor (this is what gnome-shell did), or
making it run on top of a wayland compositor such a Weston.

Christophe


signature.asc
Description: PGP signature
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [spice-gtk] gtk-session: do not request guest's clipboard data unnecessarily

2018-12-21 Thread Victor Toso
Hi,

On Thu, Dec 20, 2018 at 06:36:02PM +0100, Christophe Fergeau wrote:
> Hey,
> 
> With this patch applied, I cannot seem to be able to copy from client to
> guest when using wayland.
> 
> Christophe

You are right... I thought I had tested it properly...

> On Wed, Dec 19, 2018 at 03:29:44PM +0100, Victor Toso wrote:
> > From: Victor Toso 
> > 
> > If SpiceGtkSession is holding the keyboard, that's huge indication
> > that we should not be requesting clipboard data yet. The proper time
> > to request it is when another application in the client machine is
> > asking for it, which means the user would switch to another
> > application to paste the guest's clipboard data.
> > 
> > This is default behavior over wayland.
> > 
> > Related: https://gitlab.freedesktop.org/spice/win32/vd_agent/issues/6
> > Related: https://gitlab.freedesktop.org/spice/linux/vd_agent/issues/9
> > Related: https://bugzilla.redhat.com/show_bug.cgi?id=1594876
> > 
> > Signed-off-by: Victor Toso 
> > Tested-by: James Harvey @jamespharvey20
> > ---
> >  src/spice-gtk-session.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
> > index 1ccae07..0d3438c 100644
> > --- a/src/spice-gtk-session.c
> > +++ b/src/spice-gtk-session.c
> > @@ -645,9 +645,11 @@ static void clipboard_owner_change(GtkClipboard
> > *clipboard,
> >  if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(self))
> >  break;
> >  
> > +
> >  s->clipboard_by_guest[selection] = FALSE;
> >  s->clip_hasdata[selection] = TRUE;
> > -if (s->auto_clipboard_enable && !read_only(self))
> > +if (s->auto_clipboard_enable && !read_only(self) &&
> > +!spice_gtk_session_get_keyboard_has_focus(self))
> >  gtk_clipboard_request_targets(clipboard, clipboard_get_targets,
> >get_weak_ref(self));
> >  break;
> > -- 
> > 2.19.2
> > 
> > ___
> > Spice-devel mailing list
> > Spice-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/spice-devel




signature.asc
Description: PGP signature
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 3/4] test-playback: Remove obsolete debug

2018-12-21 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 server/tests/test-playback.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/server/tests/test-playback.c b/server/tests/test-playback.c
index a62b8299..87469c8e 100644
--- a/server/tests/test-playback.c
+++ b/server/tests/test-playback.c
@@ -87,9 +87,6 @@ static void playback_timer_cb(SPICE_GNUC_UNUSED void *opaque)
 }
 last_sent_usec = cur_usec;
 while (samples_to_send > num_samples && frame) {
-#if 0
-printf("samples_to_send = %d\n", samples_to_send);
-#endif
 samples_to_send -= num_samples;
 for (i = 0 ; i < num_samples; ++i) {
 frame[i] = (((uint16_t)((1<<14)*sin((t+i)/10))) << 16) + 
(((uint16_t)((1<<14)*sin((t+i)/10;
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 2/4] test-playback: Update misleading comments

2018-12-21 Thread Frediano Ziglio
We are waiting for a client connection, channel is already there

Signed-off-by: Frediano Ziglio 
---
 server/tests/test-playback.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/server/tests/test-playback.c b/server/tests/test-playback.c
index 32f091ef..a62b8299 100644
--- a/server/tests/test-playback.c
+++ b/server/tests/test-playback.c
@@ -72,12 +72,12 @@ static void playback_timer_cb(SPICE_GNUC_UNUSED void 
*opaque)
 
 get_frame();
 if (!frame) {
-/* continue waiting until there is a channel */
+/* continue waiting until there is a client */
 core->timer_start(playback_timer, 100);
 return;
 }
 
-/* we have a channel */
+/* we have a client */
 gettimeofday(, NULL);
 cur_usec = cur.tv_usec + cur.tv_sec * 1e6;
 if (last_sent_usec == 0) {
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 4/4] test-playback: Simplify wave generation formulae

2018-12-21 Thread Frediano Ziglio
Split level computation, make clear is a sine wave on both channels.

Signed-off-by: Frediano Ziglio 
---
 server/tests/test-playback.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/server/tests/test-playback.c b/server/tests/test-playback.c
index 87469c8e..290c8609 100644
--- a/server/tests/test-playback.c
+++ b/server/tests/test-playback.c
@@ -89,7 +89,8 @@ static void playback_timer_cb(SPICE_GNUC_UNUSED void *opaque)
 while (samples_to_send > num_samples && frame) {
 samples_to_send -= num_samples;
 for (i = 0 ; i < num_samples; ++i) {
-frame[i] = (((uint16_t)((1<<14)*sin((t+i)/10))) << 16) + 
(((uint16_t)((1<<14)*sin((t+i)/10;
+uint16_t level = (1<<14) * sin((t+i)/10.0);
+frame[i] = (level << 16) + level;
 }
 t += num_samples;
 spice_server_playback_put_samples(_instance, frame);
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 1/4] test-playback: Remove useless check for "frame"

2018-12-21 Thread Frediano Ziglio
We just fill it up, can't be NULL.

Signed-off-by: Frediano Ziglio 
---
 server/tests/test-playback.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/server/tests/test-playback.c b/server/tests/test-playback.c
index cbefb9b0..32f091ef 100644
--- a/server/tests/test-playback.c
+++ b/server/tests/test-playback.c
@@ -95,10 +95,8 @@ static void playback_timer_cb(SPICE_GNUC_UNUSED void *opaque)
 frame[i] = (((uint16_t)((1<<14)*sin((t+i)/10))) << 16) + 
(((uint16_t)((1<<14)*sin((t+i)/10;
 }
 t += num_samples;
-if (frame) {
-spice_server_playback_put_samples(_instance, frame);
-frame = NULL;
-}
+spice_server_playback_put_samples(_instance, frame);
+frame = NULL;
 get_frame();
 }
 core->timer_start(playback_timer, playback_timer_ms);
-- 
2.17.2

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel