From: Felipe Franciosi <felipe@nutanix.com>
To: berrange@redhat.com, marcandre.lureau@redhat.com
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org,
Felipe Franciosi <felipe@nutanix.com>
Subject: [Qemu-devel] [PATCH v3 3/4] io: Introduce a qio_channel_set_feature() helper
Date: Thu, 29 Sep 2016 08:52:37 -0700 [thread overview]
Message-ID: <1475164358-2933-4-git-send-email-felipe@nutanix.com> (raw)
In-Reply-To: <1475164358-2933-1-git-send-email-felipe@nutanix.com>
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 <felipe@nutanix.com>
---
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,
--
1.7.1
next prev parent reply other threads:[~2016-09-29 15:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-29 15:52 [Qemu-devel] [PATCH v3 0/4] io: Various fixes around QIOChannel Features Felipe Franciosi
2016-09-29 15:52 ` [Qemu-devel] [PATCH v3 1/4] io: Fix double shift usages on QIOChannel features Felipe Franciosi
2016-09-29 15:52 ` [Qemu-devel] [PATCH v3 2/4] io: Use qio_channel_has_feature() where applicable Felipe Franciosi
2016-09-29 15:52 ` Felipe Franciosi [this message]
2016-09-29 15:52 ` [Qemu-devel] [PATCH v3 4/4] io: Add a QIOChannelSocket cleanup test Felipe Franciosi
2016-09-29 16:32 ` [Qemu-devel] [PATCH v3 0/4] io: Various fixes around QIOChannel Features Daniel P. Berrange
2016-10-01 15:33 ` Felipe Franciosi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1475164358-2933-4-git-send-email-felipe@nutanix.com \
--to=felipe@nutanix.com \
--cc=berrange@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).