The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
fd_read.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: f04636939d9f9077bcafa0d15d5bf20809eaead5 $
20 * @file lib/bio/fd_read.h
21 * @brief Common finalization code for the FD bio read functions.
22 *
23 * @copyright 2024 Network RADIUS SAS (legal@networkradius.com)
24 */
25RCSIDH(lib_bio_fd_read_h, "$Id: f04636939d9f9077bcafa0d15d5bf20809eaead5 $")
26
27#include <freeradius-devel/bio/fd_errno.h>
28
29/** Common finalization code for the read functions.
30 *
31 * The caller must not pass rcode==0. A read of 0 means different things for datagram and stream sockets, so
32 * each caller deals with it before getting here.
33 *
34 * @todo - do we want the callbacks to notify the _previous_ BIO in the chain? That way the top-level
35 * BIO can notify the application.
36 *
37 * @param my the FD bio.
38 * @param[in,out] rcode_p in: the read() return code. out: what to return to the application.
39 * @param[in,out] tries_p how many times we have retried on EINTR.
40 * @return
41 * - false return *rcode_p to the application.
42 * - true the read was interrupted, redo it.
43 */
44static inline CC_HINT(always_inline) bool fr_bio_fd_read_retry(fr_bio_fd_t *my, ssize_t *rcode_p, int *tries_p)
45{
46 if (*rcode_p > 0) {
47 /*
48 * We weren't blocked, so we're still not blocked.
49 */
50 if (!my->info.read_blocked) return false;
51
52 /*
53 * We were blocked. Since we just read data, we're now unblocked.
54 */
55 my->info.read_blocked = false;
56
57 /*
58 * Call the "resume" function when we transition to being unblocked.
59 */
60 if (my->cb.read_resume) {
61 int error;
62
63 error = my->cb.read_resume((fr_bio_t *) my);
64 if (error < 0) *rcode_p = error;
65 }
66
67 return false;
68 }
69
70 fr_assert(*rcode_p < 0);
71
72 return fr_bio_fd_errno_retry(my, rcode_p, tries_p, false);
73}
#define RCSIDH(h, id)
Definition build.h:561
bool read_blocked
did we block on read?
Definition fd.h:134
static bool fr_bio_fd_errno_retry(fr_bio_fd_t *my, ssize_t *rcode_p, int *tries_p, bool is_write)
Turn a failed read / write into a bio return code.
Definition fd_errno.h:41
fr_bio_fd_info_t info
Definition fd_priv.h:39
Our FD bio structure.
Definition fd_priv.h:35
static bool fr_bio_fd_read_retry(fr_bio_fd_t *my, ssize_t *rcode_p, int *tries_p)
Common finalization code for the read functions.
Definition fd_read.h:44
long int ssize_t
#define fr_assert(_expr)
Definition rad_assert.h:37