26 RCSID(
"$Id: 421abac07e9966c8398f841ddf649143a271182c $")
28 #include <freeradius-devel/util/strerror.h>
41 for (total = 0; total < outlen; total += r) {
42 r = read(fd, p + total, outlen - total);
44 if (r == 0)
return total;
51 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
73 void *
out,
size_t outlen,
size_t *leftover,
bool *want_more)
79 size_t offset = *leftover;
84 if (outlen <=
sizeof(hdr)) {
94 if (offset <
sizeof(hdr)) {
105 if (offset <
sizeof(hdr))
return 0;
112 memcpy(&hdr,
buffer,
sizeof(hdr));
113 data_len = ntohl(hdr.
length);
118 if ((
sizeof(hdr) + data_len) > outlen) {
126 outlen =
sizeof(hdr) + data_len;
129 if (r <= 0)
return r;
133 if (offset == outlen) {
135 *pconduit = ntohs(hdr.
conduit);
153 r =
lo_read(fd, &hdr,
sizeof(hdr));
154 if (r <= 0)
return r;
159 *pconduit = ntohs(hdr.
conduit);
160 data_len = ntohl(hdr.
length);
161 if (data_len == 0)
return 0;
162 if (data_len > UINT32_MAX) data_len = UINT32_MAX;
165 fprintf(stderr,
"CONDUIT R %zu length %zu\n", *pconduit, data_len);
172 if (outlen > data_len) outlen = data_len;
175 if (r <= 0)
return r;
181 while (data_len > outlen) {
185 discard = data_len - outlen;
186 if (discard >
sizeof(junk)) discard =
sizeof(junk);
188 r =
lo_read(fd, junk, discard);
206 r = write(fd,
buffer, total);
213 if (errno == EINTR)
continue;
231 if (outlen > UINT32_MAX) {
232 fr_strerror_printf(
"Data to write to conduit (%zu bytes) exceeds maximum length", outlen);
239 if (!outlen)
return 0;
243 .length = htonl(outlen),
247 fprintf(stderr,
"CONDUIT W %zu length %zu\n", conduit, outlen);
253 r =
lo_write(fd, &hdr,
sizeof(hdr));
254 if (r <= 0)
return r;
260 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