The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
BIO abstractions for file descriptors. More...
#include <freeradius-devel/bio/fd_priv.h>
#include <freeradius-devel/bio/null.h>
#include "fd_read.h"
#include "fd_write.h"
#include "fd_errno.h"
Go to the source code of this file.
Macros | |
#define | ADDR_INIT |
#define | flag_blocked read_blocked |
#define | SOL_IP IPPROTO_IP |
Functions | |
int | fr_bio_fd_accept (TALLOC_CTX *ctx, fr_bio_t **out_p, fr_bio_t *bio) |
Alternative to calling fr_bio_read() on new socket. More... | |
fr_bio_t * | fr_bio_fd_alloc (TALLOC_CTX *ctx, fr_bio_fd_config_t const *cfg, size_t offset) |
Allocate a FD bio. More... | |
int | fr_bio_fd_close (fr_bio_t *bio) |
Close the FD, but leave the bio allocated and alive. More... | |
int | fr_bio_fd_connect_full (fr_bio_t *bio, fr_event_list_t *el, fr_bio_callback_t connected_cb, fr_bio_callback_t error_cb, fr_time_delta_t *timeout, fr_bio_callback_t timeout_cb) |
Finalize a connect() More... | |
static int | fr_bio_fd_destructor (fr_bio_fd_t *my) |
static void | fr_bio_fd_el_connect (NDEBUG_UNUSED fr_event_list_t *el, NDEBUG_UNUSED int fd, NDEBUG_UNUSED int flags, void *uctx) |
Connect callback for when the socket is writable. More... | |
static void | fr_bio_fd_el_error (UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED int flags, int fd_errno, void *uctx) |
FD error when trying to connect, give up on the BIO. More... | |
static void | fr_bio_fd_el_timeout (UNUSED fr_event_list_t *el, UNUSED fr_time_t now, void *uctx) |
We have a timeout on the conenction. More... | |
static int | fr_bio_fd_eof (fr_bio_t *bio) |
fr_bio_fd_info_t const * | fr_bio_fd_info (fr_bio_t *bio) |
Returns a pointer to the bio-specific information. More... | |
int | fr_bio_fd_init_common (fr_bio_fd_t *my) |
int | fr_bio_fd_init_connected (fr_bio_fd_t *my) |
static int | fr_bio_fd_init_file (fr_bio_fd_t *my) |
Files are a special case of connected sockets. More... | |
int | fr_bio_fd_init_listen (fr_bio_fd_t *my) |
static ssize_t | fr_bio_fd_read_accept (fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size) |
Return an fd on read() More... | |
static ssize_t | fr_bio_fd_read_connected_datagram (fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size) |
Connected datagram read. More... | |
static ssize_t | fr_bio_fd_read_discard (fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size) |
Discard all reads from a UDP socket. More... | |
static ssize_t | fr_bio_fd_read_stream (fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size) |
Stream read. More... | |
static ssize_t | fr_bio_fd_recvfrom (fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size) |
Read from a UDP socket where we know our IP. More... | |
static ssize_t | fr_bio_fd_sendto (fr_bio_t *bio, void *packet_ctx, const void *buffer, size_t size) |
Write to a UDP socket where we know our IP. More... | |
static void | fr_bio_fd_set_open (fr_bio_fd_t *my) |
int | fr_bio_fd_socket_name (fr_bio_fd_t *my) |
static ssize_t | fr_bio_fd_try_connect (fr_bio_fd_t *my) |
Try to connect(). More... | |
static ssize_t | fr_bio_fd_write (fr_bio_t *bio, UNUSED void *packet_ctx, const void *buffer, size_t size) |
Write to fd. More... | |
int | fr_bio_fd_write_only (fr_bio_t *bio) |
Mark up a bio as write-only. More... | |
static int | fr_bio_fd_write_resume (fr_bio_t *bio) |
int | fr_filename_to_sockaddr (struct sockaddr_un *sun, socklen_t *sunlen, char const *filename) |
BIO abstractions for file descriptors.
Definition in file fd.c.
#define ADDR_INIT |
#define flag_blocked read_blocked |
Alternative to calling fr_bio_read() on new socket.
Definition at line 1388 of file fd.c.
fr_bio_t* fr_bio_fd_alloc | ( | TALLOC_CTX * | ctx, |
fr_bio_fd_config_t const * | cfg, | ||
size_t | offset | ||
) |
Allocate a FD bio.
The caller is responsible for tracking the FD, and all associated management of it. The bio API is intended to be simple, and does not provide wrapper functions for various ioctls. The caller should instead do that work.
Once the FD is give to the bio, its lifetime is "owned" by the bio. Calling talloc_free(bio) will close the FD.
The caller can still manage the FD for being readable / writeable. However, the caller should not call this bio directly (unless it is the only one). Instead, the caller should read from / write to the previous bio which will then eventually call this one.
Before updating any event handler readable / writeable callbacks, the caller should check fr_bio_fd_at_eof(). If true, then the handlers should not be inserted. The previous bios should still be called to process any pending data, until they return EOF.
The main purpose of an FD bio is to wrap the FD in a bio container. That, and handling retries on read / write, along with returning EOF as an error instead of zero.
Note that the read / write functions can return partial data. It is the callers responsibility to ensure that any writes continue from where they left off (otherwise dat awill be missing). And any partial reads should go to a memory bio.
If a read returns EOF, then the FD remains open until talloc_free(bio) or fr_bio_fd_close() is called.
ctx | the talloc ctx |
cfg | structure holding configuration information |
offset | only for unconnected datagram sockets, where fr_bio_fd_packet_ctx_t is stored |
Definition at line 1012 of file fd.c.
int fr_bio_fd_close | ( | fr_bio_t * | bio | ) |
int fr_bio_fd_connect_full | ( | fr_bio_t * | bio, |
fr_event_list_t * | el, | ||
fr_bio_callback_t | connected_cb, | ||
fr_bio_callback_t | error_cb, | ||
fr_time_delta_t * | timeout, | ||
fr_bio_callback_t | timeout_cb | ||
) |
Finalize a connect()
connect() said "come back when the socket is writeable". It's now writeable, so we check if there was a connection error.
bio | the binary IO handler |
el | the event list |
connected_cb | callback to run when the BIO is connected |
error_cb | callback to run when the FD has an error |
timeout | when to time out the connect() attempt |
timeout_cb | to call when the timeout runs. |
Definition at line 1235 of file fd.c.
|
static |
|
static |
|
static |
|
static |
|
static |
fr_bio_fd_info_t const* fr_bio_fd_info | ( | fr_bio_t * | bio | ) |
int fr_bio_fd_init_common | ( | fr_bio_fd_t * | my | ) |
int fr_bio_fd_init_connected | ( | fr_bio_fd_t * | my | ) |
|
static |
int fr_bio_fd_init_listen | ( | fr_bio_fd_t * | my | ) |
|
static |
Connected datagram read.
The difference between this and stream protocols is that for datagrams. a read of zero means "no packets", where a read of zero on a steam socket means "EOF".
Connected sockets do not update per-packet contexts.
Definition at line 168 of file fd.c.
|
static |
Stream read.
Stream sockets return 0 at EOF. However, we want to distinguish that from the case of datagram sockets, which return 0 when there's no data. So we return 0 to the caller for "no data", but also call the EOF function to tell all of the related BIOs that we're at EOF.
Definition at line 143 of file fd.c.
|
static |
int fr_bio_fd_socket_name | ( | fr_bio_fd_t * | my | ) |
|
static |
Try to connect().
If connect is blocking, we either succeed or error immediately. Otherwise, the caller has to select the socket for writeability, and then call fr_bio_fd_connect() as soon as the socket is writeable.
Definition at line 679 of file fd.c.
int fr_bio_fd_write_only | ( | fr_bio_t * | bio | ) |
|
static |