From 45f465b92d54d4ce1459abb4bcf5968091fda34e Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Mon, 29 Jan 2024 14:52:03 -0500 Subject: [PATCH] handle EWOULDBLOCK. Helps with #5286 --- src/listen/radius/proto_radius_tcp.c | 17 +++++++++++++++++ src/listen/tacacs/proto_tacacs_tcp.c | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/listen/radius/proto_radius_tcp.c b/src/listen/radius/proto_radius_tcp.c index 46f015714701..5d24641df424 100644 --- a/src/listen/radius/proto_radius_tcp.c +++ b/src/listen/radius/proto_radius_tcp.c @@ -113,6 +113,23 @@ static ssize_t mod_read(fr_listen_t *li, UNUSED void **packet_ctx, fr_time_t *re */ data_size = read(thread->sockfd, buffer + *leftover, buffer_len - *leftover); if (data_size < 0) { + switch (errno) { +#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN) + case EWOULDBLOCK: +#endif + case EAGAIN: + /* + * We didn't read any data leave the buffers alone. + * + * i.e. if we had a partial packet in the buffer and we didn't read any data, + * then the partial packet is still left in the buffer. + */ + return 0; + + default: + break; + } + PDEBUG2("proto_radius_tcp got read error %zd", data_size); return data_size; } diff --git a/src/listen/tacacs/proto_tacacs_tcp.c b/src/listen/tacacs/proto_tacacs_tcp.c index 2c2df97beeac..19d58c3892d8 100644 --- a/src/listen/tacacs/proto_tacacs_tcp.c +++ b/src/listen/tacacs/proto_tacacs_tcp.c @@ -135,6 +135,23 @@ static ssize_t mod_read(fr_listen_t *li, UNUSED void **packet_ctx, fr_time_t *re */ data_size = read(thread->sockfd, buffer + (*leftover), buffer_len - (*leftover)); if (data_size < 0) { + switch (errno) { +#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN) + case EWOULDBLOCK: +#endif + case EAGAIN: + /* + * We didn't read any data leave the buffers alone. + * + * i.e. if we had a partial packet in the buffer and we didn't read any data, + * then the partial packet is still left in the buffer. + */ + return 0; + + default: + break; + } + ERROR("proto_tacacs_tcp got read error (%zd) - %s", data_size, fr_syserror(errno)); return data_size; }