qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH V2 17/22] chardev: socket accept subroutine


From: Steve Sistare
Subject: [PATCH V2 17/22] chardev: socket accept subroutine
Date: Tue, 5 Jan 2021 07:42:05 -0800

Factor out the post-accept actions into a subroutine that can be used in a
subsequent patch.  No functional change.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 io/channel-socket.c | 43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/io/channel-socket.c b/io/channel-socket.c
index e1b4667..de49880 100644
--- a/io/channel-socket.c
+++ b/io/channel-socket.c
@@ -349,16 +349,34 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc,
                            context);
 }
 
+static int qio_channel_socket_post_accept(QIOChannelSocket *cioc,
+                                           Error **errp)
+{
+    cioc->localAddrLen = sizeof(cioc->localAddr);
+    if (getsockname(cioc->fd, (struct sockaddr *)&cioc->localAddr,
+                    &cioc->localAddrLen) < 0) {
+        error_setg_errno(errp, errno,
+                         "Unable to query local socket address");
+        return 1;
+    }
+
+#ifndef WIN32
+    if (cioc->localAddr.ss_family == AF_UNIX) {
+        QIOChannel *ioc_local = QIO_CHANNEL(cioc);
+        qio_channel_set_feature(ioc_local, QIO_CHANNEL_FEATURE_FD_PASS);
+    }
+#endif /* WIN32 */
+
+    return 0;
+}
 
 QIOChannelSocket *
 qio_channel_socket_accept(QIOChannelSocket *ioc,
                           Error **errp)
 {
-    QIOChannelSocket *cioc;
+    QIOChannelSocket *cioc = qio_channel_socket_new();
 
-    cioc = qio_channel_socket_new();
     cioc->remoteAddrLen = sizeof(ioc->remoteAddr);
-    cioc->localAddrLen = sizeof(ioc->localAddr);
 
  retry:
     trace_qio_channel_socket_accept(ioc);
@@ -372,24 +390,11 @@ qio_channel_socket_accept(QIOChannelSocket *ioc,
         trace_qio_channel_socket_accept_fail(ioc);
         goto error;
     }
-
-    if (getsockname(cioc->fd, (struct sockaddr *)&cioc->localAddr,
-                    &cioc->localAddrLen) < 0) {
-        error_setg_errno(errp, errno,
-                         "Unable to query local socket address");
-        goto error;
+    if (!qio_channel_socket_post_accept(cioc, errp)) {
+        trace_qio_channel_socket_accept_complete(ioc, cioc, cioc->fd);
+        return cioc;
     }
 
-#ifndef WIN32
-    if (cioc->localAddr.ss_family == AF_UNIX) {
-        QIOChannel *ioc_local = QIO_CHANNEL(cioc);
-        qio_channel_set_feature(ioc_local, QIO_CHANNEL_FEATURE_FD_PASS);
-    }
-#endif /* WIN32 */
-
-    trace_qio_channel_socket_accept_complete(ioc, cioc, cioc->fd);
-    return cioc;
-
  error:
     object_unref(OBJECT(cioc));
     return NULL;
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]