summaryrefslogtreecommitdiffstats
path: root/main_loop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main_loop.cpp')
-rw-r--r--main_loop.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/main_loop.cpp b/main_loop.cpp
index 62bed31..8ad030a 100644
--- a/main_loop.cpp
+++ b/main_loop.cpp
@@ -30,6 +30,8 @@ namespace wifilogd {
namespace {
constexpr auto kMainBufferSizeBytes = 128 * 1024;
+// TODO(b/32840641): Tune the sleep time.
+constexpr auto kTransientErrorSleepTimeNsec = 100 * 1000; // 100 usec
}
MainLoop::MainLoop(const std::string& socket_name)
@@ -53,8 +55,7 @@ void MainLoop::RunOnce() {
std::tie(datagram_len, err) =
os_->ReceiveDatagram(sock_fd_, input_buf.data(), input_buf.size());
if (err) {
- // TODO(b/32098735): Increment stats counter.
- // TODO(b/32481888): Improve error handling.
+ ProcessError(err);
return;
}
@@ -67,5 +68,20 @@ void MainLoop::RunOnce() {
Os::kInvalidFd);
}
+// Private methods below.
+
+void MainLoop::ProcessError(Os::Errno err) {
+ if (err == EINTR || err == ENOMEM) {
+ // TODO(b/32098735): Increment stats counter.
+ os_->Nanosleep(kTransientErrorSleepTimeNsec);
+ return;
+ }
+
+ // Any other error is unexpected, and assumed to be non-recoverable.
+ // (If, e.g., our socket is in a bad state, then we won't be able to receive
+ // any new log messages.)
+ LOG(FATAL) << "Unexpected error: " << std::strerror(err);
+}
+
} // namespace wifilogd
} // namespace android