The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
io.c
Go to the documentation of this file.
1/*
2 * This program is is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: a0c28f0263cfaf973ad0ea0adf493410eb3a922f $
19 * @file rlm_rest/io.c
20 * @brief Implement asynchronous callbacks for curl
21 *
22 * @copyright 2016 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
23 */
24#include "rest.h"
25#include <freeradius-devel/util/debug.h>
26#include <freeradius-devel/server/module_rlm.h>
27
28/** Handle asynchronous cancellation of a request
29 *
30 * If we're signalled that the request has been cancelled (FR_SIGNAL_CANCEL).
31 * Cleanup any pending state and release the connection handle back into the pool.
32 */
34{
35 fr_curl_io_request_t *randle = talloc_get_type_abort(mctx->rctx, fr_curl_io_request_t);
36 rlm_rest_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_rest_thread_t);
37 CURLMcode ret;
38
39 RDEBUG2("Forcefully cancelling pending REST request");
40
41 ret = curl_multi_remove_handle(t->mhandle->mandle, randle->candle); /* Gracefully terminate the request */
42 if (ret != CURLM_OK) {
43 RERROR("Failed removing curl handle from multi-handle: %s (%i)", curl_multi_strerror(ret), ret);
44 /* Not much we can do */
45 }
46 t->mhandle->transfers--;
47
48 rest_slab_release(randle);
49}
50
51/** Handle asynchronous cancellation of a request
52 *
53 * If we're signalled that the request has been cancelled (FR_SIGNAL_CANCEL).
54 * Cleanup any pending state and release the connection handle back into the pool.
55 */
56void rest_io_xlat_signal(xlat_ctx_t const *xctx, request_t *request, fr_signal_t action)
57{
58 rlm_rest_thread_t *t = talloc_get_type_abort(xctx->mctx->thread, rlm_rest_thread_t);
59
60 rlm_rest_xlat_rctx_t *our_rctx = talloc_get_type_abort(xctx->rctx, rlm_rest_xlat_rctx_t);
61 fr_curl_io_request_t *randle = talloc_get_type_abort(our_rctx->handle, fr_curl_io_request_t);
62
64 t,
65 xctx->mctx->env_data,
66 randle),
67 request,
68 action);
69}
#define UNUSED
Definition build.h:315
uint64_t transfers
How many transfers are current in progress.
Definition base.h:94
CURLM * mandle
The multi handle.
Definition base.h:95
CURL * candle
Request specific handle.
Definition base.h:102
Structure representing an individual request being passed to curl for processing.
Definition base.h:101
#define RERROR(fmt,...)
Definition log.h:298
void * env_data
Per call environment data.
Definition module_ctx.h:44
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
void * thread
Thread specific instance data.
Definition module_ctx.h:43
void * rctx
Resume ctx that a module previously set.
Definition module_ctx.h:45
#define MODULE_CTX(_mi, _thread, _env_data, _rctx)
Wrapper to create a module_ctx_t as a compound literal.
Definition module_ctx.h:128
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
void rest_io_module_signal(module_ctx_t const *mctx, request_t *request, UNUSED fr_signal_t action)
Handle asynchronous cancellation of a request.
Definition io.c:33
void rest_io_xlat_signal(xlat_ctx_t const *xctx, request_t *request, fr_signal_t action)
Handle asynchronous cancellation of a request.
Definition io.c:56
#define RDEBUG2(fmt,...)
Definition radclient.h:54
Function prototypes and datatypes for the REST (HTTP) transport.
fr_curl_handle_t * mhandle
Thread specific multi handle.
Definition rest.h:183
fr_curl_io_request_t * handle
curl easy handle servicing our request.
Definition rest.h:268
Thread specific rlm_rest instance data.
Definition rest.h:180
Stores the state of a yielded xlat.
Definition rest.h:266
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
void * rctx
Resume context.
Definition xlat_ctx.h:54
module_ctx_t const * mctx
Synthesised module calling ctx.
Definition xlat_ctx.h:52
An xlat calling ctx.
Definition xlat_ctx.h:49