aboutsummaryrefslogtreecommitdiffstats
path: root/src/input/CurlInputPlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-10 20:52:25 +0100
committerMax Kellermann <max@duempel.org>2013-01-10 20:52:58 +0100
commit01f3131c819617d78ef74746fd008e4e8c2712ef (patch)
treef952a949ada938139ad0931189951367b74204cd /src/input/CurlInputPlugin.cxx
parent2ca92368647860929bc1b50d84ba93688d82abcc (diff)
downloadmpd-01f3131c819617d78ef74746fd008e4e8c2712ef.tar.gz
mpd-01f3131c819617d78ef74746fd008e4e8c2712ef.tar.xz
mpd-01f3131c819617d78ef74746fd008e4e8c2712ef.zip
input/Curl: use std::forward_list instead of GSList
Diffstat (limited to 'src/input/CurlInputPlugin.cxx')
-rw-r--r--src/input/CurlInputPlugin.cxx48
1 files changed, 21 insertions, 27 deletions
diff --git a/src/input/CurlInputPlugin.cxx b/src/input/CurlInputPlugin.cxx
index f1bd6c134..f3a5c87d2 100644
--- a/src/input/CurlInputPlugin.cxx
+++ b/src/input/CurlInputPlugin.cxx
@@ -42,6 +42,8 @@ extern "C" {
#include <string.h>
#include <errno.h>
+#include <forward_list>
+
#include <curl/curl.h>
#include <glib.h>
@@ -137,7 +139,7 @@ static struct {
* A linked list of all active HTTP requests. An active
* request is one that doesn't have the "eof" flag set.
*/
- GSList *requests;
+ std::forward_list<input_curl *> requests;
/**
* The GMainLoop source used to poll all CURL file
@@ -151,7 +153,7 @@ static struct {
guint source_id;
/** a linked list of all registered GPollFD objects */
- GSList *fds;
+ std::forward_list<GPollFD> fds;
/**
* Did CURL give us a timeout? If yes, then we need to call
@@ -183,11 +185,9 @@ input_curl_find_request(CURL *easy)
{
assert(io_thread_inside());
- for (GSList *i = curl.requests; i != NULL; i = g_slist_next(i)) {
- struct input_curl *c = (struct input_curl *)i->data;
+ for (auto c : curl.requests)
if (c->easy == easy)
return c;
- }
return NULL;
}
@@ -260,18 +260,15 @@ curl_update_fds(void)
return;
}
- GSList *fds = curl.fds;
- curl.fds = NULL;
+ for (auto prev = curl.fds.before_begin(), end = curl.fds.end(),
+ i = std::next(prev);
+ i != end; i = std::next(prev)) {
+ const auto poll_fd = &*i;
+ assert(poll_fd->events != 0);
- while (fds != NULL) {
- GPollFD *poll_fd = (GPollFD *)fds->data;
gushort events = input_curl_fd_events(poll_fd->fd, &rfds,
&wfds, &efds);
- assert(poll_fd->events != 0);
-
- fds = g_slist_remove(fds, poll_fd);
-
if (events != poll_fd->events)
g_source_remove_poll(curl.source, poll_fd);
@@ -281,20 +278,20 @@ curl_update_fds(void)
g_source_add_poll(curl.source, poll_fd);
}
- curl.fds = g_slist_prepend(curl.fds, poll_fd);
+ prev = i;
} else {
- g_free(poll_fd);
+ curl.fds.erase_after(prev);
}
}
for (int fd = 0; fd <= max_fd; ++fd) {
gushort events = input_curl_fd_events(fd, &rfds, &wfds, &efds);
if (events != 0) {
- GPollFD *poll_fd = g_new(GPollFD, 1);
+ curl.fds.push_front(GPollFD());
+ const auto poll_fd = &curl.fds.front();
poll_fd->fd = fd;
poll_fd->events = events;
g_source_add_poll(curl.source, poll_fd);
- curl.fds = g_slist_prepend(curl.fds, poll_fd);
}
}
}
@@ -310,7 +307,7 @@ input_curl_easy_add(struct input_curl *c, GError **error_r)
assert(c->easy != NULL);
assert(input_curl_find_request(c->easy) == NULL);
- curl.requests = g_slist_prepend(curl.requests, c);
+ curl.requests.push_front(c);
CURLMcode mcode = curl_multi_add_handle(curl.multi, c->easy);
if (mcode != CURLM_OK) {
@@ -375,7 +372,7 @@ input_curl_easy_free(struct input_curl *c)
if (c->easy == NULL)
return;
- curl.requests = g_slist_remove(curl.requests, c);
+ curl.requests.remove(c);
curl_multi_remove_handle(curl.multi, c->easy);
curl_easy_cleanup(c->easy);
@@ -423,9 +420,8 @@ input_curl_abort_all_requests(GError *error)
assert(io_thread_inside());
assert(error != NULL);
- while (curl.requests != NULL) {
- struct input_curl *c =
- (struct input_curl *)curl.requests->data;
+ while (!curl.requests.empty()) {
+ struct input_curl *c = curl.requests.front();
assert(c->postponed_error == NULL);
input_curl_easy_free(c);
@@ -586,11 +582,9 @@ input_curl_source_check(G_GNUC_UNUSED GSource *source)
return true;
}
- for (GSList *i = curl.fds; i != NULL; i = i->next) {
- GPollFD *poll_fd = (GPollFD *)i->data;
- if (poll_fd->revents != 0)
+ for (const auto &i : curl.fds)
+ if (i.revents != 0)
return true;
- }
return false;
}
@@ -682,7 +676,7 @@ curl_destroy_sources(G_GNUC_UNUSED gpointer data)
static void
input_curl_finish(void)
{
- assert(curl.requests == NULL);
+ assert(curl.requests.empty());
io_thread_call(curl_destroy_sources, NULL);