Compare commits
2 Commits
61f9697250
...
536226e3ab
Author | SHA1 | Date |
---|---|---|
nekobit | 536226e3ab | |
nekobit | cc06a401a4 |
31
src/fetch.c
31
src/fetch.c
|
@ -10,6 +10,7 @@
|
|||
#include <mastodont_hooks.h>
|
||||
#include <mastodont_fetch.h>
|
||||
#include <mastodont_json_helper.h>
|
||||
#include <mastodont_error.h>
|
||||
|
||||
/* For use with libcurl */
|
||||
size_t mstdnt_curl_write_callback(char* ptr, size_t _size, size_t nmemb, void* _content)
|
||||
|
@ -161,7 +162,6 @@ int mstdnt_await(mastodont_t* mstdnt,
|
|||
// Data used with response, must keep it with request
|
||||
struct mstdnt_fetch_data* data;
|
||||
// Data that the user will work with
|
||||
mstdnt_request_cb_data* results = calloc(1, sizeof(mstdnt_request_cb_data));
|
||||
|
||||
// Check if our socket is done
|
||||
// BUG: Reusing data structures if multiple transfers in place
|
||||
|
@ -170,7 +170,7 @@ int mstdnt_await(mastodont_t* mstdnt,
|
|||
// TODO error check
|
||||
res = curl_multi_perform(mstdnt->curl, &running);
|
||||
|
||||
if (running)
|
||||
if (running || nfds)
|
||||
res = curl_multi_poll(mstdnt->curl, fds, nfds, 1000, &numfds);
|
||||
|
||||
if (res) break;
|
||||
|
@ -184,6 +184,8 @@ int mstdnt_await(mastodont_t* mstdnt,
|
|||
// Get easy info
|
||||
curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &data);
|
||||
// Setup
|
||||
mstdnt_request_cb_data* results = calloc(1, sizeof(mstdnt_request_cb_data));
|
||||
|
||||
results->fetch_data = data; // So we can clean it up
|
||||
results->storage.needs_cleanup = 0;
|
||||
|
||||
|
@ -195,15 +197,21 @@ int mstdnt_await(mastodont_t* mstdnt,
|
|||
res = 1;
|
||||
goto cleanup_res;
|
||||
}
|
||||
|
||||
if (!mstdnt_check_error(&results->storage))
|
||||
{
|
||||
// Pass data to json callback, so it can store it's data
|
||||
if (data->json_cb)
|
||||
res = data->json_cb(results->storage.root,
|
||||
data->json_args,
|
||||
results);
|
||||
}
|
||||
|
||||
// Pass data to json callback, so it can store it's data
|
||||
if (data->json_cb)
|
||||
res = data->json_cb(results->storage.root,
|
||||
data->json_args,
|
||||
results);
|
||||
|
||||
// Call the actual callback
|
||||
res = data->callback(results, data->callback_args);
|
||||
// Call the actual callback, regardless of error
|
||||
if (data->callback)
|
||||
res = data->callback(results, data->callback_args);
|
||||
else
|
||||
res = MSTDNT_REQUEST_DONE;
|
||||
|
||||
cleanup_res:
|
||||
/* The response of the callback is important!
|
||||
|
@ -243,7 +251,8 @@ void
|
|||
mstdnt_request_cb_cleanup(mstdnt_request_cb_data* data)
|
||||
{
|
||||
mstdnt_storage_cleanup(&(data->storage));
|
||||
data->data_free_cb(data->data);
|
||||
if (data->data_free_cb)
|
||||
data->data_free_cb(data->data);
|
||||
// Cleanup
|
||||
mstdnt_fetch_data_cleanup(data->fetch_data);
|
||||
// Free ourself
|
||||
|
|
Loading…
Reference in New Issue