mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
tcp: Convert tcpclientsink to new helpers.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1105>
This commit is contained in:
parent
13743353cb
commit
dd12c9b230
1 changed files with 32 additions and 42 deletions
|
@ -283,54 +283,47 @@ gst_tcp_client_sink_start (GstBaseSink * bsink)
|
|||
{
|
||||
GstTCPClientSink *this = GST_TCP_CLIENT_SINK (bsink);
|
||||
GError *err = NULL;
|
||||
GInetAddress *addr;
|
||||
GSocketAddress *saddr;
|
||||
GResolver *resolver;
|
||||
GList *addrs;
|
||||
GList *cur_addr;
|
||||
GSocketAddress *saddr = NULL;
|
||||
|
||||
if (GST_OBJECT_FLAG_IS_SET (this, GST_TCP_CLIENT_SINK_OPEN))
|
||||
return TRUE;
|
||||
|
||||
/* look up name if we need to */
|
||||
addr = g_inet_address_new_from_string (this->host);
|
||||
if (!addr) {
|
||||
GList *results;
|
||||
addrs =
|
||||
tcp_get_addresses (GST_ELEMENT (this), this->host, this->cancellable,
|
||||
&err);
|
||||
if (!addrs)
|
||||
goto name_resolve;
|
||||
|
||||
resolver = g_resolver_get_default ();
|
||||
|
||||
results =
|
||||
g_resolver_lookup_by_name (resolver, this->host, this->cancellable,
|
||||
&err);
|
||||
if (!results)
|
||||
goto name_resolve;
|
||||
addr = G_INET_ADDRESS (g_object_ref (results->data));
|
||||
|
||||
g_resolver_free_addresses (results);
|
||||
g_object_unref (resolver);
|
||||
}
|
||||
#ifndef GST_DISABLE_GST_DEBUG
|
||||
{
|
||||
gchar *ip = g_inet_address_to_string (addr);
|
||||
|
||||
GST_DEBUG_OBJECT (this, "IP address for host %s is %s", this->host, ip);
|
||||
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);
|
||||
|
||||
cur_addr = addrs;
|
||||
while (cur_addr) {
|
||||
/* iterate over addresses until one works */
|
||||
this->socket =
|
||||
tcp_create_socket (GST_ELEMENT (this), &cur_addr, this->port, &saddr,
|
||||
&err);
|
||||
if (!this->socket)
|
||||
break;
|
||||
|
||||
GST_DEBUG_OBJECT (this, "opened sending client socket");
|
||||
|
||||
/* connect to server */
|
||||
if (g_socket_connect (this->socket, saddr, this->cancellable, &err))
|
||||
break;
|
||||
|
||||
/* failed to connect, release and try next address... */
|
||||
g_clear_object (&this->socket);
|
||||
g_clear_object (&saddr);
|
||||
}
|
||||
g_list_free_full (addrs, g_object_unref);
|
||||
if (!this->socket)
|
||||
goto no_socket;
|
||||
|
||||
GST_DEBUG_OBJECT (this, "opened sending client socket");
|
||||
|
||||
/* connect to server */
|
||||
if (!g_socket_connect (this->socket, saddr, this->cancellable, &err))
|
||||
/* we should only have a valid saddr if connect was successful */
|
||||
if (!saddr)
|
||||
goto connect_failed;
|
||||
|
||||
g_object_unref (saddr);
|
||||
|
@ -345,19 +338,17 @@ 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:
|
||||
{
|
||||
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||
GST_DEBUG_OBJECT (this, "Cancelled name resolval");
|
||||
GST_DEBUG_OBJECT (this, "Cancelled name resolution");
|
||||
} else {
|
||||
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
|
||||
("Failed to resolve host '%s': %s", this->host, err->message));
|
||||
}
|
||||
g_clear_error (&err);
|
||||
g_object_unref (resolver);
|
||||
return FALSE;
|
||||
}
|
||||
connect_failed:
|
||||
|
@ -370,7 +361,6 @@ connect_failed:
|
|||
err->message));
|
||||
}
|
||||
g_clear_error (&err);
|
||||
g_object_unref (saddr);
|
||||
/* pretend we opened ok for proper cleanup to happen */
|
||||
GST_OBJECT_FLAG_SET (this, GST_TCP_CLIENT_SINK_OPEN);
|
||||
gst_tcp_client_sink_stop (GST_BASE_SINK (this));
|
||||
|
|
Loading…
Reference in a new issue