The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Functions
io.c File Reference

Common functions for interacting with Redis via hiredis. More...

#include <freeradius-devel/redis/io.h>
#include <freeradius-devel/util/debug.h>
#include <hiredis/async.h>
+ Include dependency graph for io.c:

Go to the source code of this file.

Functions

static void _redis_connected (redisAsyncContext const *ac, UNUSED int status)
 Called by hiredis to indicate the connection is live. More...
 
static void _redis_disconnected (redisAsyncContext const *ac, UNUSED int status)
 Called by hiredis to indicate the connection is dead. More...
 
static int _redis_handle_free (fr_redis_handle_t *h)
 Free the redis async context when the handle is freed. More...
 
static void _redis_io_add_read (void *uctx)
 Register FD for reads. More...
 
static void _redis_io_add_write (void *uctx)
 Register FD for writes. More...
 
static void _redis_io_common (fr_connection_t *conn, fr_redis_handle_t *h, bool read, bool write)
 Deal with the method hiredis uses to register/unregister interest in a file descriptor. More...
 
static void _redis_io_connection_close (UNUSED fr_event_list_t *el, void *h, UNUSED void *uctx)
 Notification that the connection has errored and must be closed. More...
 
static fr_connection_state_t _redis_io_connection_init (void **h_out, fr_connection_t *conn, void *uctx)
 Callback for the initialise state. More...
 
static fr_connection_state_t _redis_io_connection_shutdown (UNUSED fr_event_list_t *el, void *h, UNUSED void *uctx)
 Gracefully signal that the connection should shutdown. More...
 
static void _redis_io_del_read (void *uctx)
 De-register FD for reads. More...
 
static void _redis_io_del_write (void *uctx)
 De-register FD for writes. More...
 
static void _redis_io_free (void *uctx)
 Handle freeing the redisAsyncContext. More...
 
static void _redis_io_service_errored (UNUSED fr_event_list_t *el, int fd, UNUSED int flags, int fd_errno, void *uctx)
 Redis FD errored - Automatically removes registered events. More...
 
static void _redis_io_service_readable (UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
 Redis FD became readable. More...
 
static void _redis_io_service_writable (UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
 Redis FD became writable. More...
 
fr_connection_tfr_redis_connection_alloc (TALLOC_CTX *ctx, fr_event_list_t *el, fr_connection_conf_t const *conn_conf, fr_redis_io_conf_t const *io_conf, char const *log_prefix)
 Allocate an async redis I/O connection. More...
 
redisAsyncContext * fr_redis_connection_get_async_ctx (fr_connection_t *conn)
 Return the redisAsyncContext associated with the connection. More...
 
static int fr_redis_io_setup (redisAsyncContext *ac, fr_connection_t const *conn)
 Configures async I/O callbacks for an existing redisAsyncContext. More...
 

Detailed Description

Common functions for interacting with Redis via hiredis.

Id
8cebe08fc00ccbefc09327065594498db07010c5
Author
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.

Function Documentation

◆ _redis_connected()

static void _redis_connected ( redisAsyncContext const *  ac,
UNUSED int  status 
)
static

Called by hiredis to indicate the connection is live.

Definition at line 60 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _redis_disconnected()

static void _redis_disconnected ( redisAsyncContext const *  ac,
UNUSED int  status 
)
static

Called by hiredis to indicate the connection is dead.

Definition at line 36 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _redis_handle_free()

static int _redis_handle_free ( fr_redis_handle_t h)
static

Free the redis async context when the handle is freed.

Definition at line 281 of file io.c.

+ Here is the caller graph for this function:

◆ _redis_io_add_read()

static void _redis_io_add_read ( void *  uctx)
static

Register FD for reads.

Definition at line 155 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _redis_io_add_write()

static void _redis_io_add_write ( void *  uctx)
static

Register FD for writes.

Definition at line 177 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _redis_io_common()

static void _redis_io_common ( fr_connection_t conn,
fr_redis_handle_t h,
bool  read,
bool  write 
)
static

Deal with the method hiredis uses to register/unregister interest in a file descriptor.

Definition at line 115 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _redis_io_connection_close()

static void _redis_io_connection_close ( UNUSED fr_event_list_t el,
void *  h,
UNUSED void *  uctx 
)
static

Notification that the connection has errored and must be closed.

This should be used to close the file descriptor. It is assumed that the file descriptor is invalid after this callback has been executed.

If this callback does not close the file descriptor, the server will leak file descriptors.

Parameters
[in]elto remove event handlers from.
[in]hto close.
[in]uctxUser context.

Definition at line 406 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _redis_io_connection_init()

static fr_connection_state_t _redis_io_connection_init ( void **  h_out,
fr_connection_t conn,
void *  uctx 
)
static

Callback for the initialise state.

Should attempt to open a non-blocking connection and return it in h_out.

Parameters
[out]h_outWhere to write the new handle
[in]connThis connection. Opaque, should only be used for signalling the connection state machine.
[in]uctxUser context.
Returns

Definition at line 305 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _redis_io_connection_shutdown()

static fr_connection_state_t _redis_io_connection_shutdown ( UNUSED fr_event_list_t el,
void *  h,
UNUSED void *  uctx 
)
static

Gracefully signal that the connection should shutdown.

Definition at line 385 of file io.c.

+ Here is the caller graph for this function:

◆ _redis_io_del_read()

static void _redis_io_del_read ( void *  uctx)
static

De-register FD for reads.

Definition at line 166 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _redis_io_del_write()

static void _redis_io_del_write ( void *  uctx)
static

De-register FD for writes.

Definition at line 188 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _redis_io_free()

static void _redis_io_free ( void *  uctx)
static

Handle freeing the redisAsyncContext.

delRead and delWrite don't seem to be called when the redisAsyncContext is freed

As the IO events must be removed from the event loop before the FD is closed and as the IO events will only be automatically de-registered when when the fr_redis_handle_t is freed.

Unfortunately the destructor for the fr_redis_handle_t will be run before the IO events are de-registered, which'll free the redisAsycCtx, which'll close the FD.

This means there'd be a brief period of time between the FD is closed, and it being removed from the event loop.

We use the cleanup callback (which is called before the FD is closed) to remove the events now, and ensure there's no chance of issues.

Definition at line 248 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _redis_io_service_errored()

static void _redis_io_service_errored ( UNUSED fr_event_list_t el,
int  fd,
UNUSED int  flags,
int  fd_errno,
void *  uctx 
)
static

Redis FD errored - Automatically removes registered events.

Definition at line 98 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _redis_io_service_readable()

static void _redis_io_service_readable ( UNUSED fr_event_list_t el,
int  fd,
UNUSED int  flags,
void *  uctx 
)
static

Redis FD became readable.

Definition at line 72 of file io.c.

+ Here is the caller graph for this function:

◆ _redis_io_service_writable()

static void _redis_io_service_writable ( UNUSED fr_event_list_t el,
int  fd,
UNUSED int  flags,
void *  uctx 
)
static

Redis FD became writable.

Definition at line 85 of file io.c.

+ Here is the caller graph for this function:

◆ fr_redis_connection_alloc()

fr_connection_t* fr_redis_connection_alloc ( TALLOC_CTX *  ctx,
fr_event_list_t el,
fr_connection_conf_t const *  conn_conf,
fr_redis_io_conf_t const *  io_conf,
char const *  log_prefix 
)

Allocate an async redis I/O connection.

Definition at line 421 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_redis_connection_get_async_ctx()

redisAsyncContext* fr_redis_connection_get_async_ctx ( fr_connection_t conn)

Return the redisAsyncContext associated with the connection.

This is needed to issue commands to the redis server.

Parameters
[in]connTo retrieve async ctx from.
Returns
The async ctx.

Definition at line 454 of file io.c.

◆ fr_redis_io_setup()

static int fr_redis_io_setup ( redisAsyncContext *  ac,
fr_connection_t const *  conn 
)
static

Configures async I/O callbacks for an existing redisAsyncContext.

Definition at line 261 of file io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: