Commit 13743353 authored by Doug Nazar's avatar Doug Nazar Committed by GStreamer Marge Bot

tcp: Convert tcpclientsrc to new helpers.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1105>
parent 0fefbc93
......@@ -408,58 +408,50 @@ gst_tcp_client_src_start (GstBaseSrc * bsrc)
{
GstTCPClientSrc *src = GST_TCP_CLIENT_SRC (bsrc);
GError *err = NULL;
GInetAddress *addr;
GList *addrs;
GList *cur_addr;
GSocketAddress *saddr;
GResolver *resolver;
src->bytes_received = 0;
gst_clear_structure (&src->stats);
/* look up name if we need to */
addr = g_inet_address_new_from_string (src->host);
if (!addr) {
GList *results;
resolver = g_resolver_get_default ();
addrs =
tcp_get_addresses (GST_ELEMENT (src), src->host, src->cancellable, &err);
if (!addrs)
goto name_resolve;
cur_addr = addrs;
while (cur_addr) {
/* iterate over addresses until one works */
src->socket =
tcp_create_socket (GST_ELEMENT (src), &cur_addr, src->port, &saddr,
&err);
if (!src->socket)
break;
results =
g_resolver_lookup_by_name (resolver, src->host, src->cancellable, &err);
if (!results)
goto name_resolve;
addr = G_INET_ADDRESS (g_object_ref (results->data));
/* create receiving client socket */
GST_DEBUG_OBJECT (src, "opening receiving client socket to %s:%d",
src->host, src->port);
g_resolver_free_addresses (results);
g_object_unref (resolver);
}
#ifndef GST_DISABLE_GST_DEBUG
{
gchar *ip = g_inet_address_to_string (addr);
g_socket_set_timeout (src->socket, src->timeout);
GST_DEBUG_OBJECT (src, "IP address for host %s is %s", src->host, ip);
g_free (ip);
}
#endif
GST_DEBUG_OBJECT (src, "opened receiving client socket");
GST_OBJECT_FLAG_SET (src, GST_TCP_CLIENT_SRC_OPEN);
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);
/* connect to server */
if (g_socket_connect (src->socket, saddr, src->cancellable, &err))
break;
src->socket =
g_socket_new (g_socket_address_get_family (saddr), G_SOCKET_TYPE_STREAM,
G_SOCKET_PROTOCOL_TCP, &err);
/* failed to connect, release and try next address... */
g_clear_object (&src->socket);
g_clear_object (&saddr);
}
g_list_free_full (addrs, g_object_unref);
if (!src->socket)
goto no_socket;
g_socket_set_timeout (src->socket, src->timeout);
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))
/* we should only have a valid saddr if connect was successful */
if (!saddr)
goto connect_failed;
g_object_unref (saddr);
......@@ -471,19 +463,17 @@ 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:
{
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
GST_DEBUG_OBJECT (src, "Cancelled name resolval");
GST_DEBUG_OBJECT (src, "Cancelled name resolution");
} else {
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
("Failed to resolve host '%s': %s", src->host, err->message));
}
g_clear_error (&err);
g_object_unref (resolver);
return FALSE;
}
connect_failed:
......@@ -496,7 +486,6 @@ connect_failed:
err->message));
}
g_clear_error (&err);
g_object_unref (saddr);
gst_tcp_client_src_stop (GST_BASE_SRC (src));
return FALSE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment