26 RCSID(
"$Id: c53a909e894457a53ca9bbc1d177f4e996a82d04 $")
28 #include <freeradius-devel/util/strerror.h>
41 for (total = 0; total < outlen; ) {
43 r = read(fd, p + total, outlen - total);
46 if (r == 0)
return total;
53 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
76 void *
out,
size_t outlen,
size_t *leftover,
bool *want_more)
82 size_t offset = *leftover;
87 if (outlen <=
sizeof(hdr)) {
97 if (offset <
sizeof(hdr)) {
108 if (offset <
sizeof(hdr))
return 0;
115 memcpy(&hdr,
buffer,
sizeof(hdr));
116 data_len = ntohl(hdr.
length);
121 if ((
sizeof(hdr) + data_len) > outlen) {
129 outlen =
sizeof(hdr) + data_len;
132 if (r <= 0)
return r;
136 if (offset == outlen) {
138 *pconduit = ntohs(hdr.
conduit);
156 r =
lo_read(fd, &hdr,
sizeof(hdr));
157 if (r <= 0)
return r;
162 *pconduit = ntohs(hdr.
conduit);
163 data_len = ntohl(hdr.
length);
164 if (data_len == 0)
return 0;
165 if (data_len > UINT32_MAX) data_len = UINT32_MAX;
168 fprintf(stderr,
"CONDUIT R %zu length %zu\n", *pconduit, data_len);
175 if (outlen > data_len) outlen = data_len;
178 if (r <= 0)
return r;
184 while (data_len > outlen) {
188 discard = data_len - outlen;
189 if (discard >
sizeof(junk)) discard =
sizeof(junk);
191 r =
lo_read(fd, junk, discard);
209 r = write(fd,
buffer, total);
216 if (errno == EINTR)
continue;
234 if (outlen > UINT32_MAX) {
235 fr_strerror_printf(
"Data to write to conduit (%zu bytes) exceeds maximum length", outlen);
242 if (!outlen)
return 0;
246 .length = htonl(outlen),
250 fprintf(stderr,
"CONDUIT W %zu length %zu\n", conduit, outlen);
256 r =
lo_write(fd, &hdr,
sizeof(hdr));
257 if (r <= 0)
return r;
263 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