input_curl: use curl_multi_info_read()

The function curl_multi_info_read() provides access to errors from the
curl easy interface.
This commit is contained in:
Max Kellermann 2008-11-03 21:49:43 +01:00
parent fdf0d46e3d
commit 75d2a39768

View File

@ -143,6 +143,27 @@ input_curl_free(struct input_stream *is)
g_free(c);
}
static bool
input_curl_multi_info_read(struct input_stream *is)
{
struct input_curl *c = is->data;
CURLMsg *msg;
int msgs_in_queue;
while ((msg = curl_multi_info_read(c->multi,
&msgs_in_queue)) != NULL) {
if (msg->msg == CURLMSG_DONE &&
msg->data.result != CURLE_OK) {
g_warning("curl failed: %s\n",
curl_easy_strerror(msg->data.result));
c->eof = true;
return false;
}
}
return true;
}
/**
* Wait for the libcurl socket.
*
@ -220,6 +241,7 @@ input_curl_read(struct input_stream *is, void *ptr, size_t size)
while (!c->eof && list_empty(&c->buffers)) {
int running_handles;
bool bret;
if (mcode != CURLM_CALL_MULTI_PERFORM) {
/* if we're still here, there is no input yet
@ -238,6 +260,10 @@ input_curl_read(struct input_stream *is, void *ptr, size_t size)
return 0;
}
bret = input_curl_multi_info_read(is);
if (!bret)
return -1;
c->eof = running_handles == 0;
}
@ -292,11 +318,12 @@ input_curl_eof(mpd_unused struct input_stream *is)
}
static int
input_curl_buffer(mpd_unused struct input_stream *is)
input_curl_buffer(struct input_stream *is)
{
struct input_curl *c = is->data;
CURLMcode mcode;
int running_handles;
bool ret;
c->buffered = false;
@ -311,6 +338,10 @@ input_curl_buffer(mpd_unused struct input_stream *is)
return -1;
}
ret = input_curl_multi_info_read(is);
if (!ret)
return -1;
c->eof = running_handles == 0;
return c->buffered;