[PATCH 3/4] libcamera: Detect IPC disconnection with poll
Harvey Yang
chenghaoyang at chromium.org
Fri Oct 18 09:57:36 CEST 2024
Previously an IPC disconnection will only be detected when there's an
IPC message. This CL fixes the issue with poll event: POLLHUP.
Signed-off-by: Harvey Yang <chenghaoyang at chromium.org>
Co-developed-by: Yudhistira Erlandinata <yerlandinata at chromium.org>
Signed-off-by: Yudhistira Erlandinata <yerlandinata at chromium.org>
---
include/libcamera/base/event_notifier.h | 1 +
include/libcamera/internal/ipc_unixsocket.h | 1 +
src/libcamera/base/event_dispatcher_poll.cpp | 9 +++++++++
src/libcamera/base/event_notifier.cpp | 5 +++++
src/libcamera/ipc_unixsocket.cpp | 8 ++++++++
5 files changed, 24 insertions(+)
diff --git a/include/libcamera/base/event_notifier.h b/include/libcamera/base/event_notifier.h
index 158f2d44b..9ddc1824f 100644
--- a/include/libcamera/base/event_notifier.h
+++ b/include/libcamera/base/event_notifier.h
@@ -35,6 +35,7 @@ public:
void setEnabled(bool enable);
Signal<> activated;
+ Signal<> disconnected;
protected:
void message(Message *msg) override;
diff --git a/include/libcamera/internal/ipc_unixsocket.h b/include/libcamera/internal/ipc_unixsocket.h
index a1e326b6b..535be6fbf 100644
--- a/include/libcamera/internal/ipc_unixsocket.h
+++ b/include/libcamera/internal/ipc_unixsocket.h
@@ -51,6 +51,7 @@ private:
int recvData(void *buffer, size_t length, int32_t *fds, unsigned int num);
void dataNotifier();
+ void EventNotifierDisconnected();
UniqueFD fd_;
bool headerReceived_;
diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp
index 52bfb34e2..fdfeeff06 100644
--- a/src/libcamera/base/event_dispatcher_poll.cpp
+++ b/src/libcamera/base/event_dispatcher_poll.cpp
@@ -263,6 +263,15 @@ void EventDispatcherPoll::processNotifiers(const std::vector<struct pollfd> &pol
if (!notifier)
continue;
+ if (pfd.revents & POLLHUP) {
+ LOG(Event, Debug) << "Got signal POLLHUP."
+ << " Disconnecting IPC";
+
+ notifier->disconnected.emit();
+ unregisterEventNotifier(notifier);
+ continue;
+ }
+
/*
* If the file descriptor is invalid, disable the
* notifier immediately.
diff --git a/src/libcamera/base/event_notifier.cpp b/src/libcamera/base/event_notifier.cpp
index 495c281d9..a5a583ac6 100644
--- a/src/libcamera/base/event_notifier.cpp
+++ b/src/libcamera/base/event_notifier.cpp
@@ -131,6 +131,11 @@ void EventNotifier::setEnabled(bool enable)
* parameter.
*/
+/**
+ * \var EventNotifier::disconnected
+ * \brief Signal emitted when the file descriptor is disconnected
+ */
+
void EventNotifier::message(Message *msg)
{
if (msg->type() == Message::ThreadMoveMessage) {
diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp
index 3d0248857..609549b6f 100644
--- a/src/libcamera/ipc_unixsocket.cpp
+++ b/src/libcamera/ipc_unixsocket.cpp
@@ -133,9 +133,17 @@ int IPCUnixSocket::bind(UniqueFD fd)
notifier_ = new EventNotifier(fd_.get(), EventNotifier::Read);
notifier_->activated.connect(this, &IPCUnixSocket::dataNotifier);
+ notifier_->disconnected.connect(
+ this, &IPCUnixSocket::EventNotifierDisconnected);
+
return 0;
}
+void IPCUnixSocket::EventNotifierDisconnected()
+{
+ disconnected.emit();
+}
+
/**
* \brief Close the IPC channel
*
--
2.47.0.rc1.288.g06298d1525-goog
More information about the libcamera-devel
mailing list