Implement patty_ax25_if_recv()

Implement patty_ax25_if_recv() as a utility function to allow one to
use when instantiating a network interface without a full network stack
This commit is contained in:
XANTRONIX Development 2020-09-22 16:33:57 -04:00 committed by XANTRONIX Industrial
parent c8c00c994c
commit b2789a4d56
2 changed files with 26 additions and 0 deletions

View file

@ -122,6 +122,8 @@ int patty_ax25_if_ready(patty_ax25_if *iface);
ssize_t patty_ax25_if_flush(patty_ax25_if *iface);
ssize_t patty_ax25_if_recv(patty_ax25_if *iface, void *buf, size_t len);
ssize_t patty_ax25_if_send(patty_ax25_if *iface,
const void *buf,
size_t len);

View file

@ -323,6 +323,30 @@ error_handle_promisc_frame:
return -1;
}
ssize_t patty_ax25_if_recv(patty_ax25_if *iface, void *buf, size_t len) {
while (!patty_ax25_if_ready(iface)) {
ssize_t drained;
if ((drained = patty_ax25_if_drain(iface, buf, len)) < 0) {
goto error_drain;
} else if (drained == 0) {
ssize_t filled;
if ((filled = patty_ax25_if_fill(iface)) < 0) {
goto error_fill;
} else if (filled == 0) {
return 0;
}
}
}
return patty_ax25_if_flush(iface);
error_drain:
error_fill:
return -1;
}
ssize_t patty_ax25_if_send(patty_ax25_if *iface,
const void *buf,
size_t len) {