diff --git a/src/fetch.c b/src/fetch.c index 67464c4..7d3d7a7 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -157,7 +157,7 @@ int mstdnt_await(mastodont_t* mstdnt, } int numfds; - int running = 1; + int running; // Data used with response, must keep it with request struct mstdnt_fetch_data* data; // Data that the user will work with @@ -168,56 +168,57 @@ int mstdnt_await(mastodont_t* mstdnt, do { // TODO error check - curl_multi_perform(mstdnt->curl, &running); + res = curl_multi_perform(mstdnt->curl, &running); + + if (running) + res = curl_multi_poll(mstdnt->curl, fds, nfds, 1000, &numfds); - res = curl_multi_poll(mstdnt->curl, fds, nfds, 1000, &numfds); - - while ((msg = curl_multi_info_read(mstdnt->curl, &msgs_left)) != NULL) - { - if (msg->msg == CURLMSG_DONE) - { - // Get easy info - curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &data); - // Setup - results->fetch_data = data; // So we can clean it up - results->storage.needs_cleanup = 0; - - // Get json - if (_mstdnt_json_init(&(results->root), - data, - &(results->storage))) - { - res = 1; - goto cleanup_res; - } - - // 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); - - cleanup_res: - /* The response of the callback is important! - * If the user returns the below response, then the request - * must be cleaned up manually by them */ - if (res != MSTDNT_REQUEST_DATA_NOCLEANUP) - { - // Will cleanup fetch too - mstdnt_request_cb_cleanup(results); - } - // We can clean the handle up though - curl_multi_remove_handle(mstdnt->curl, msg->easy_handle); - curl_easy_cleanup(msg->easy_handle); - } - } - if (res) break; } while (/* opt == MSTDNT_AWAIT_ALL && msgs_left */ running); + + while ((msg = curl_multi_info_read(mstdnt->curl, &msgs_left)) != NULL) + { + if (msg->msg == CURLMSG_DONE) + { + // Get easy info + curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &data); + // Setup + results->fetch_data = data; // So we can clean it up + results->storage.needs_cleanup = 0; + + // Get json + if (_mstdnt_json_init(&(results->root), + data, + &(results->storage))) + { + res = 1; + goto cleanup_res; + } + + // 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); + + cleanup_res: + /* The response of the callback is important! + * If the user returns the below response, then the request + * must be cleaned up manually by them */ + if (res != MSTDNT_REQUEST_DATA_NOCLEANUP) + { + // Will cleanup fetch too + mstdnt_request_cb_cleanup(results); + } + // We can clean the handle up though + curl_multi_remove_handle(mstdnt->curl, msg->easy_handle); + curl_easy_cleanup(msg->easy_handle); + } + } // Put revents back for callee if (extra_fds) diff --git a/tests/get_feed_efl.c b/tests/get_feed_efl.c index 5313f45..a35c995 100644 --- a/tests/get_feed_efl.c +++ b/tests/get_feed_efl.c @@ -25,10 +25,21 @@ gui_quit_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED) efl_exit(0); } +static void +gui_create_status(struct mstdnt_status* status) +{ + Eo* root = efl_add(EFL_UI_BOX_CLASS, + efl_name_set(efl_added, "Status")); + + //Eo* avatar = efl_add(); + + return root; +} + static void gui_add_status(struct mstdnt_status* status) { - + efl_pack_end(gui_create_status(status)); } int @@ -39,7 +50,7 @@ tl_callback(mstdnt_request_cb_data* cb_data, void* args) for (int i = 0; i < statuses->len; ++i) { struct mstdnt_status* status = statuses->statuses + i; - + gui_add_status(status); } return MSTDNT_REQUEST_DONE; @@ -69,8 +80,15 @@ mstdnt_results_cb(void* data EINA_UNUSED, const Efl_Event* event EINA_UNUSED) mstdnt_await(&mstdnt, 0, NULL, 0); } +static void +mstdnt_update_cb(void* data EINA_UNUSED, const Efl_Event* event EINA_UNUSED) +{ + int running; + curl_multi_perform(mstdnt.curl, &running); +} + void -update_mstdnt_fds(void) +update_mstdnt_fds() { int nfds; // Get @@ -82,18 +100,26 @@ update_mstdnt_fds(void) FD_ZERO(&error); mstdnt_get_fds(&mstdnt, &read, &write, &error, &nfds); - printf("%d\n", nfds); - for (int i = 0; i < nfds; ++i) + for (int i = 0; i <= nfds; ++i) { + printf("FD_ISSET: %i\n", i); if (FD_ISSET(i, &read)) { - printf("Added: %i\n", i); - fd = efl_add(EFL_LOOP_FD_CLASS, + efl_add(EFL_LOOP_FD_CLASS, efl_main_loop_get(), efl_loop_fd_set(efl_added, i), efl_event_callback_add(efl_added, EFL_LOOP_FD_EVENT_READ, mstdnt_results_cb, &i)); } +#if 0 + if (FD_ISSET(i, &write)) + { + efl_add(EFL_LOOP_FD_CLASS, + efl_main_loop_get(), + efl_loop_fd_set(efl_added, i), + efl_event_callback_add(efl_added, EFL_LOOP_FD_EVENT_WRITE, mstdnt_update_cb, &i)); + } +#endif } }