From 142890817cb670f4521ebf5883ac86dc779af2c5 Mon Sep 17 00:00:00 2001 From: lasan Date: Fri, 5 Jun 2026 23:13:52 +0530 Subject: [PATCH] removed redundant polling --- .../linux/bluetooth_classic_socket.cc | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/internal/platform/implementation/linux/bluetooth_classic_socket.cc b/internal/platform/implementation/linux/bluetooth_classic_socket.cc index 9dd48b98..f1ff28f7 100644 --- a/internal/platform/implementation/linux/bluetooth_classic_socket.cc +++ b/internal/platform/implementation/linux/bluetooth_classic_socket.cc @@ -58,9 +58,19 @@ ExceptionOr BluetoothInputStream::Read(std::int64_t size) { return Exception{Exception::kIo}; } if (pfds[0].revents & POLLIN) { - auto r = recv(fd_raw_->get(), buffer.data() + rcvd, size - rcvd, 0); - if (r < 0){ return Exception{Exception::kIo};} - rcvd += r; + while (rcvd < size) { + + auto r = recv(fd_raw_->get(), buffer.data() + rcvd, size - rcvd, 0); + if (r > 0) { + rcvd += r; + continue; + } + if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {continue;} + + LOG(ERROR) << __func__ + << ": error reading from fd: " << std::strerror(errno); + return {Exception::kIo}; + } } } @@ -89,9 +99,18 @@ Exception BluetoothOutputStream::Write(absl::string_view data) { return Exception{Exception::kIo}; } if (pfds[0].revents & POLLOUT) { - auto r = send(fd_raw_->get(), data.data() + sent, data.size(), 0); - if (r < 0){ return Exception{Exception::kIo};} - sent += r; + while (sent < data.size()) { + auto r = send(fd_raw_->get(), data.data() + sent, data.size(), 0); + if (r > 0) { + sent += r; + continue; + } + if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {continue;} + + LOG(ERROR) << __func__ + << ": error reading from fd: " << std::strerror(errno); + return {Exception::kIo}; + } } } return {Exception::kSuccess};