patchpanel: system-proxy: better error logs for Socket
This patch fixes several logging issues with the use of patchpanel
Socket class.
When socket.cc itself is in charge of logging an error, any context
about the call site is lost. This makes debugging and analyzing issues
from logs much harder than logging the error at the call site. See
b/195507716 for an example.
To fix this, errors are now logged at call sites in patchpanel and
system-proxy.
Additionally, some errors for some Socket calls were until ignored or
incorrectly processed. For instance SendTo() errors in system-proxy were
always ignored since SendTo() < 0 implies SendTo == true.
BUG=b:195507716
TEST= - FEATURES="test" emerge-trogdor system-proxy
- FEATURES="test" emerge-trogdor patchpanel
- flashed DUT, started user session, observed patchapnel
multicast_forwader.cc logs and adb_proxy.cc logs.
Change-Id: I5a472b43c4cb47d2b13d2b7749c857c4865a3ea4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/3105860
Reviewed-by: Andreea-Elena Costinas <acostinas@google.com>
Reviewed-by: Garrick Evans <garrick@chromium.org>
Commit-Queue: Hugo Benichi <hugobenichi@google.com>
Tested-by: Hugo Benichi <hugobenichi@google.com>
diff --git a/patchpanel/socket.h b/patchpanel/socket.h
index 2fd69c3..d5e36cf 100644
--- a/patchpanel/socket.h
+++ b/patchpanel/socket.h
@@ -43,6 +43,8 @@
struct sockaddr* addr = nullptr,
socklen_t addrlen = 0);
+ bool is_valid() const { return fd_.is_valid(); }
+
int fd() const { return fd_.get(); }
// Releases the underlying fd rendering the Socket instance invalid.