Re: [Qemu-devel] [PULL v4 4/9] io: add QIOChannelSocket class

2016-01-08 Thread Paolo Bonzini


On 18/12/2015 13:21, Daniel P. Berrange wrote:
> +
> +if (nfds > SOCKET_MAX_FDS) {
> +error_setg_errno(errp, -EINVAL,
> + "Only %d FDs can be sent, got %zu",
> + SOCKET_MAX_FDS, nfds);
> +return -1;
> +}

Hi Daniel,

the second argument here should be positive (s/-EINVAL/EINVAL).

Paolo



Re: [Qemu-devel] [PULL v4 4/9] io: add QIOChannelSocket class

2016-01-08 Thread Daniel P. Berrange
On Fri, Jan 08, 2016 at 10:04:23AM +0100, Paolo Bonzini wrote:
> 
> 
> On 18/12/2015 13:21, Daniel P. Berrange wrote:
> > +
> > +if (nfds > SOCKET_MAX_FDS) {
> > +error_setg_errno(errp, -EINVAL,
> > + "Only %d FDs can be sent, got %zu",
> > + SOCKET_MAX_FDS, nfds);
> > +return -1;
> > +}
> 
> Hi Daniel,
> 
> the second argument here should be positive (s/-EINVAL/EINVAL).

Ok, I'll send followup patch(es) to fix this & the bugs you mention
against the other 2 patches.

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



[Qemu-devel] [PULL v4 4/9] io: add QIOChannelSocket class

2015-12-18 Thread Daniel P. Berrange
Implement a QIOChannel subclass that supports sockets I/O.
The implementation is able to manage a single socket file
descriptor, whether a TCP/UNIX listener, TCP/UNIX connection,
or a UDP datagram. It provides APIs which can listen and
connect either asynchronously or synchronously. Since there
is no asynchronous DNS lookup API available, it uses the
QIOTask helper for spawning a background thread to ensure
non-blocking operation.

Signed-off-by: Daniel P. Berrange 
---
 configure  |  11 +
 include/io/channel-socket.h| 244 ++
 include/qemu/sockets.h |  19 ++
 io/Makefile.objs   |   1 +
 io/channel-socket.c| 741 +
 scripts/create_config  |   9 +
 tests/.gitignore   |   1 +
 tests/Makefile |   3 +
 tests/io-channel-helpers.c | 246 ++
 tests/io-channel-helpers.h |  42 +++
 tests/test-io-channel-socket.c | 399 ++
 trace-events   |  19 ++
 util/qemu-sockets.c|   2 +-
 13 files changed, 1736 insertions(+), 1 deletion(-)
 create mode 100644 include/io/channel-socket.h
 create mode 100644 io/channel-socket.c
 create mode 100644 tests/io-channel-helpers.c
 create mode 100644 tests/io-channel-helpers.h
 create mode 100644 tests/test-io-channel-socket.c

diff --git a/configure b/configure
index b9552fd..375f103 100755
--- a/configure
+++ b/configure
@@ -2427,6 +2427,14 @@ fi
 
 
 ##
+# getifaddrs (for tests/test-io-channel-socket )
+
+have_ifaddrs_h=yes
+if ! check_include "ifaddrs.h" ; then
+  have_ifaddrs_h=no
+fi
+
+##
 # VTE probe
 
 if test "$vte" != "no"; then
@@ -5137,6 +5145,9 @@ fi
 if test "$tasn1" = "yes" ; then
   echo "CONFIG_TASN1=y" >> $config_host_mak
 fi
+if test "$have_ifaddrs_h" = "yes" ; then
+echo "HAVE_IFADDRS_H=y" >> $config_host_mak
+fi
 if test "$vte" = "yes" ; then
   echo "CONFIG_VTE=y" >> $config_host_mak
   echo "VTE_CFLAGS=$vte_cflags" >> $config_host_mak
diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h
new file mode 100644
index 000..0719757
--- /dev/null
+++ b/include/io/channel-socket.h
@@ -0,0 +1,244 @@
+/*
+ * QEMU I/O channels sockets driver
+ *
+ * Copyright (c) 2015 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 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 .
+ *
+ */
+
+#ifndef QIO_CHANNEL_SOCKET_H__
+#define QIO_CHANNEL_SOCKET_H__
+
+#include "io/channel.h"
+#include "io/task.h"
+#include "qemu/sockets.h"
+
+#define TYPE_QIO_CHANNEL_SOCKET "qio-channel-socket"
+#define QIO_CHANNEL_SOCKET(obj) \
+OBJECT_CHECK(QIOChannelSocket, (obj), TYPE_QIO_CHANNEL_SOCKET)
+
+typedef struct QIOChannelSocket QIOChannelSocket;
+
+/**
+ * QIOChannelSocket:
+ *
+ * The QIOChannelSocket class provides a channel implementation
+ * that can transport data over a UNIX socket or TCP socket.
+ * Beyond the core channel API, it also provides functionality
+ * for accepting client connections, tuning some socket
+ * parameters and getting socket address strings.
+ */
+
+struct QIOChannelSocket {
+QIOChannel parent;
+int fd;
+struct sockaddr_storage localAddr;
+socklen_t localAddrLen;
+struct sockaddr_storage remoteAddr;
+socklen_t remoteAddrLen;
+};
+
+
+/**
+ * qio_channel_socket_new:
+ *
+ * Create a channel for performing I/O on a socket
+ * connection, that is initially closed. After
+ * creating the socket, it must be setup as a client
+ * connection or server.
+ *
+ * Returns: the socket channel object
+ */
+QIOChannelSocket *
+qio_channel_socket_new(void);
+
+/**
+ * qio_channel_socket_new_fd:
+ * @fd: the socket file descriptor
+ * @errp: pointer to an uninitialized error object
+ *
+ * Create a channel for performing I/O on the socket
+ * connection represented by the file descriptor @fd.
+ *
+ * Returns: the socket channel object, or NULL on error
+ */
+QIOChannelSocket *
+qio_channel_socket_new_fd(int fd,
+  Error **errp);
+
+
+/**
+ * qio_channel_socket_connect_sync:
+ * @ioc: the socket channel object
+ * @addr: the address to connect to
+ * @errp: pointer to an uninitialized error object
+ *
+ * Attempt to connect to the address @addr. This method
+ * will run in the foreground