diff options
author | Max Kellermann <max@duempel.org> | 2011-09-16 08:27:59 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-09-16 11:36:09 +0200 |
commit | a6d6873856bb024608d50b7d9f6c1167827c76ec (patch) | |
tree | de52fc0b1f4816f3c5438d759a9d17948e6c6f74 /src/input/soup_input_plugin.c | |
parent | e99df3a3be853067fc2cdb17f1e45f61eae4b697 (diff) | |
download | mpd-a6d6873856bb024608d50b7d9f6c1167827c76ec.tar.gz mpd-a6d6873856bb024608d50b7d9f6c1167827c76ec.tar.xz mpd-a6d6873856bb024608d50b7d9f6c1167827c76ec.zip |
input/soup: return real GErrors to the caller
Add attribute postponed_error, pass this GError to the caller.
Diffstat (limited to '')
-rw-r--r-- | src/input/soup_input_plugin.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/input/soup_input_plugin.c b/src/input/soup_input_plugin.c index 753bb19ab..710800294 100644 --- a/src/input/soup_input_plugin.c +++ b/src/input/soup_input_plugin.c @@ -58,6 +58,8 @@ struct input_soup { size_t total_buffered; bool alive, pause, eof; + + GError *postponed_error; }; static inline GQuark @@ -128,6 +130,16 @@ input_soup_got_headers(SoupMessage *msg, gpointer user_data) struct input_soup *s = user_data; if (!SOUP_STATUS_IS_SUCCESSFUL(msg->status_code)) { + g_mutex_lock(s->mutex); + + if (s->postponed_error == NULL) + s->postponed_error = + g_error_new(soup_quark(), msg->status_code, + "got HTTP status %d", + msg->status_code); + + g_mutex_unlock(s->mutex); + soup_session_cancel_message(soup_session, msg, SOUP_STATUS_CANCELLED); return; @@ -230,6 +242,7 @@ input_soup_open(const char *uri, G_GNUC_UNUSED GError **error_r) s->alive = true; s->pause = false; s->eof = false; + s->postponed_error = NULL; soup_session_queue_message(soup_session, s->msg, input_soup_session_callback, s); @@ -286,10 +299,19 @@ input_soup_buffer(struct input_stream *is, GError **error_r) bool success = input_soup_wait_data(s); + + if (!success) { + if (s->postponed_error != NULL) { + g_propagate_error(error_r, s->postponed_error); + s->postponed_error = NULL; + } else + g_set_error_literal(error_r, soup_quark(), 0, + "HTTP failure"); + } + g_mutex_unlock(s->mutex); if (!success) { - g_set_error_literal(error_r, soup_quark(), 0, "HTTP failure"); return -1; } @@ -306,9 +328,15 @@ input_soup_read(struct input_stream *is, void *ptr, size_t size, if (!input_soup_wait_data(s)) { assert(!s->alive); - g_mutex_unlock(s->mutex); - g_set_error_literal(error_r, soup_quark(), 0, "HTTP failure"); + if (s->postponed_error != NULL) { + g_propagate_error(error_r, s->postponed_error); + s->postponed_error = NULL; + } else + g_set_error_literal(error_r, soup_quark(), 0, + "HTTP failure"); + + g_mutex_unlock(s->mutex); return 0; } |