From 05af07a450f7cf8f88f720fba4c4d664bb85dd54 Mon Sep 17 00:00:00 2001 From: nekobit Date: Mon, 6 Mar 2023 03:14:01 +0000 Subject: [PATCH] Get fds function FossilOrigin-Name: f2e861ab0b82431686099ea537def9b3344d390b3c7445643b9b09986e48be32 --- include/mastodont.h | 8 ++++---- include/mastodont_fetch.h | 35 ++++++++++++++++++++++++++++------- src/fetch.c | 18 +++++++++++++++++- tests/CMakeLists.txt | 23 ++++++++++++++++++++++- tests/get_feed.c | 6 +++--- 5 files changed, 74 insertions(+), 16 deletions(-) diff --git a/include/mastodont.h b/include/mastodont.h index 253135c..350e28f 100644 --- a/include/mastodont.h +++ b/include/mastodont.h @@ -28,8 +28,8 @@ mstdnt_global_curl_cleanup(void); /** * Initializes a mstdnt struct * - * @param data Pointer to struct to fill in - * @return Value of curl_easy_init(); either Zero or non-zero + * \param data Pointer to struct to fill in + * \return Value of curl_easy_init(); either Zero or non-zero */ int mstdnt_init(mastodont_t* data); @@ -37,7 +37,7 @@ mstdnt_init(mastodont_t* data); /** * Cleans up the mstdnt struct * - * @param data Pointer to the mstdnt data + * \param data Pointer to the mstdnt data */ void mstdnt_cleanup(mastodont_t* data); @@ -47,7 +47,7 @@ mstdnt_cleanup(mastodont_t* data); * * This contains information such as JSON information and errors. * - * @param storage The storage block to cleanup + * \param storage The storage block to cleanup */ void mstdnt_storage_cleanup(struct mstdnt_storage *storage); diff --git a/include/mastodont_fetch.h b/include/mastodont_fetch.h index 78828db..efc6cca 100644 --- a/include/mastodont_fetch.h +++ b/include/mastodont_fetch.h @@ -67,22 +67,43 @@ int mstdnt_fetch_curl_async(mastodont_t* mstdnt, char* request_t_custom); /** - * @brief Blocks until a transfer is complete. + * \brief Blocks until a transfer is complete. * - * You can also check curl's socket + * You can also check curl's socket, but mastodont offers ways to do that + * in case of change * - * @param mstdnt Mastodont struct - * @param opt Option, MSTDNT_AWAIT_ALL means it will keep going until + * \param mstdnt Mastodont struct + * \param opt Option, MSTDNT_AWAIT_ALL means it will keep going until * there are no more transfers. MSTDNT_AWAIT_ONCE will run - * @param extra_fds Set of file descriptors to poll alongside + * \param extra_fds Set of file descriptors to poll alongside * the mastodont data. - * @param nfds Length of extra_fds - * @return 1 on error + * \param nfds Length of extra_fds + * \return 1 on error */ int mstdnt_await(mastodont_t* mstdnt, enum mstdnt_fetch_await opt, struct mstdnt_fd extra_fds[], size_t nfds); + + +/** + * Returns a array of file descriptors to network sockets (if any) + * + * These file descriptors only notify when ready to read. + * + * \remark If you need the write-ready sockets available, poke at CURLM* + directly + * \remark Usually required if you want to interface Mastodont with + * application event loops (i.e. GTK, QT, EFL) + * + * \param set Reference ptr to set + * \param nfds Number of file descriptors to check for reading. + * \return 0 on success, 1 on error + */ +int +mstdnt_get_fds(mastodont_t* mstdnt, + fd_set* set, + int* nfds); void mstdnt_request_cb_cleanup(mstdnt_request_cb_data* data); diff --git a/src/fetch.c b/src/fetch.c index a4f4b26..7a40b12 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -2,6 +2,8 @@ * Licensed under BSD 3-Clause License */ +#include +#include #include #include #include @@ -114,6 +116,20 @@ int mstdnt_fetch_curl_async(mastodont_t* mstdnt, return 0; } +int +mstdnt_get_fds(mastodont_t* mstdnt, + fd_set* set, + int* nfds) +{ + assert(mstdnt && nfds); + + return curl_multi_fdset(mstdnt->curl, + set, + NULL, + NULL, + nfds) != CURLM_OK; +} + int mstdnt_await(mastodont_t* mstdnt, enum mstdnt_fetch_await opt, struct mstdnt_fd extra_fds[], @@ -208,7 +224,7 @@ int mstdnt_await(mastodont_t* mstdnt, return res; } -void mstdnt_storage_cleanup(struct mstdnt_storage* storage); +void mstdnt_storage_cleanup(struct mstdnt_storage* storage);// ? void mstdnt_fetch_data_cleanup(struct mstdnt_fetch_data* res) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3e44030..4c14e1b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,5 @@ include(../cmake/mastodont-config.cmake) + add_executable(get_feed get_feed.c) target_compile_options(get_feed PUBLIC -std=c99 -Wall) target_link_libraries(get_feed PUBLIC @@ -7,4 +8,24 @@ target_link_libraries(get_feed PUBLIC target_include_directories(get_feed PUBLIC ${MASTODONT_INCLUDE_DIRS} ) - \ No newline at end of file + + +# GUI demo +pkg_check_modules(EFL_ECORE efl-core) +if (EFL_ECORE_FOUND) + # EFL is clearly installed... + pkg_check_modules(EFL_ELEMENTARY elementary) + + add_executable(get_feed_efl get_feed_efl.c) + target_compile_options(get_feed_efl PUBLIC -std=c99 -Wall) + target_link_libraries(get_feed_efl PUBLIC + ${MASTODONT_LIBRARIES} + ${EFL_ECORE_LIBRARIES} + ${EFL_ELEMENTARY_LIBRARIES} + ) + target_include_directories(get_feed_efl PUBLIC + ${MASTODONT_INCLUDE_DIRS} + ${EFL_ECORE_INCLUDE_DIRS} + ${EFL_ELEMENTARY_INCLUDE_DIRS} + ) +endif(EFL_ECORE_FOUND) diff --git a/tests/get_feed.c b/tests/get_feed.c index 5b90740..f57bc16 100644 --- a/tests/get_feed.c +++ b/tests/get_feed.c @@ -82,9 +82,9 @@ main(int argc, char** argv) mstdnt_await(&data, 0, NULL, 0); // Cleanup - //free(instance); - //mstdnt_cleanup(&data); - //mstdnt_global_curl_cleanup(); + free(instance); + mstdnt_cleanup(&data); + mstdnt_global_curl_cleanup(); return 1; }