diff --git a/src/kiss.c b/src/kiss.c index 1ac8b58..838b42f 100644 --- a/src/kiss.c +++ b/src/kiss.c @@ -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: