From patchwork Thu Sep 29 15:52:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Franciosi X-Patchwork-Id: 9356687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 26B9960757 for ; Thu, 29 Sep 2016 16:10:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16AD729B2F for ; Thu, 29 Sep 2016 16:10:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09A9C29B56; Thu, 29 Sep 2016 16:10:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4334329B2F for ; Thu, 29 Sep 2016 16:10:01 +0000 (UTC) Received: from localhost ([::1]:38984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpduI-00065Z-SV for patchwork-qemu-devel@patchwork.kernel.org; Thu, 29 Sep 2016 12:09:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpddf-0007rG-Ld for qemu-devel@nongnu.org; Thu, 29 Sep 2016 11:52:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpddb-0002s8-IH for qemu-devel@nongnu.org; Thu, 29 Sep 2016 11:52:46 -0400 Received: from 206-15-90-246.static.twtelecom.net ([206.15.90.246]:35421 helo=felipe-franciosi.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpddb-0002rD-Aw for qemu-devel@nongnu.org; Thu, 29 Sep 2016 11:52:43 -0400 Received: by felipe-franciosi.localdomain (Postfix, from userid 500) id 00B17103FA5; Thu, 29 Sep 2016 08:52:41 -0700 (PDT) From: Felipe Franciosi To: berrange@redhat.com, marcandre.lureau@redhat.com Date: Thu, 29 Sep 2016 08:52:37 -0700 Message-Id: <1475164358-2933-4-git-send-email-felipe@nutanix.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1475164358-2933-1-git-send-email-felipe@nutanix.com> References: <1475164358-2933-1-git-send-email-felipe@nutanix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 206.15.90.246 Subject: [Qemu-devel] [PATCH v3 3/4] io: Introduce a qio_channel_set_feature() helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, Felipe Franciosi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Testing QIOChannel feature support can be done with a helper called qio_channel_has_feature(). Setting feature support, however, was done manually with a logical OR. This patch introduces a new helper called qio_channel_set_feature() and makes use of it where applicable. Signed-off-by: Felipe Franciosi --- include/io/channel.h | 10 ++++++++++ io/channel-socket.c | 9 +++++---- io/channel-tls.c | 2 +- io/channel-websock.c | 2 +- io/channel.c | 7 +++++++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index 5368604..cf1c622 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -149,6 +149,16 @@ bool qio_channel_has_feature(QIOChannel *ioc, QIOChannelFeature feature); /** + * qio_channel_set_feature: + * @ioc: the channel object + * @feature: the feature to set support for + * + * Add channel support for the feature named in @feature. + */ +void qio_channel_set_feature(QIOChannel *ioc, + QIOChannelFeature feature); + +/** * qio_channel_readv_full: * @ioc: the channel object * @iov: the array of memory regions to read data into diff --git a/io/channel-socket.c b/io/channel-socket.c index 8fc6e5a..75cbca3 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -55,7 +55,7 @@ qio_channel_socket_new(void) sioc->fd = -1; ioc = QIO_CHANNEL(sioc); - ioc->features |= (1 << QIO_CHANNEL_FEATURE_SHUTDOWN); + qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN); #ifdef WIN32 ioc->event = CreateEvent(NULL, FALSE, FALSE, NULL); @@ -107,12 +107,12 @@ qio_channel_socket_set_fd(QIOChannelSocket *sioc, #ifndef WIN32 if (sioc->localAddr.ss_family == AF_UNIX) { QIOChannel *ioc = QIO_CHANNEL(sioc); - ioc->features |= (1 << QIO_CHANNEL_FEATURE_FD_PASS); + qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_FD_PASS); } #endif /* WIN32 */ if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &val, &len) == 0 && val) { QIOChannel *ioc = QIO_CHANNEL(sioc); - ioc->features |= (1 << QIO_CHANNEL_FEATURE_LISTEN); + qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_LISTEN); } return 0; @@ -380,7 +380,8 @@ qio_channel_socket_accept(QIOChannelSocket *ioc, #ifndef WIN32 if (cioc->localAddr.ss_family == AF_UNIX) { - QIO_CHANNEL(cioc)->features |= (1 << QIO_CHANNEL_FEATURE_FD_PASS); + QIOChannel *ioc_local = QIO_CHANNEL(cioc); + qio_channel_set_feature(ioc_local, QIO_CHANNEL_FEATURE_FD_PASS); } #endif /* WIN32 */ diff --git a/io/channel-tls.c b/io/channel-tls.c index f7bb0e3..d24dc8c 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -112,7 +112,7 @@ qio_channel_tls_new_client(QIOChannel *master, tioc->master = master; if (qio_channel_has_feature(master, QIO_CHANNEL_FEATURE_SHUTDOWN)) { - ioc->features |= (1 << QIO_CHANNEL_FEATURE_SHUTDOWN); + qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN); } object_ref(OBJECT(master)); diff --git a/io/channel-websock.c b/io/channel-websock.c index 75df03e..f45bced 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -498,7 +498,7 @@ qio_channel_websock_new_server(QIOChannel *master) wioc->master = master; if (qio_channel_has_feature(master, QIO_CHANNEL_FEATURE_SHUTDOWN)) { - ioc->features |= (1 << QIO_CHANNEL_FEATURE_SHUTDOWN); + qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN); } object_ref(OBJECT(master)); diff --git a/io/channel.c b/io/channel.c index e50325c..d1f1ae5 100644 --- a/io/channel.c +++ b/io/channel.c @@ -30,6 +30,13 @@ bool qio_channel_has_feature(QIOChannel *ioc, } +void qio_channel_set_feature(QIOChannel *ioc, + QIOChannelFeature feature) +{ + ioc->features |= (1 << feature); +} + + ssize_t qio_channel_readv_full(QIOChannel *ioc, const struct iovec *iov, size_t niov,