26RCSID(
"$Id: 916fdd211f66c561813dbf2d1590edcefc745ac5 $")
28#include <freeradius-devel/util/strerror.h>
40 for (total = 0; total < outlen; ) {
42 r = read(fd, p + total, outlen - total);
45 if (r == 0)
return total;
52#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
75 void *
out,
size_t outlen,
size_t *leftover,
bool *want_more)
81 size_t offset = *leftover;
86 if (outlen <=
sizeof(hdr)) {
96 if (offset <
sizeof(hdr)) {
107 if (offset <
sizeof(hdr))
return 0;
114 memcpy(&hdr,
buffer,
sizeof(hdr));
115 data_len = ntohl(hdr.
length);
120 if ((
sizeof(hdr) + data_len) > outlen) {
128 outlen =
sizeof(hdr) + data_len;
131 if (r <= 0)
return r;
135 if (offset == outlen) {
137 *pconduit = ntohs(hdr.
conduit);
155 r =
lo_read(fd, &hdr,
sizeof(hdr));
156 if (r <= 0)
return r;
161 *pconduit = ntohs(hdr.
conduit);
162 data_len = ntohl(hdr.
length);
163 if (data_len == 0)
return 0;
164 if (data_len > UINT32_MAX) data_len = UINT32_MAX;
167 fprintf(stderr,
"CONDUIT R %zu length %zu\n", *pconduit, data_len);
174 if (outlen > data_len) outlen = data_len;
177 if (r <= 0)
return r;
183 while (data_len > outlen) {
187 discard = data_len - outlen;
188 if (discard >
sizeof(junk)) discard =
sizeof(junk);
190 r =
lo_read(fd, junk, discard);
208 r = write(fd,
buffer, total);
215 if (errno == EINTR)
continue;
233 if (outlen > UINT32_MAX) {
234 fr_strerror_printf(
"Data to write to conduit (%zu bytes) exceeds maximum length", outlen);
241 if (!outlen)
return 0;
245 .length = htonl(outlen),
249 fprintf(stderr,
"CONDUIT W %zu length %zu\n", conduit, outlen);
255 r =
lo_write(fd, &hdr,
sizeof(hdr));
256 if (r <= 0)
return r;
262 if (r <= 0)
return r;
static int const char char buffer[256]
static ssize_t lo_write(int fd, void const *out, size_t outlen)
ssize_t fr_conduit_write(int fd, fr_conduit_type_t conduit, void const *out, size_t outlen)
static ssize_t lo_read(int fd, void *out, size_t outlen)
ssize_t fr_conduit_read_async(int fd, fr_conduit_type_t *pconduit, void *out, size_t outlen, size_t *leftover, bool *want_more)
ssize_t fr_conduit_read(int fd, fr_conduit_type_t *pconduit, void *out, size_t outlen)
API to provide distinct communication conduits for the radmin protocol.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
static size_t char ** out