The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Binary IO abstractions. More...
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/dlist.h>
Go to the source code of this file.
Data Structures | |
struct | fr_bio_cb_funcs_t |
struct | fr_bio_s |
Macros | |
#define | _CONST const |
#define | fr_bio_error(_x) (-(FR_BIO_ERROR_ ## _x)) |
#define | XDEBUG(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__) |
Typedefs | |
typedef int(* | fr_bio_accept_t) (fr_bio_t *bio, TALLOC_CTX *ctx, fr_bio_t **accepted) |
Accept a new connection on a bio. More... | |
typedef int(* | fr_bio_callback_t) (fr_bio_t *bio) |
typedef ssize_t(* | fr_bio_read_t) (fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size) |
Do a raw read from a socket, or other data source. More... | |
typedef struct fr_bio_s | fr_bio_t |
typedef ssize_t(* | fr_bio_write_t) (fr_bio_t *bio, void *packet_ctx, const void *buffer, size_t size) |
Enumerations | |
enum | fr_bio_error_type_t { FR_BIO_ERROR_NONE = 0 , FR_BIO_ERROR_IO_WOULD_BLOCK , FR_BIO_ERROR_IO , FR_BIO_ERROR_GENERIC , FR_BIO_ERROR_VERIFY , FR_BIO_ERROR_BUFFER_FULL , FR_BIO_ERROR_BUFFER_TOO_SMALL , FR_BIO_ERROR_EOF } |
Functions | |
int | fr_bio_destructor (fr_bio_t *bio) |
Free this bio. More... | |
int | fr_bio_free (fr_bio_t *bio) |
Free this bio, and everything it calls. More... | |
static fr_bio_t * | fr_bio_next (fr_bio_t *bio) |
static fr_bio_t * | fr_bio_prev (fr_bio_t *bio) |
static ssize_t | fr_bio_read (fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size) |
Read raw data from a bio. More... | |
int | fr_bio_shutdown (fr_bio_t *bio) |
Shut down a set of BIOs. More... | |
int | fr_bio_shutdown_intermediate (fr_bio_t *bio) |
Like fr_bio_shutdown(), but can be called by anyone in the chain. More... | |
char const * | fr_bio_strerror (ssize_t error) |
static ssize_t | fr_bio_write (fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size) |
Write raw data to a bio. More... | |
Binary IO abstractions.
Create abstract binary input / output buffers.
Definition in file base.h.
struct fr_bio_cb_funcs_t |
Data Fields | ||
---|---|---|
fr_bio_callback_t | activate | |
fr_bio_callback_t | shutdown |
struct fr_bio_s |
Data Fields | ||
---|---|---|
fr_dlist_t _CONST | entry | in the linked list of multiple bios |
fr_bio_read_t _CONST | read | read from the underlying bio |
void * | uctx | user ctx, caller can manually set it. |
fr_bio_write_t _CONST | write | write to the underlying bio |
Do a raw read from a socket, or other data source.
These functions should be careful about packet_ctx. This handling depends on a number of factors. Note that the packet_ctx may be NULL!
Stream sockets will generally ignore packet_ctx.
Datagram sockets generally write src/dst IP/port to the packet context. This same packet_ctx is then passed to bio->write(), which can use it to send the data to the correct destination.
bio | the binary IO handler |
packet_ctx | where the function can store per-packet information, such as src/dst IP/port for datagram sockets |
buffer | where the function should store data it reads |
size | the maximum amount of data to read. |
enum fr_bio_error_type_t |
Enumerator | |
---|---|
FR_BIO_ERROR_NONE | |
FR_BIO_ERROR_IO_WOULD_BLOCK | IO would block. |
FR_BIO_ERROR_IO | IO error - check errno. |
FR_BIO_ERROR_GENERIC | generic "failed" error - check fr_strerror() |
FR_BIO_ERROR_VERIFY | some packet verification error |
FR_BIO_ERROR_BUFFER_FULL | the buffer is full |
FR_BIO_ERROR_BUFFER_TOO_SMALL | the output buffer is too small for the data |
FR_BIO_ERROR_EOF | at EOF |
int fr_bio_destructor | ( | fr_bio_t * | bio | ) |
int fr_bio_free | ( | fr_bio_t * | bio | ) |
Free this bio, and everything it calls.
We unlink the bio chain, and then free it individually. If there's an error, the bio chain is relinked. That way the error can be addressed (somehow) and this function can be called again.
Note that we do not support talloc_free() for the bio chain. Each individual bio has to be unlinked from the chain before the destructor will allow it to be freed. This functionality is by design.
We want to have an API where bios are created "bottom up", so that it is impossible for an application to create an incorrect chain. However, creating the chain bottom up means that the lower bios not parented from the higher bios, and therefore talloc_free() won't free them. As a result, we need an explicit bio_free() function.
Definition at line 113 of file base.c.
|
inlinestatic |
Read raw data from a bio.
bio | the binary IO handler |
packet_ctx | packet-specific data associated with the buffer |
buffer | where to read the data |
size | amount of data to read. |
Definition at line 141 of file base.h.
int fr_bio_shutdown | ( | fr_bio_t * | bio | ) |
Shut down a set of BIOs.
Must be called from the top-most bio.
Will shut down the bios from the bottom-up.
The shutdown function MUST be callable multiple times without breaking.
Definition at line 152 of file base.c.
int fr_bio_shutdown_intermediate | ( | fr_bio_t * | bio | ) |
Like fr_bio_shutdown(), but can be called by anyone in the chain.
Definition at line 186 of file base.c.
char const* fr_bio_strerror | ( | ssize_t | error | ) |
|
inlinestatic |
Write raw data to a bio.
bio | the binary IO handler |
packet_ctx | packet-specific data associated with the buffer |
buffer | the data to write. If NULL, will "flush" any pending data. |
size | amount of data to write. For flush, it should be SIZE_MAX |
Definition at line 164 of file base.h.