mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 20:21:24 +00:00
tcp: Convert tcpserversrc to new helpers.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1105>
This commit is contained in:
parent
408b2fa634
commit
9ad0566c37
1 changed files with 14 additions and 36 deletions
|
@ -419,46 +419,26 @@ gst_tcp_server_src_start (GstBaseSrc * bsrc)
|
|||
{
|
||||
GstTCPServerSrc *src = GST_TCP_SERVER_SRC (bsrc);
|
||||
GError *err = NULL;
|
||||
GInetAddress *addr;
|
||||
GSocketAddress *saddr;
|
||||
GResolver *resolver;
|
||||
GList *addrs;
|
||||
GList *cur_addr;
|
||||
GSocketAddress *saddr = NULL;
|
||||
gint bound_port = 0;
|
||||
|
||||
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;
|
||||
addrs =
|
||||
tcp_get_addresses (GST_ELEMENT (src), src->host, src->cancellable, &err);
|
||||
if (!addrs)
|
||||
goto name_resolve;
|
||||
|
||||
resolver = g_resolver_get_default ();
|
||||
|
||||
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));
|
||||
|
||||
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 (src, "IP address for host %s is %s", src->host, ip);
|
||||
g_free (ip);
|
||||
}
|
||||
#endif
|
||||
|
||||
saddr = g_inet_socket_address_new (addr, src->server_port);
|
||||
g_object_unref (addr);
|
||||
|
||||
/* create the server listener socket */
|
||||
/* iterate over addresses until one works */
|
||||
cur_addr = addrs;
|
||||
src->server_socket =
|
||||
g_socket_new (g_socket_address_get_family (saddr), G_SOCKET_TYPE_STREAM,
|
||||
G_SOCKET_PROTOCOL_TCP, &err);
|
||||
tcp_create_socket (GST_ELEMENT (src), &cur_addr, src->server_port,
|
||||
&saddr, &err);
|
||||
g_list_free_full (addrs, g_object_unref);
|
||||
|
||||
if (!src->server_socket)
|
||||
goto no_socket;
|
||||
|
||||
|
@ -501,19 +481,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;
|
||||
}
|
||||
bind_failed:
|
||||
|
|
Loading…
Reference in a new issue