diff mbox series

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

Message ID 1609861330-129855-18-git-send-email-steven.sistare@oracle.com (mailing list archive)
State New, archived
Headers show
Series Live Update | expand

Commit Message

Steven Sistare Jan. 5, 2021, 3:42 p.m. UTC
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 mbox series

Patch

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;