From c1bad1be5d7af242e65ba17b1ca33dae182f6139 Mon Sep 17 00:00:00 2001 From: Patricia Muscalu Date: Mon, 25 May 2015 12:33:50 +0200 Subject: [PATCH] curlsink: handle socket callback for active FTP connections as well Since version 7.28.0, libcurl allows application to set socket options for active FTP connections. Bump libcurl requirement to version tested. https://bugzilla.gnome.org/show_bug.cgi?id=749815 --- configure.ac | 2 +- ext/curl/gstcurlbasesink.c | 33 ++++++++++++++++++++++++++------- ext/curl/gstcurlbasesink.h | 1 + 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index d295253cf3..55eca0ee0d 100644 --- a/configure.ac +++ b/configure.ac @@ -1812,7 +1812,7 @@ AG_GST_CHECK_FEATURE(CHROMAPRINT, [chromaprint], chromaprint, [ dnl *** Curl *** translit(dnm, m, l) AM_CONDITIONAL(USE_CURL, true) AG_GST_CHECK_FEATURE(CURL, [Curl plugin], curl, [ - PKG_CHECK_MODULES(CURL, libcurl >= 7.21.0, [ + PKG_CHECK_MODULES(CURL, libcurl >= 7.37.1, [ HAVE_CURL="yes" AC_CHECK_HEADERS([unistd.h sys/socket.h sys/types.h netinet/in.h netinet/ip.h netinet/tcp.h fcntl.h], [ ], [ AC_CHECK_HEADERS([unistd.h sys/types.h winsock2.h ws2tcpip.h fcntl.h], [ ], [HAVE_CURL="no"]) diff --git a/ext/curl/gstcurlbasesink.c b/ext/curl/gstcurlbasesink.c index 1654c45a57..b47f2467d1 100644 --- a/ext/curl/gstcurlbasesink.c +++ b/ext/curl/gstcurlbasesink.c @@ -449,6 +449,8 @@ gst_curl_base_sink_start (GstBaseSink * bsink) return FALSE; } + gst_poll_fd_init (&sink->fd); + return TRUE; } @@ -972,6 +974,18 @@ handle_transfer (GstCurlBaseSink * sink) gst_curl_base_sink_got_response_notify (sink); + GST_OBJECT_LOCK (sink); + if (sink->socket_type == CURLSOCKTYPE_ACCEPT) { + if (!gst_poll_remove_fd (sink->fdset, &sink->fd)) { + sink->error = g_strdup_printf ("failed to remove fd"); + retval = GST_FLOW_ERROR; + GST_OBJECT_UNLOCK (sink); + goto fail; + } + sink->fd.fd = -1; + } + GST_OBJECT_UNLOCK (sink); + return; fail: @@ -1041,7 +1055,7 @@ gst_curl_base_sink_debug_cb (CURL * handle, curl_infotype type, char *data, * the connect() call. */ static int gst_curl_base_sink_transfer_socket_cb (void *clientp, curl_socket_t curlfd, - curlsocktype G_GNUC_UNUSED purpose) + curlsocktype socket_type) { GstCurlBaseSink *sink; gboolean ret = TRUE; @@ -1058,14 +1072,19 @@ gst_curl_base_sink_transfer_socket_cb (void *clientp, curl_socket_t curlfd, return 1; } - gst_poll_fd_init (&sink->fd); - sink->fd.fd = curlfd; + GST_OBJECT_LOCK (sink); + sink->socket_type = socket_type; - ret &= gst_poll_add_fd (sink->fdset, &sink->fd); - ret &= gst_poll_fd_ctl_write (sink->fdset, &sink->fd, TRUE); - ret &= gst_poll_fd_ctl_read (sink->fdset, &sink->fd, TRUE); + if (sink->fd.fd != curlfd) { + if (sink->fd.fd > 0 && sink->socket_type != CURLSOCKTYPE_ACCEPT) { + ret &= gst_poll_remove_fd (sink->fdset, &sink->fd); + } + sink->fd.fd = curlfd; + ret &= gst_poll_add_fd (sink->fdset, &sink->fd); + ret &= gst_poll_fd_ctl_write (sink->fdset, &sink->fd, TRUE); + ret &= gst_poll_fd_ctl_read (sink->fdset, &sink->fd, TRUE); + } GST_DEBUG_OBJECT (sink, "fd: %d", sink->fd.fd); - GST_OBJECT_LOCK (sink); gst_curl_base_sink_setup_dscp_unlocked (sink); GST_OBJECT_UNLOCK (sink); diff --git a/ext/curl/gstcurlbasesink.h b/ext/curl/gstcurlbasesink.h index 51059817bf..afa6d5bad4 100644 --- a/ext/curl/gstcurlbasesink.h +++ b/ext/curl/gstcurlbasesink.h @@ -67,6 +67,7 @@ struct _GstCurlBaseSink CURL *curl; GstPollFD fd; GstPoll *fdset; + curlsocktype socket_type; GThread *transfer_thread; gchar *error; GstFlowReturn flow_ret; -- 2.34.1