Implement asynchronous callbacks for curl.
More...
#include <freeradius-devel/curl/base.h>
#include <freeradius-devel/server/module.h>
#include <freeradius-devel/unlang/interpret.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/syserror.h>
Go to the source code of this file.
|
static void | _fr_curl_io_demux (fr_curl_handle_t *mhandle, CURLM *mandle) |
| De-queue curl requests and wake up the requests that initiated them. More...
|
|
static int | _fr_curl_io_event_modify (UNUSED CURL *easy, curl_socket_t fd, int what, void *ctx, UNUSED void *fd_ctx) |
| Called by libcurl to register a socket that it's intefr_curled in receiving IO events for. More...
|
|
static int | _fr_curl_io_request_free (fr_curl_io_request_t *randle) |
|
static void | _fr_curl_io_service (fr_curl_handle_t *mhandle, int fd, int event) |
| Service an IO event on a file descriptor. More...
|
|
static void | _fr_curl_io_service_errored (UNUSED fr_event_list_t *el, int fd, int flags, int fd_errno, void *uctx) |
| File descriptor experienced an error. More...
|
|
static void | _fr_curl_io_service_readable (UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *uctx) |
| File descriptor became readable. More...
|
|
static void | _fr_curl_io_service_writable (UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *uctx) |
| File descriptor became writable. More...
|
|
static void | _fr_curl_io_timer_expired (UNUSED fr_event_list_t *el, UNUSED fr_time_t now, void *uctx) |
| libcurl's timer expired More...
|
|
static int | _fr_curl_io_timer_modify (CURLM *mandle, long timeout_ms, void *ctx) |
| Callback called by libcurl to set/unset timers. More...
|
|
static int | _mhandle_free (fr_curl_handle_t *mhandle) |
| Free the multi-handle. More...
|
|
static int | curl_debug_log (UNUSED CURL *candle, curl_infotype type, char *data, size_t len, void *uctx) |
| Callback to receive debugging data from libcurl. More...
|
|
fr_curl_handle_t * | fr_curl_io_init (TALLOC_CTX *ctx, fr_event_list_t *el, UNUSED bool multiplex) |
| Performs the libcurl initialisation of the thread. More...
|
|
fr_curl_io_request_t * | fr_curl_io_request_alloc (TALLOC_CTX *ctx) |
| Allocate a new curl easy request and wrapper struct. More...
|
|
int | fr_curl_io_request_enqueue (fr_curl_handle_t *mhandle, request_t *request, fr_curl_io_request_t *randle) |
| Sends a request using libcurl. More...
|
|
Implement asynchronous callbacks for curl.
- Id
- b72064bb98a3e1e49d61f15f5941c5cb9465dbc7
- Copyright
- 2020 Arran Cudbard-Bell (a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg)
Definition in file io.c.
◆ SET_MOPTION
#define SET_MOPTION |
( |
|
_mandle, |
|
|
|
_opt, |
|
|
|
_val |
|
) |
| |
Value:do {\
if ((ret = curl_multi_setopt(mandle, _opt, _val)) != CURLM_OK) {\
goto error;\
}\
} while (0)
Definition at line 38 of file io.c.
◆ _fr_curl_io_demux()
De-queue curl requests and wake up the requests that initiated them.
- Parameters
-
[in] | mhandle | containing the event loop and request counter. |
[in] | mandle | to dequeue curl easy handles/responses from. |
Definition at line 51 of file io.c.
◆ _fr_curl_io_event_modify()
static int _fr_curl_io_event_modify |
( |
UNUSED CURL * |
easy, |
|
|
curl_socket_t |
fd, |
|
|
int |
what, |
|
|
void * |
ctx, |
|
|
UNUSED void * |
fd_ctx |
|
) |
| |
|
static |
Called by libcurl to register a socket that it's intefr_curled in receiving IO events for.
- Parameters
-
[in] | easy | handle this fd relates to. |
[in] | fd | File descriptor curl wants to be notified about. |
[in] | what | Which events libcurl wants to be notified of, may be one of:
- CURL_POLL_IN Wait for incoming data. For the socket to become readable.
- CURL_POLL_OUT Wait for outgoing data. For the socket to become writable.
- CURL_POLL_INOUT Wait for incoming and outgoing data. For the socket to become readable or writable.
- CURL_POLL_REMOVE The specified socket/file descriptor is no longer used by libcurl.
|
[in] | ctx | The fr_curl_handle_t specific to this thread. |
[in] | fd_ctx | Private data associated with the socket. |
Definition at line 327 of file io.c.
◆ _fr_curl_io_request_free()
Definition at line 536 of file io.c.
◆ _fr_curl_io_service()
static void _fr_curl_io_service |
( |
fr_curl_handle_t * |
mhandle, |
|
|
int |
fd, |
|
|
int |
event |
|
) |
| |
|
inlinestatic |
Service an IO event on a file descriptor.
- Parameters
-
[in] | mhandle | containing the event loop and request counter. |
[in] | fd | the IO event occurred for. |
[in] | event | type. |
Definition at line 151 of file io.c.
◆ _fr_curl_io_service_errored()
static void _fr_curl_io_service_errored |
( |
UNUSED fr_event_list_t * |
el, |
|
|
int |
fd, |
|
|
int |
flags, |
|
|
int |
fd_errno, |
|
|
void * |
uctx |
|
) |
| |
|
static |
File descriptor experienced an error.
- Parameters
-
[in] | el | fd was registered with. |
[in] | fd | that errored. |
[in] | flags | from kevent. |
[in] | fd_errno | from kevent. |
[in] | uctx | The rlm_fr_curl_thread_t specific to this thread. |
Definition at line 205 of file io.c.
◆ _fr_curl_io_service_readable()
File descriptor became readable.
- Parameters
-
[in] | el | fd was registered with. |
[in] | fd | that became readable. |
[in] | flags | from kevent. |
[in] | uctx | The rlm_fr_curl_thread_t specific to this thread. |
Definition at line 251 of file io.c.
◆ _fr_curl_io_service_writable()
File descriptor became writable.
- Parameters
-
[in] | el | fd was registered with. |
[in] | fd | that became writable. |
[in] | flags | from kevent. |
[in] | uctx | The rlm_fr_curl_thread_t specific to this thread. |
Definition at line 235 of file io.c.
◆ _fr_curl_io_timer_expired()
libcurl's timer expired
- Parameters
-
[in] | el | the timer was inserted into. |
[in] | now | The current time according to the event loop. |
[in] | uctx | The rlm_fr_curl_thread_t specific to this thread. |
Definition at line 124 of file io.c.
◆ _fr_curl_io_timer_modify()
static int _fr_curl_io_timer_modify |
( |
CURLM * |
mandle, |
|
|
long |
timeout_ms, |
|
|
void * |
ctx |
|
) |
| |
|
static |
Callback called by libcurl to set/unset timers.
Each rlm_fr_curl_thread_t has a timer event which is controller by libcurl. This allows libcurl to honour timeouts set on requests to remote hosts, and means we don't need to set timeouts for individual I/O events.
- Parameters
-
[in] | mandle | handle requesting the timer be set/unset. |
[in] | timeout_ms | If > 0, how long to wait before calling curl_multi_socket_action. If == 0, we call curl_multi_socket_action as soon as possible. If < 0, we delete the timer. |
[in] | ctx | The rlm_fr_curl_thread_t specific to this thread. |
- Returns
- 0 on success.
- -1 on error.
Definition at line 275 of file io.c.
◆ _mhandle_free()
Free the multi-handle.
Definition at line 567 of file io.c.
◆ curl_debug_log()
static int curl_debug_log |
( |
UNUSED CURL * |
candle, |
|
|
curl_infotype |
type, |
|
|
char * |
data, |
|
|
size_t |
len, |
|
|
void * |
uctx |
|
) |
| |
|
static |
Callback to receive debugging data from libcurl.
- Note
- Should only be set on a handle if RDEBUG_ENABLED3 is true.
- Parameters
-
[in] | candle | Curl handle the debugging data pertains to. |
[in] | type | The type of debugging data we received. |
[in] | data | Buffer containing debug data (not \0 terminated). Despite the type being char *, this can be binary data depending on the curl_infotype. |
[in] | len | The length of the data in the buffer. |
[in] | uctx | The current request. |
- Returns
- 0 (we always indicate success)
Definition at line 401 of file io.c.
◆ fr_curl_io_init()
Performs the libcurl initialisation of the thread.
- Parameters
-
[in] | ctx | to alloc handle in. |
[in] | el | to initial. |
[in] | multiplex | Run multiple requests over the same connection simultaneously. HTTP/2 only. |
- Returns
- 0 on success.
- -1 on error.
Definition at line 584 of file io.c.
◆ fr_curl_io_request_alloc()
Allocate a new curl easy request and wrapper struct.
Definition at line 546 of file io.c.
◆ fr_curl_io_request_enqueue()
Sends a request using libcurl.
Send the actual curl request to the server. The response will be handled by the numerous callbacks configured for the easy handle.
- Parameters
-
[in] | mhandle | Thread-specific mhandle wrapper. |
[in] | request | Current request. |
[in] | randle | representing the request. |
- Returns
- 0 on success.
- -1 on failure.
Definition at line 482 of file io.c.