[0.11] gst-plugins-base: tcp: Add support for IPv6

Sebastian Dröge slomo at kemper.freedesktop.org
Tue Jan 17 03:08:48 PST 2012


Module: gst-plugins-base
Branch: 0.11
Commit: 6d6593b757b044b63e1f0bf6083df529b682c8f7
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-base/commit/?id=6d6593b757b044b63e1f0bf6083df529b682c8f7

Author: Sebastian Dröge <sebastian.droege at collabora.co.uk>
Date:   Tue Jan 17 12:08:17 2012 +0100

tcp: Add support for IPv6

---

 gst/tcp/gsttcpclientsink.c |   29 ++++++++++++++---------------
 gst/tcp/gsttcpclientsrc.c  |   34 +++++++++++++++++-----------------
 gst/tcp/gsttcpserversink.c |   30 +++++++++++++++---------------
 gst/tcp/gsttcpserversrc.c  |   28 +++++++++++++++-------------
 4 files changed, 61 insertions(+), 60 deletions(-)

diff --git a/gst/tcp/gsttcpclientsink.c b/gst/tcp/gsttcpclientsink.c
index 7a9c513..a28c03d 100644
--- a/gst/tcp/gsttcpclientsink.c
+++ b/gst/tcp/gsttcpclientsink.c
@@ -287,17 +287,6 @@ gst_tcp_client_sink_start (GstBaseSink * bsink)
   if (GST_OBJECT_FLAG_IS_SET (this, GST_TCP_CLIENT_SINK_OPEN))
     return TRUE;
 
-  /* create sending client socket */
-  GST_DEBUG_OBJECT (this, "opening sending client socket to %s:%d", this->host,
-      this->port);
-  this->socket =
-      g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM,
-      G_SOCKET_PROTOCOL_TCP, &err);
-  if (!this->socket)
-    goto no_socket;
-
-  GST_DEBUG_OBJECT (this, "opened sending client socket");
-
   /* look up name if we need to */
   addr = g_inet_address_new_from_string (this->host);
   if (!addr) {
@@ -323,14 +312,25 @@ gst_tcp_client_sink_start (GstBaseSink * bsink)
     g_free (ip);
   }
 #endif
+  saddr = g_inet_socket_address_new (addr, this->port);
+  g_object_unref (addr);
+
+  /* create sending client socket */
+  GST_DEBUG_OBJECT (this, "opening sending client socket to %s:%d", this->host,
+      this->port);
+  this->socket =
+      g_socket_new (g_socket_address_get_family (saddr), G_SOCKET_TYPE_STREAM,
+      G_SOCKET_PROTOCOL_TCP, &err);
+  if (!this->socket)
+    goto no_socket;
+
+  GST_DEBUG_OBJECT (this, "opened sending client socket");
 
   /* connect to server */
-  saddr = g_inet_socket_address_new (addr, this->port);
   if (!g_socket_connect (this->socket, saddr, this->cancellable, &err))
     goto connect_failed;
 
   g_object_unref (saddr);
-  g_object_unref (addr);
 
   GST_OBJECT_FLAG_SET (this, GST_TCP_CLIENT_SINK_OPEN);
 
@@ -342,6 +342,7 @@ no_socket:
     GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
         ("Failed to create socket: %s", err->message));
     g_clear_error (&err);
+    g_object_unref (saddr);
     return FALSE;
   }
 name_resolve:
@@ -354,7 +355,6 @@ name_resolve:
     }
     g_clear_error (&err);
     g_object_unref (resolver);
-    gst_tcp_client_sink_stop (GST_BASE_SINK (this));
     return FALSE;
   }
 connect_failed:
@@ -368,7 +368,6 @@ connect_failed:
     }
     g_clear_error (&err);
     g_object_unref (saddr);
-    g_object_unref (addr);
     gst_tcp_client_sink_stop (GST_BASE_SINK (this));
     return FALSE;
   }
diff --git a/gst/tcp/gsttcpclientsrc.c b/gst/tcp/gsttcpclientsrc.c
index 2ea6dc0..de21783 100644
--- a/gst/tcp/gsttcpclientsrc.c
+++ b/gst/tcp/gsttcpclientsrc.c
@@ -338,19 +338,6 @@ gst_tcp_client_src_start (GstBaseSrc * bsrc)
   GSocketAddress *saddr;
   GResolver *resolver;
 
-  /* create receiving client socket */
-  GST_DEBUG_OBJECT (src, "opening receiving client socket to %s:%d",
-      src->host, src->port);
-
-  src->socket =
-      g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM,
-      G_SOCKET_PROTOCOL_TCP, &err);
-  if (!src->socket)
-    goto no_socket;
-
-  GST_DEBUG_OBJECT (src, "opened receiving client socket");
-  GST_OBJECT_FLAG_SET (src, GST_TCP_CLIENT_SRC_OPEN);
-
   /* look up name if we need to */
   addr = g_inet_address_new_from_string (src->host);
   if (!addr) {
@@ -376,13 +363,27 @@ gst_tcp_client_src_start (GstBaseSrc * bsrc)
   }
 #endif
 
-  /* connect to server */
   saddr = g_inet_socket_address_new (addr, src->port);
+  g_object_unref (addr);
+
+  /* create receiving client socket */
+  GST_DEBUG_OBJECT (src, "opening receiving client socket to %s:%d",
+      src->host, src->port);
+
+  src->socket =
+      g_socket_new (g_socket_address_get_family (saddr), G_SOCKET_TYPE_STREAM,
+      G_SOCKET_PROTOCOL_TCP, &err);
+  if (!src->socket)
+    goto no_socket;
+
+  GST_DEBUG_OBJECT (src, "opened receiving client socket");
+  GST_OBJECT_FLAG_SET (src, GST_TCP_CLIENT_SRC_OPEN);
+
+  /* connect to server */
   if (!g_socket_connect (src->socket, saddr, src->cancellable, &err))
     goto connect_failed;
 
   g_object_unref (saddr);
-  g_object_unref (addr);
 
   return TRUE;
 
@@ -391,6 +392,7 @@ no_socket:
     GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
         ("Failed to create socket: %s", err->message));
     g_clear_error (&err);
+    g_object_unref (saddr);
     return FALSE;
   }
 name_resolve:
@@ -403,7 +405,6 @@ name_resolve:
     }
     g_clear_error (&err);
     g_object_unref (resolver);
-    gst_tcp_client_src_stop (GST_BASE_SRC (src));
     return FALSE;
   }
 connect_failed:
@@ -417,7 +418,6 @@ connect_failed:
     }
     g_clear_error (&err);
     g_object_unref (saddr);
-    g_object_unref (addr);
     gst_tcp_client_src_stop (GST_BASE_SRC (src));
     return FALSE;
   }
diff --git a/gst/tcp/gsttcpserversink.c b/gst/tcp/gsttcpserversink.c
index f7b0023..f9b0b9c 100644
--- a/gst/tcp/gsttcpserversink.c
+++ b/gst/tcp/gsttcpserversink.c
@@ -273,16 +273,6 @@ gst_tcp_server_sink_init_send (GstMultiSocketSink * parent)
   GSocketAddress *saddr;
   GResolver *resolver;
 
-  /* create the server listener socket */
-  this->server_socket =
-      g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM,
-      G_SOCKET_PROTOCOL_TCP, &err);
-  if (!this->server_socket)
-    goto no_socket;
-
-  GST_DEBUG_OBJECT (this, "opened sending server socket with socket %p",
-      this->server_socket);
-
   /* look up name if we need to */
   addr = g_inet_address_new_from_string (this->host);
   if (!addr) {
@@ -308,15 +298,28 @@ gst_tcp_server_sink_init_send (GstMultiSocketSink * parent)
     g_free (ip);
   }
 #endif
+  saddr = g_inet_socket_address_new (addr, this->server_port);
+  g_object_unref (addr);
+
+  /* create the server listener socket */
+  this->server_socket =
+      g_socket_new (g_socket_address_get_family (saddr), G_SOCKET_TYPE_STREAM,
+      G_SOCKET_PROTOCOL_TCP, &err);
+  if (!this->server_socket)
+    goto no_socket;
+
+  GST_DEBUG_OBJECT (this, "opened sending server socket with socket %p",
+      this->server_socket);
 
   g_socket_set_blocking (this->server_socket, FALSE);
 
   /* bind it */
-  saddr = g_inet_socket_address_new (addr, this->server_port);
   GST_DEBUG_OBJECT (this, "binding server socket to address");
   if (!g_socket_bind (this->server_socket, saddr, TRUE, &err))
     goto bind_failed;
 
+  g_object_unref (saddr);
+
   GST_DEBUG_OBJECT (this, "listening on server socket");
   g_socket_set_listen_backlog (this->server_socket, TCP_BACKLOG);
 
@@ -344,6 +347,7 @@ no_socket:
     GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
         ("Failed to create socket: %s", err->message));
     g_clear_error (&err);
+    g_object_unref (saddr);
     return FALSE;
   }
 name_resolve:
@@ -356,7 +360,6 @@ name_resolve:
     }
     g_clear_error (&err);
     g_object_unref (resolver);
-    gst_tcp_server_sink_close (&this->element);
     return FALSE;
   }
 bind_failed:
@@ -370,7 +373,6 @@ bind_failed:
     }
     g_clear_error (&err);
     g_object_unref (saddr);
-    g_object_unref (addr);
     gst_tcp_server_sink_close (&this->element);
     return FALSE;
   }
@@ -384,8 +386,6 @@ listen_failed:
               this->server_port, err->message));
     }
     g_clear_error (&err);
-    g_object_unref (saddr);
-    g_object_unref (addr);
     gst_tcp_server_sink_close (&this->element);
     return FALSE;
   }
diff --git a/gst/tcp/gsttcpserversrc.c b/gst/tcp/gsttcpserversrc.c
index a217e07..1ca5071 100644
--- a/gst/tcp/gsttcpserversrc.c
+++ b/gst/tcp/gsttcpserversrc.c
@@ -344,14 +344,6 @@ gst_tcp_server_src_start (GstBaseSrc * bsrc)
   GSocketAddress *saddr;
   GResolver *resolver;
 
-  /* create the server listener socket */
-  src->server_socket = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM,
-      G_SOCKET_PROTOCOL_TCP, &err);
-  if (!src->server_socket)
-    goto no_socket;
-
-  GST_DEBUG_OBJECT (src, "opened receiving server socket");
-
   /* look up name if we need to */
   addr = g_inet_address_new_from_string (src->host);
   if (!addr) {
@@ -377,12 +369,25 @@ gst_tcp_server_src_start (GstBaseSrc * bsrc)
   }
 #endif
 
-  /* bind it */
   saddr = g_inet_socket_address_new (addr, src->server_port);
+  g_object_unref (addr);
+
+  /* create the server listener socket */
+  src->server_socket =
+      g_socket_new (g_socket_address_get_family (saddr), G_SOCKET_TYPE_STREAM,
+      G_SOCKET_PROTOCOL_TCP, &err);
+  if (!src->server_socket)
+    goto no_socket;
+
+  GST_DEBUG_OBJECT (src, "opened receiving server socket");
+
+  /* bind it */
   GST_DEBUG_OBJECT (src, "binding server socket to address");
   if (!g_socket_bind (src->server_socket, saddr, TRUE, &err))
     goto bind_failed;
 
+  g_object_unref (saddr);
+
   GST_DEBUG_OBJECT (src, "listening on server socket");
 
   g_socket_set_listen_backlog (src->server_socket, TCP_BACKLOG);
@@ -400,6 +405,7 @@ no_socket:
     GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
         ("Failed to create socket: %s", err->message));
     g_clear_error (&err);
+    g_object_unref (saddr);
     return FALSE;
   }
 name_resolve:
@@ -412,7 +418,6 @@ name_resolve:
     }
     g_clear_error (&err);
     g_object_unref (resolver);
-    gst_tcp_server_src_stop (GST_BASE_SRC (src));
     return FALSE;
   }
 bind_failed:
@@ -426,7 +431,6 @@ bind_failed:
     }
     g_clear_error (&err);
     g_object_unref (saddr);
-    g_object_unref (addr);
     gst_tcp_server_src_stop (GST_BASE_SRC (src));
     return FALSE;
   }
@@ -440,8 +444,6 @@ listen_failed:
               err->message));
     }
     g_clear_error (&err);
-    g_object_unref (saddr);
-    g_object_unref (addr);
     gst_tcp_server_src_stop (GST_BASE_SRC (src));
     return FALSE;
   }



More information about the gstreamer-commits mailing list