diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2024-10-16 12:42:30 +0200 |
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2024-10-16 13:30:25 +0200 |
| commit | 17f512c10dabfd895172926e7f99b63b02fe3be3 (patch) | |
| tree | 44ecc72fe8261563bb0e0f15b38e86e79485088b /lib/ptm_lib.c | |
| parent | a67df2a17f69a4e847bad84568f13e1d0fccd02d (diff) | |
lib: fix invalid use of errno in PTM
errno is only valid if there was an actual error. A zero return value
isn't an error, it's either EOF or an empty datagram depending on
context. Fix the logic.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/ptm_lib.c')
| -rw-r--r-- | lib/ptm_lib.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/lib/ptm_lib.c b/lib/ptm_lib.c index ac800be0a5..737c60775f 100644 --- a/lib/ptm_lib.c +++ b/lib/ptm_lib.c @@ -308,22 +308,18 @@ static int _ptm_lib_read_ptm_socket(int fd, char *buf, int len) while (bytes_read != len) { rc = recv(fd, (void *)(buf + bytes_read), (len - bytes_read), MSG_DONTWAIT); - if (rc <= 0) { - if (errno && (errno != EAGAIN) - && (errno != EWOULDBLOCK)) { - ERRLOG("fatal recv error(%s), closing connection, rc %d\n", - strerror(errno), rc); - return (rc); - } else { - if (retries++ < 2) { - usleep(10000); - continue; - } - DLOG("max retries - recv error(%d - %s) bytes read %d (%d)\n", - errno, strerror(errno), bytes_read, len); - return (bytes_read); + if (rc < 0 && (errno != EAGAIN) && (errno != EWOULDBLOCK)) { + ERRLOG("fatal recv error(%s), closing connection, rc %d\n", strerror(errno), + rc); + return (rc); + } else if (rc <= 0) { + if (retries++ < 2) { + usleep(10000); + continue; } - break; + DLOG("max retries - recv error(%d - %s) bytes read %d (%d)\n", errno, + strerror(errno), bytes_read, len); + return (bytes_read); } else { bytes_read += rc; } |
