aboutsummaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-08-24 01:47:10 +0200
committerMax Kellermann <max@duempel.org>2011-08-24 01:47:10 +0200
commit5ecb6fecc478733622aa33aaf4e6997f618bd006 (patch)
tree8a022436fa867d45f6026ccf8a629d99604da1ac /src/input
parenteea726740bf222a92885b0f3c3c1255a5b04cd01 (diff)
parentb3df4dc2c92d27034eaf9cef52e97a6e39c77d2e (diff)
downloadmpd-5ecb6fecc478733622aa33aaf4e6997f618bd006.tar.gz
mpd-5ecb6fecc478733622aa33aaf4e6997f618bd006.tar.xz
mpd-5ecb6fecc478733622aa33aaf4e6997f618bd006.zip
Merge branch 'v0.16.x'
Diffstat (limited to '')
-rw-r--r--src/input/curl_input_plugin.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/input/curl_input_plugin.c b/src/input/curl_input_plugin.c
index 09010c220..20e8dea07 100644
--- a/src/input/curl_input_plugin.c
+++ b/src/input/curl_input_plugin.c
@@ -43,6 +43,13 @@
#define G_LOG_DOMAIN "input_curl"
/**
+ * Do not buffer more than this number of bytes. It should be a
+ * reasonable limit that doesn't make low-end machines suffer too
+ * much, but doesn't cause stuttering on high-latency lines.
+ */
+static const size_t CURL_MAX_BUFFERED = 512 * 1024;
+
+/**
* Buffers created by input_curl_writefunction().
*/
struct buffer {
@@ -144,6 +151,25 @@ input_curl_finish(void)
curl_global_cleanup();
}
+/**
+ * Determine the total sizes of all buffers, including portions that
+ * have already been consumed.
+ */
+G_GNUC_PURE
+static size_t
+curl_total_buffer_size(const struct input_curl *c)
+{
+ size_t total = 0;
+
+ for (GList *i = g_queue_peek_head_link(c->buffers);
+ i != NULL; i = g_list_next(i)) {
+ struct buffer *buffer = i->data;
+ total += buffer->size;
+ }
+
+ return total;
+}
+
static void
buffer_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
{
@@ -473,6 +499,10 @@ static int
input_curl_buffer(struct input_stream *is, GError **error_r)
{
struct input_curl *c = (struct input_curl *)is;
+
+ if (curl_total_buffer_size(c) >= CURL_MAX_BUFFERED)
+ return 0;
+
CURLMcode mcode;
int running_handles;
bool ret;