aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-10-11 23:09:38 +0200
committerMax Kellermann <max@duempel.org>2009-10-11 23:09:38 +0200
commit016558093ba9fa7bd030367e50feca303fb012ca (patch)
tree377f0435bb1ceb6aeaad2895bdd0959f5003fd87 /src
parentd6d4de11232946ba57a8b40863a0fcb2ef923349 (diff)
downloadmpd-016558093ba9fa7bd030367e50feca303fb012ca.tar.gz
mpd-016558093ba9fa7bd030367e50feca303fb012ca.tar.xz
mpd-016558093ba9fa7bd030367e50feca303fb012ca.zip
input/curl: moved code to fill_buffer()
Diffstat (limited to '')
-rw-r--r--src/input/curl_input_plugin.c67
1 files changed, 40 insertions, 27 deletions
diff --git a/src/input/curl_input_plugin.c b/src/input/curl_input_plugin.c
index a140556c5..4ed8e5b5b 100644
--- a/src/input/curl_input_plugin.c
+++ b/src/input/curl_input_plugin.c
@@ -282,6 +282,42 @@ input_curl_select(struct input_curl *c)
return ret;
}
+static bool
+fill_buffer(struct input_stream *is)
+{
+ struct input_curl *c = is->data;
+ CURLMcode mcode = CURLM_CALL_MULTI_PERFORM;
+
+ while (!c->eof && g_queue_is_empty(c->buffers)) {
+ int running_handles;
+ bool bret;
+
+ if (mcode != CURLM_CALL_MULTI_PERFORM) {
+ /* if we're still here, there is no input yet
+ - wait for input */
+ int ret = input_curl_select(c);
+ if (ret <= 0)
+ /* no data yet or error */
+ return false;
+ }
+
+ mcode = curl_multi_perform(c->multi, &running_handles);
+ if (mcode != CURLM_OK && mcode != CURLM_CALL_MULTI_PERFORM) {
+ g_warning("curl_multi_perform() failed: %s\n",
+ curl_multi_strerror(mcode));
+ c->eof = true;
+ is->ready = true;
+ return false;
+ }
+
+ bret = input_curl_multi_info_read(is);
+ if (!bret)
+ return false;
+ }
+
+ return true;
+}
+
/**
* Mark a part of the buffer object as consumed.
*/
@@ -381,7 +417,7 @@ static size_t
input_curl_read(struct input_stream *is, void *ptr, size_t size)
{
struct input_curl *c = is->data;
- CURLMcode mcode = CURLM_CALL_MULTI_PERFORM;
+ bool success;
GQueue *rewind_buffers;
size_t nbytes = 0;
char *dest = ptr;
@@ -409,32 +445,9 @@ input_curl_read(struct input_stream *is, void *ptr, size_t size)
/* fill the buffer */
- while (!c->eof && g_queue_is_empty(c->buffers)) {
- int running_handles;
- bool bret;
-
- if (mcode != CURLM_CALL_MULTI_PERFORM) {
- /* if we're still here, there is no input yet
- - wait for input */
- int ret = input_curl_select(c);
- if (ret <= 0)
- /* no data yet or error */
- return 0;
- }
-
- mcode = curl_multi_perform(c->multi, &running_handles);
- if (mcode != CURLM_OK && mcode != CURLM_CALL_MULTI_PERFORM) {
- g_warning("curl_multi_perform() failed: %s\n",
- curl_multi_strerror(mcode));
- c->eof = true;
- is->ready = true;
- return 0;
- }
-
- bret = input_curl_multi_info_read(is);
- if (!bret)
- return 0;
- }
+ success = fill_buffer(is);
+ if (!success)
+ return 0;
/* send buffer contents */