diff mbox

[RFC,3/3] sockets: replace creating a new socket with the record one

Message ID 576AAE58.2000503@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Xu June 22, 2016, 3:27 p.m. UTC
There has been comments on this patch, but i forgot adding this patch to 
the list, just forward it again.

Both server mode and client mode are supported.

Signed-off-by: Wei Xu <wexu@redhat.com>
---
  util/qemu-sockets.c | 25 +++++++++++++++++--------
  1 file changed, 17 insertions(+), 8 deletions(-)

          connect_state->callback = callback;
diff mbox

Patch

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 0d6cd1f..e6429d7 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -713,10 +713,14 @@  static int unix_listen_saddr(UnixSocketAddress *saddr,
      struct sockaddr_un un;
      int sock, fd;

-    sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
-    if (sock < 0) {
-        error_setg_errno(errp, errno, "Failed to create Unix socket");
-        return -1;
+    if (saddr->sockfd) {
+        sock = saddr->sockfd;
+    } else {
+        sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
+        if (sock < 0) {
+            error_setg_errno(errp, errno, "Failed to create Unix socket");
+            return -1;
+        }
      }

      memset(&un, 0, sizeof(un));
@@ -786,11 +790,16 @@  static int unix_connect_saddr(UnixSocketAddress 
*saddr, Error **errp,
          return -1;
      }

-    sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
-    if (sock < 0) {
-        error_setg_errno(errp, errno, "Failed to create socket");
-        return -1;
+    if (saddr->sockfd) {
+        sock = saddr->sockfd;
+    } else {
+        sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
+        if (sock < 0) {
+            error_setg_errno(errp, errno, "Failed to create socket");
+            return -1;
+        }
      }
+
      if (callback != NULL) {
          connect_state = g_malloc0(sizeof(*connect_state));