Get fds function

FossilOrigin-Name: f2e861ab0b82431686099ea537def9b3344d390b3c7445643b9b09986e48be32
This commit is contained in:
nekobit 2023-03-06 03:14:01 +00:00
parent 8c40a4c3c5
commit 05af07a450
5 changed files with 74 additions and 16 deletions

View file

@ -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);

View file

@ -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);

View file

@ -2,6 +2,8 @@
* Licensed under BSD 3-Clause License
*/
#include <sys/select.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
@ -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)
{

View file

@ -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}
)
# 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)

View file

@ -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;
}