error handling

This commit is contained in:
folkert van heusden 2024-05-16 22:40:45 +02:00
parent a0b2392ac6
commit 12f3f59620
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1

View file

@ -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<std::mutex> 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<std::mutex> 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;