]> git.proxmox.com Git - mirror_qemu.git/commitdiff
io: Introduce a qio_channel_set_feature() helper
authorFelipe Franciosi <felipe@nutanix.com>
Thu, 29 Sep 2016 15:52:37 +0000 (08:52 -0700)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 26 Oct 2016 16:19:53 +0000 (18:19 +0200)
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>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
include/io/channel.h
io/channel-socket.c
io/channel-tls.c
io/channel-websock.c
io/channel.c

index 5368604c8e80671bf03dd5c235f03b03b2729002..cf1c6223fa11f4ef086d4e0695b4f0a8ba86adf6 100644 (file)
@@ -148,6 +148,16 @@ struct QIOChannelClass {
 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
index 8fc6e5aaaa4b702c792a7f230b75a2a374069aa2..75cbca3c551218c1c1d95c6d68cb3e3caeb5eb19 100644 (file)
@@ -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 */
 
index f7bb0e3698592eba70e0ffece563720746a7d9a9..d24dc8c613ab494d701246367d685b93501bd1b4 100644 (file)
@@ -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));
 
index 75df03ef2964029bbe7f1cff3cae4887648b1d2e..f45bced82a17d2a730f607207175e5db1b4f4015 100644 (file)
@@ -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));
 
index e50325c3f71613bd835d711d207fbfac67c2ed92..d1f1ae515749db0a6e64a650c10a3ca09152d360 100644 (file)
@@ -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,