Fix patty_kiss_tnc_recv() issues

Fix patty_kiss_tnc_recv() issues with small buffers (~330 bytes) by
more properly detecting EOF being the condition at which the current
decoder offset in the buffer is equal to the last buffer read size; the
offset can never be the number of bytes read, and the initial read
length is -1, so early EOF conditions are avoided
This commit is contained in:
XANTRONIX Development 2020-05-29 00:11:54 -04:00 committed by XANTRONIX Industrial
parent 2e0adee54e
commit d266058ad4

View file

@ -27,10 +27,7 @@ struct _patty_kiss_tnc {
offset,
dropped;
ssize_t readlen,
left;
int eof;
ssize_t readlen;
};
patty_kiss_tnc *patty_kiss_tnc_open_fd(int fd) {
@ -45,12 +42,10 @@ patty_kiss_tnc *patty_kiss_tnc_open_fd(int fd) {
}
tnc->fd = fd;
tnc->bufsz = PATTY_KISS_BUFSZ;
tnc->offset = 0;
tnc->dropped = 0;
tnc->readlen = 0;
tnc->left = 0;
tnc->eof = 0;
tnc->bufsz = PATTY_KISS_BUFSZ;
tnc->offset = 0;
tnc->dropped = 0;
tnc->readlen = -1;
return tnc;
@ -93,10 +88,8 @@ void patty_kiss_tnc_close(patty_kiss_tnc *tnc) {
}
static void tnc_drop(patty_kiss_tnc *tnc) {
tnc->offset = 0;
tnc->readlen = 0;
tnc->left = 0;
tnc->eof = 0;
tnc->offset = 0;
tnc->readlen = -1;
tnc->dropped++;
}
@ -113,7 +106,7 @@ ssize_t patty_kiss_tnc_recv(patty_kiss_tnc *tnc,
enum kiss_flags flags = KISS_NONE;
if (tnc->eof) {
if (tnc->offset == tnc->readlen) {
return 0;
}
@ -139,8 +132,6 @@ ssize_t patty_kiss_tnc_recv(patty_kiss_tnc *tnc,
goto done;
}
tnc->left = tnc->readlen;
}
c = ((uint8_t *)tnc->buf)[tnc->offset++];
@ -220,12 +211,6 @@ done:
return 0;
}
tnc->left -= r;
if (tnc->readlen < tnc->bufsz && tnc->left == 0) {
tnc->eof = 1;
}
return (ssize_t)w;
error_io: