From 12f3f59620b15fd525e7a2dc3bd851ba48a430e8 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Thu, 16 May 2024 22:40:45 +0200 Subject: [PATCH] error handling --- comm_tcp_socket.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/comm_tcp_socket.cpp b/comm_tcp_socket.cpp index ca6ed66..1ec1afb 100644 --- a/comm_tcp_socket.cpp +++ b/comm_tcp_socket.cpp @@ -114,7 +114,11 @@ uint8_t comm_tcp_socket::get_byte() } uint8_t c = 0; - read(use_fd, &c, 1); // TODO error checking + if (read(use_fd, &c, 1) <= 0) { + std::unique_lock lck(cfd_lock); + close(cfd); + cfd = INVALID_SOCKET; + } return c; } @@ -127,8 +131,11 @@ void comm_tcp_socket::send_data(const uint8_t *const in, const size_t n) while(len > 0) { std::unique_lock lck(cfd_lock); int rc = write(cfd, p, len); - if (rc <= 0) // TODO error checking + if (rc <= 0) { // TODO error checking + close(cfd); + cfd = INVALID_SOCKET; break; + } p += rc; len -= rc;