From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yj8Bn-00034d-Ar for qemu-devel@nongnu.org; Fri, 17 Apr 2015 11:28:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yj8Bk-0002Id-2v for qemu-devel@nongnu.org; Fri, 17 Apr 2015 11:28:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50987) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yj8Bj-0002IG-Mq for qemu-devel@nongnu.org; Fri, 17 Apr 2015 11:28:16 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 3CB2491763 for ; Fri, 17 Apr 2015 15:28:15 +0000 (UTC) Message-ID: <55312689.3070202@redhat.com> Date: Fri, 17 Apr 2015 17:28:09 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1429280557-8887-1-git-send-email-berrange@redhat.com> <1429280557-8887-24-git-send-email-berrange@redhat.com> In-Reply-To: <1429280557-8887-24-git-send-email-berrange@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v1 RFC 23/34] io: add QIOChannelSocket class List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Gerd Hoffmann , Stefan Hajnoczi On 17/04/2015 16:22, Daniel P. Berrange wrote: > Implement a QIOChannel subclass that supports sockets I/O >=20 > TBD check errno handling of windows port & fix watch impl >=20 > Signed-off-by: Daniel P. Berrange > --- > include/io/channel-socket.h | 168 +++++++++++++ > io/Makefile.objs | 1 + > io/channel-socket.c | 572 ++++++++++++++++++++++++++++++++++++= ++++++++ > 3 files changed, 741 insertions(+) > create mode 100644 include/io/channel-socket.h > create mode 100644 io/channel-socket.c >=20 > diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h > new file mode 100644 > index 0000000..b95349b > --- /dev/null > +++ b/include/io/channel-socket.h > @@ -0,0 +1,168 @@ > +/* > + * 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 "qemu/sockets.h" > + > +#define TYPE_QIO_CHANNEL_SOCKET "qemu:io-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_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_get_local_addr_string: > + * @ioc: the socket channel object > + * @hostname: pointer to be filled with hostname string > + * @servicename: pointer to be filled with servicename string > + * @family: pointer to be filled with network address family > + * @errp: pointer to an uninitialized error object > + * > + * Get the string representation of the local socket > + * address. The address information will be stored in > + * the @hostname, @servicename and @family parameters. > + * The @hostname and @servicename strings will be > + * allocated to the size required and should be free > + * with g_free() when no longer required > + * > + * Returns: 0 on success, -1 on error > + */ > +int > +qio_channel_socket_get_local_addr_string(QIOChannelSocket *ioc, > + char **hostname, > + char **servicename, > + NetworkAddressFamily *family, > + Error **errp); > + > +/** > + * qio_channel_socket_get_remote_addr_string: > + * @ioc: the socket channel object > + * @hostname: pointer to be filled with hostname string > + * @servicename: pointer to be filled with servicename string > + * @family: pointer to be filled with network address family > + * @errp: pointer to an uninitialized error object > + * > + * Get the string representation of the remote socket > + * address. The address information will be stored in > + * the @hostname, @servicename and @family parameters. > + * The @hostname and @servicename strings will be > + * allocated to the size required and should be free > + * with g_free() when no longer required > + * > + * Returns: 0 on success, -1 on error > + */ > +int > +qio_channel_socket_get_remote_addr_string(QIOChannelSocket *ioc, > + char **hostname, > + char **servicename, > + NetworkAddressFamily *family= , > + Error **errp); Would it be possible to change these to use a SocketAddress* type? > + > +/** > + * qio_channel_socket_set_nodelay: > + * @ioc: the socket channel object > + * @enabled: the new flag state > + * > + * Set the state of the NODELAY socket flag. If the The function name is okay, but please write TCP_NODELAY in the documentation, or talk about Nagle's algorithm instead of mentioning the flag. > + * @enabled parameter is true, then NODELAY will be > + * set and data will be transmitted immediately. If > + * @enabled is false, then data may be temporarily > + * held for transmission to enable writes to be > + * coallesced. > + */ > +void > +qio_channel_socket_set_nodelay(QIOChannelSocket *ioc, > + bool enabled); > + > +/** > + * qio_channel_socket_accept: > + * @ioc: the socket channel object > + * @errp: pointer to an uninitialized error object > + * > + * If the socket represents a server, then this accepts > + * a new client connection. The returned channel will > + * represent the connected client socket. > + * > + * Returns: the new client channel, or NULL on error > + */ > +QIOChannelSocket * > +qio_channel_socket_accept(QIOChannelSocket *ioc, > + Error **errp); Does it make sense for a passive socket to be a QIOChannelSocket? We have already a pretty decent API in util/qemu-sockets.c, and QIOChannelSocket will become more similar to qemu-sockets if you switch to SocketAddress. Perhaps this function can just take a file descriptor? Paolo > + > +typedef enum { > + QIO_CHANNEL_SOCKET_SHUTDOWN_BOTH, > + QIO_CHANNEL_SOCKET_SHUTDOWN_READ, > + QIO_CHANNEL_SOCKET_SHUTDOWN_WRITE, > +} QIOChannelSocketShutdown; > + > +/** > + * qio_channel_socket_shutdown: > + * @ioc: the socket channel object > + * @how: the direction to shutdown > + * @errp: pointer to an uninitialized error object > + * > + * Shutdowns transmission or receiving on a socket > + * without closing the socket file descriptor. > + * > + * Returns: 0 on success, -1 on error > + */ > +int > +qio_channel_socket_shutdown(QIOChannelSocket *ioc, > + QIOChannelSocketShutdown how, > + Error **errp); > + > +#endif /* QIO_CHANNEL_SOCKET_H__ */ > diff --git a/io/Makefile.objs b/io/Makefile.objs > index a776676..4f5e276 100644 > --- a/io/Makefile.objs > +++ b/io/Makefile.objs > @@ -1,2 +1,3 @@ > util-obj-y +=3D channel.o > util-obj-y +=3D channel-unix.o > +util-obj-y +=3D channel-socket.o > diff --git a/io/channel-socket.c b/io/channel-socket.c > new file mode 100644 > index 0000000..5eacf38 > --- /dev/null > +++ b/io/channel-socket.c > @@ -0,0 +1,572 @@ > +/* > + * 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 . > + * > + */ > + > +#include > + > +#include "io/channel-socket.h" > +#include "io/channel-unix.h" > + > +#define SOCKET_MAX_FDS 16 > + > +static int > +qio_channel_socket_get_addr_string(struct sockaddr_storage *sa, > + socklen_t salen, > + char **hostname, > + char **servicename, > + NetworkAddressFamily *family, > + Error **errp) > +{ > + char host[NI_MAXHOST]; > + char serv[NI_MAXSERV]; > + int ret; > + > + ret =3D getnameinfo((struct sockaddr *)sa, salen, > + host, sizeof(host), > + serv, sizeof(serv), > + NI_NUMERICHOST | NI_NUMERICSERV); > + if (ret !=3D 0) { > + error_setg(errp, "Cannot format numeric socket address: %s\n", > + gai_strerror(ret)); > + return -1; > + } > + > + *hostname =3D g_strdup(host); > + *servicename =3D g_strdup(serv); > + *family =3D inet_netfamily(sa->ss_family); > + return 0; > +} > + > +int > +qio_channel_socket_get_local_addr_string(QIOChannelSocket *ioc, > + char **hostname, > + char **servicename, > + NetworkAddressFamily *family, > + Error **errp) > +{ > + return qio_channel_socket_get_addr_string(&ioc->localAddr, > + ioc->localAddrLen, > + hostname, > + servicename, > + family, > + errp); > +} > + > +int > +qio_channel_socket_get_remote_addr_string(QIOChannelSocket *ioc, > + char **hostname, > + char **servicename, > + NetworkAddressFamily *family= , > + Error **errp) > +{ > + return qio_channel_socket_get_addr_string(&ioc->remoteAddr, > + ioc->remoteAddrLen, > + hostname, > + servicename, > + family, > + errp); > +} > + > +QIOChannelSocket * > +qio_channel_socket_new_fd(int fd, > + Error **errp) > +{ > + QIOChannelSocket *ioc; > + > + ioc =3D QIO_CHANNEL_SOCKET(object_new(TYPE_QIO_CHANNEL_SOCKET)); > + > + ioc->fd =3D fd; > + ioc->remoteAddrLen =3D sizeof(ioc->remoteAddr); > + ioc->localAddrLen =3D sizeof(ioc->localAddr); > + > + if (getpeername(fd, (struct sockaddr *)&ioc->remoteAddr, > + &ioc->remoteAddrLen) < 0) { > + if (socket_error() =3D=3D ENOTCONN) { > + memset(&ioc->remoteAddr, 0, sizeof(ioc->remoteAddr)); > + ioc->remoteAddrLen =3D sizeof(ioc->remoteAddr); > + } else { > + error_setg_errno(errp, socket_error(), "%s", > + _("Unable to query remote socket address"= )); > + goto error; > + } > + } > + > + if (getsockname(fd, (struct sockaddr *)&ioc->localAddr, > + &ioc->localAddrLen) < 0) { > + error_setg_errno(errp, socket_error(), "%s", > + _("Unable to query local socket address")); > + goto error; > + } > + > + return ioc; > + > + error: > + ioc->fd =3D -1; /* Let the caller close FD on failure */ > + object_unref(OBJECT(ioc)); > + return NULL; > +} > + > +QIOChannelSocket * > +qio_channel_socket_accept(QIOChannelSocket *ioc, > + Error **errp) > +{ > + QIOChannelSocket *cioc; > + > + cioc =3D QIO_CHANNEL_SOCKET(object_new(TYPE_QIO_CHANNEL_SOCKET)); > + cioc->fd =3D -1; > + cioc->remoteAddrLen =3D sizeof(ioc->remoteAddr); > + cioc->localAddrLen =3D sizeof(ioc->localAddr); > + > + retry: > + cioc->fd =3D accept(ioc->fd, (struct sockaddr *)&cioc->remoteAddr, > + &cioc->remoteAddrLen); > + if (cioc->fd < 0) { > + if (socket_error() =3D=3D EINTR) { > + goto retry; > + } > + goto error; > + } > + > + if (getsockname(cioc->fd, (struct sockaddr *)&ioc->localAddr, > + &ioc->localAddrLen) < 0) { > + error_setg_errno(errp, socket_error(), "%s", > + _("Unable to query local socket address")); > + goto error; > + } > + > + return cioc; > + > + error: > + object_unref(OBJECT(cioc)); > + return NULL; > +} > + > +static void qio_channel_socket_init(Object *obj) > +{ > + QIOChannelSocket *ioc =3D QIO_CHANNEL_SOCKET(obj); > + ioc->fd =3D -1; > +} > + > +static void qio_channel_socket_finalize(Object *obj) > +{ > + QIOChannelSocket *ioc =3D QIO_CHANNEL_SOCKET(obj); > + if (ioc->fd !=3D -1) { > + close(ioc->fd); > + ioc->fd =3D -1; > + } > +} > + > +static bool qio_channel_socket_has_feature(QIOChannel *ioc, > + QIOChannelFeature feature) > +{ > + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); > + > + switch (feature) { > + case QIO_CHANNEL_FEATURE_FD_PASS: > +#ifndef WIN32 > + if (sioc->localAddr.ss_family =3D=3D AF_UNIX) { > + return true; > + } else { > +#endif /* WIN32 */ > + return false; > +#ifndef WIN32 > + } > +#endif /* WIN32 */ > + default: > + return false; > + } > +} > + > + > +#ifndef WIN32 > +static void qio_channel_socket_copy_fds(struct msghdr *msg, > + int **fds, size_t *nfds) > +{ > + struct cmsghdr *cmsg; > + > + *nfds =3D 0; > + *fds =3D NULL; > + > + for (cmsg =3D CMSG_FIRSTHDR(msg); cmsg; cmsg =3D CMSG_NXTHDR(msg, = cmsg)) { > + int fd_size, i; > + int gotfds; > + > + if (cmsg->cmsg_len < CMSG_LEN(sizeof(int)) || > + cmsg->cmsg_level !=3D SOL_SOCKET || > + cmsg->cmsg_type !=3D SCM_RIGHTS) { > + continue; > + } > + > + fd_size =3D cmsg->cmsg_len - CMSG_LEN(0); > + > + if (!fd_size) { > + continue; > + } > + > + gotfds =3D fd_size / sizeof(int); > + *fds =3D g_renew(int, *fds, *nfds + gotfds); > + memcpy(*fds + *nfds, CMSG_DATA(cmsg), fd_size); > + > + for (i =3D 0; i < gotfds; i++) { > + int fd =3D (*fds)[*nfds + i]; > + if (fd < 0) { > + continue; > + } > + > + /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it *= / > + qemu_set_block(fd); > + > +#ifndef MSG_CMSG_CLOEXEC > + qemu_set_cloexec(fd); > +#endif > + } > + *nfds +=3D gotfds; > + } > +} > + > + > +static ssize_t qio_channel_socket_readv(QIOChannel *ioc, > + const struct iovec *iov, > + size_t niov, > + int **fds, > + size_t *nfds, > + int flags, > + Error **errp) > +{ > + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); > + ssize_t ret; > + struct msghdr msg =3D { NULL, }; > + char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)]; > + int sflags =3D 0; > + > + if (flags & ~QIO_CHANNEL_READ_PEEK) { > + error_setg_errno(errp, EINVAL, > + _("Flags %x are not supported"), > + flags & ~QIO_CHANNEL_READ_PEEK); > + return -1; > + } > + > +#ifdef MSG_CMSG_CLOEXEC > + sflags |=3D MSG_CMSG_CLOEXEC; > +#endif > + if (flags & QIO_CHANNEL_READ_PEEK) { > + sflags |=3D MSG_PEEK; > + } > + > + msg.msg_iov =3D (struct iovec *)iov; > + msg.msg_iovlen =3D niov; > + if (fds && nfds) { > + msg.msg_control =3D control; > + msg.msg_controllen =3D sizeof(control); > + } > + > + retry: > + ret =3D recvmsg(sioc->fd, &msg, sflags); > + if (ret < 0) { > + if (socket_error() =3D=3D EAGAIN) { > + return -2; > + } > + if (socket_error() =3D=3D EINTR) { > + goto retry; > + } > + > + error_setg_errno(errp, socket_error(), "%s", > + _("Unable to read from socket")); > + return -1; > + } > + > + if (fds && nfds) { > + qio_channel_socket_copy_fds(&msg, fds, nfds); > + } > + > + return ret; > +} > + > +static ssize_t qio_channel_socket_writev(QIOChannel *ioc, > + const struct iovec *iov, > + size_t niov, > + int *fds, > + size_t nfds, > + int flags G_GNUC_UNUSED, > + Error **errp) > +{ > + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); > + ssize_t ret; > + struct msghdr msg =3D { NULL, }; > + > + if (flags) { > + error_setg_errno(errp, EINVAL, > + _("Flags %x are not supported"), > + flags); > + return -1; > + } > + > + msg.msg_iov =3D (struct iovec *)iov; > + msg.msg_iovlen =3D niov; > + > + if (nfds) { > + char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)]; > + size_t fdsize =3D sizeof(int) * nfds; > + struct cmsghdr *cmsg; > + > + if (nfds > SOCKET_MAX_FDS) { > + error_setg_errno(errp, -EINVAL, > + _("Only %d FDs can be sent, got %zu"), > + SOCKET_MAX_FDS, nfds); > + return -1; > + } > + > + msg.msg_control =3D control; > + msg.msg_controllen =3D CMSG_SPACE(sizeof(int) * nfds); > + > + cmsg =3D CMSG_FIRSTHDR(&msg); > + cmsg->cmsg_len =3D CMSG_LEN(fdsize); > + cmsg->cmsg_level =3D SOL_SOCKET; > + cmsg->cmsg_type =3D SCM_RIGHTS; > + memcpy(CMSG_DATA(cmsg), fds, fdsize); > + } > + > + retry: > + ret =3D sendmsg(sioc->fd, &msg, 0); > + if (ret <=3D 0) { > + if (socket_error() =3D=3D EAGAIN) { > + return -2; > + } > + if (socket_error() =3D=3D EINTR) { > + goto retry; > + } > + error_setg_errno(errp, socket_error(), "%s", > + _("Unable to write to socket")); > + return -1; > + } > + return ret; > +} > +#else /* WIN32 */ > +static ssize_t qio_channel_socket_readv(QIOChannel *ioc, > + const struct iovec *iov, > + size_t niov, > + int **fds, > + size_t *nfds, > + int flags, > + Error **errp) > +{ > + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); > + ssize_t done =3D 0; > + ssize_t i; > + > + if (flags) { > + error_setg_errno(errp, EINVAL, > + _("Flags %x are not supported"), > + flags); > + return -1; > + } > + if (fds || nfds) { > + error_setg_errno(errp, EINVAL, "%s", > + _("Channel does not support file descriptor p= assing")); > + return -1; > + } > + > + for (i =3D 0; i < niov; i++) { > + ssize_t ret; > + retry: > + ret =3D recv(sioc->fd, > + iov[i].iov_base, > + iov[i].iov_len, > + 0); > + if (ret < 0) { > + if (socket_error() =3D=3D EAGAIN) { > + if (done) { > + return done; > + } else { > + return QIO_CHANNEL_ERR_BLOCK; > + } > + } else if (socket_error() =3D=3D EINTR) { > + goto retry; > + } else { > + error_setg_errno(errp, socket_error(), "%s", > + _("Unable to write to socket")); > + return -1; > + } > + } > + done +=3D ret; > + if (ret < iov[i].iov_len) { > + return done; > + } > + } > + > + return done; > +} > + > +static ssize_t qio_channel_socket_writev(QIOChannel *ioc, > + const struct iovec *iov, > + size_t niov, > + int *fds, > + size_t nfds, > + int flags G_GNUC_UNUSED, > + Error **errp) > +{ > + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); > + ssize_t done =3D 0; > + ssize_t i; > + > + if (flags) { > + error_setg_errno(errp, EINVAL, > + _("Flags %x are not supported"), > + flags); > + return -1; > + } > + if (fds || nfds) { > + error_setg_errno(errp, EINVAL, "%s", > + _("Channel does not support file descriptor p= assing")); > + return -1; > + } > + > + for (i =3D 0; i < niov; i++) { > + ssize_t ret; > + retry: > + ret =3D send(sioc->fd, > + iov[i].iov_base, > + iov[i].iov_len, > + 0); > + if (ret < 0) { > + if (socket_error() =3D=3D EAGAIN) { > + if (done) { > + return done; > + } else { > + return QIO_CHANNEL_ERR_BLOCK; > + } > + } else if (socket_error() =3D=3D EINTR) { > + goto retry; > + } else { > + error_setg_errno(errp, socket_error(), "%s", > + _("Unable to write to socket")); > + return -1; > + } > + } > + done +=3D ret; > + if (ret < iov[i].iov_len) { > + return done; > + } > + } > + > + return done; > +} > +#endif /* WIN32 */ > + > +static void qio_channel_socket_set_blocking(QIOChannel *ioc, > + bool enabled) > +{ > + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); > + > + if (enabled) { > + qemu_set_block(sioc->fd); > + } else { > + qemu_set_nonblock(sioc->fd); > + } > +} > + > +void > +qio_channel_socket_set_nodelay(QIOChannelSocket *ioc, > + bool enabled) > +{ > + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); > + int v =3D enabled ? 1 : 0; > + > + qemu_setsockopt(sioc->fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v))= ; > +} > + > +static int qio_channel_socket_close(QIOChannel *ioc, > + Error **errp) > +{ > + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); > + > + if (closesocket(sioc->fd) < 0) { > + sioc->fd =3D -1; > + error_setg_errno(errp, socket_error(), "%s", > + _("Unable to close socket")); > + return -1; > + } > + sioc->fd =3D -1; > + return 0; > +} > + > +int > +qio_channel_socket_shutdown(QIOChannelSocket *ioc, > + QIOChannelSocketShutdown how, > + Error **errp) > +{ > + int sockhow; > + switch (how) { > + case QIO_CHANNEL_SOCKET_SHUTDOWN_READ: > + sockhow =3D SHUT_RD; > + break; > + case QIO_CHANNEL_SOCKET_SHUTDOWN_WRITE: > + sockhow =3D SHUT_WR; > + break; > + case QIO_CHANNEL_SOCKET_SHUTDOWN_BOTH: > + default: > + sockhow =3D SHUT_RDWR; > + break; > + } > + > + if (shutdown(ioc->fd, sockhow) < 0) { > + error_setg_errno(errp, socket_error(), "%s", > + _("Unable to shutdown socket")); > + return -1; > + } > + return 0; > +} > + > +static GSource *qio_channel_socket_create_watch(QIOChannel *ioc, > + GIOCondition condition= ) > +{ > + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); > + return qio_channel_unix_create_fd_watch(ioc, > + sioc->fd, > + condition); > +} > + > +static void qio_channel_socket_class_init(ObjectClass *klass, > + void *class_data G_GNUC_UNUS= ED) > +{ > + QIOChannelClass *ioc_klass =3D QIO_CHANNEL_CLASS(klass); > + > + ioc_klass->io_has_feature =3D qio_channel_socket_has_feature; > + ioc_klass->io_writev =3D qio_channel_socket_writev; > + ioc_klass->io_readv =3D qio_channel_socket_readv; > + ioc_klass->io_set_blocking =3D qio_channel_socket_set_blocking; > + ioc_klass->io_close =3D qio_channel_socket_close; > + ioc_klass->io_create_watch =3D qio_channel_socket_create_watch; > +} > + > +static const TypeInfo qio_channel_socket_info =3D { > + .parent =3D TYPE_QIO_CHANNEL, > + .name =3D TYPE_QIO_CHANNEL_SOCKET, > + .instance_size =3D sizeof(QIOChannelSocket), > + .instance_init =3D qio_channel_socket_init, > + .instance_finalize =3D qio_channel_socket_finalize, > + .class_init =3D qio_channel_socket_class_init, > +}; > + > +static void qio_channel_socket_register_types(void) > +{ > + type_register_static(&qio_channel_socket_info); > +} > + > +type_init(qio_channel_socket_register_types); >=20