The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
bio_priv.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: 3e12ea128dad61c62aac83b53913bc03a7be0bbb $
20 * @file lib/bio/bio_priv.h
21 * @brief Binary IO private functions
22 *
23 * Create abstract binary input / output buffers.
24 *
25 * @copyright 2024 Network RADIUS SAS (legal@networkradius.com)
26 */
27RCSIDH(lib_bio_bio_priv_h, "$Id: 3e12ea128dad61c62aac83b53913bc03a7be0bbb $")
28
29#define _BIO_PRIVATE 1
30#include <freeradius-devel/bio/base.h>
31
33
46
47/** Common elements at the start of each private #fr_bio_t
48 *
49 */
50#define FR_BIO_COMMON \
51 fr_bio_t bio; \
52 fr_bio_cb_funcs_t cb; \
53 fr_bio_priv_callback_t priv_cb
54
58
59/** Define a common destructor pattern.
60 *
61 * Ensure that talloc_free() is safe no matter what. The caller can free any BIO at any time. If that
62 * happens, then the entire chain is shut down. On successful shutdown, this BIO is removed from the chain.
63 */
64#define FR_BIO_DESTRUCTOR_COMMON \
65do { \
66 if (my->priv_cb.shutdown) { \
67 int rcode; \
68 rcode = fr_bio_shutdown(&my->bio); \
69 if (rcode < 0) return rcode; \
70 } \
71 if (fr_bio_prev(&my->bio) || fr_bio_next(&my->bio)) \
72 fr_bio_unchain(&my->bio); \
73} while (0)
74
75
76ssize_t fr_bio_next_read(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size);
77
78ssize_t fr_bio_next_write(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size);
79
80/** Chain one bio after another.
81 *
82 * @todo - this likely needs to be public
83 */
84static inline void CC_HINT(nonnull) fr_bio_chain(fr_bio_t *first, fr_bio_t *second)
85{
86 fr_assert(first->entry.prev == NULL);
87 fr_assert(first->entry.next == NULL);
88
89 fr_assert(second->entry.prev == NULL);
90
91 first->entry.next = &second->entry;
92 second->entry.prev = &first->entry;
93}
94
95/** Remove a bio from a chain
96 *
97 * And reset prev/next ptrs to NULL.
98 *
99 * @todo - this likely needs to be public
100 */
101static inline void CC_HINT(nonnull) fr_bio_unchain(fr_bio_t *bio)
102{
103 fr_bio_t *prev = fr_bio_prev(bio);
104 fr_bio_t *next = fr_bio_next(bio);
105
106 fr_assert(prev || next);
107
108 if (prev) prev->entry.next = bio->entry.next;
109
110 if (next) next->entry.prev = bio->entry.prev;
111
112 bio->entry.prev = bio->entry.next = NULL;
113}
114
115void fr_bio_eof(fr_bio_t *bio) CC_HINT(nonnull);
116
117int fr_bio_write_blocked(fr_bio_t *bio) CC_HINT(nonnull);
static int const char char buffer[256]
Definition acutest.h:576
static fr_bio_t * fr_bio_prev(fr_bio_t *bio)
Definition base.h:122
fr_dlist_t _CONST entry
in the linked list of multiple bios
Definition base.h:119
static fr_bio_t * fr_bio_next(fr_bio_t *bio)
Definition base.h:131
int(* fr_bio_io_t)(fr_bio_t *bio)
Definition base.h:84
void(* fr_bio_callback_t)(fr_bio_t *bio)
Definition base.h:86
fr_bio_io_t read_resume
"unblocked" is too similar to "blocked"
Definition bio_priv.h:43
fr_bio_io_t write_blocked
Definition bio_priv.h:41
fr_bio_io_t connected
Definition bio_priv.h:35
fr_bio_callback_t failed
Definition bio_priv.h:38
static void fr_bio_chain(fr_bio_t *first, fr_bio_t *second)
Chain one bio after another.
Definition bio_priv.h:84
int fr_bio_write_blocked(fr_bio_t *bio)
Internal BIO function to tell all BIOs that it's blocked.
Definition base.c:261
fr_bio_io_t shutdown
Definition bio_priv.h:36
fr_bio_io_t write_resume
Definition bio_priv.h:44
fr_bio_io_t read_blocked
Definition bio_priv.h:40
void fr_bio_eof(fr_bio_t *bio)
Internal BIO function to run EOF callbacks.
Definition base.c:212
ssize_t fr_bio_next_read(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
Internal bio function which just reads from the "next" bio.
Definition base.c:49
static void fr_bio_unchain(fr_bio_t *bio)
Remove a bio from a chain.
Definition bio_priv.h:101
ssize_t fr_bio_next_write(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
Internal bio function which just writes to the "next" bio.
Definition base.c:64
#define RCSIDH(h, id)
Definition build.h:486
fr_dlist_t * next
Definition dlist.h:43
fr_dlist_t * prev
Definition dlist.h:42
long int ssize_t
#define fr_assert(_expr)
Definition rad_assert.h:38
int nonnull(2, 5))