From patchwork Fri Oct 18 07:57:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 21668 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BC5ACC32FC for ; Fri, 18 Oct 2024 08:00:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D29D065395; Fri, 18 Oct 2024 09:59:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="me2Y4Pmw"; dkim-atps=neutral Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EB5636538B for ; Fri, 18 Oct 2024 09:59:54 +0200 (CEST) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-71e5a1c9071so1404981b3a.0 for ; Fri, 18 Oct 2024 00:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729238393; x=1729843193; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yci7oVr/bgnEF/hXg58IG8sMXvpOTd+bGIWcstS8MbU=; b=me2Y4PmwK2YKI7GZzzvIcPrXzqOImo+7jTBr3xNb7izRyp4hIrf+hw1UFgJ6USHBoz npak9GIM5M/FMPBlIfCN6zl73pN9tGoJUDy3vPe5Z7FjnLOuCxKekT1Lr4NgyoPRIL6A 9J5n9WnusUdTRurZEipxB/wPsGkXPGSc26xcg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729238393; x=1729843193; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yci7oVr/bgnEF/hXg58IG8sMXvpOTd+bGIWcstS8MbU=; b=aJvVf8J5/DicbXydpo6alD+ejDMgPFo2tr8I+oIMN3Bf3p4Ldh0zIB7paX82TWyrF2 xHYbJOpW6ircxMzVR3cUs2p4ZheOITc0VXYtD8aBXuaFmFTPk5v/q1Px9HhliuXYN+OK X64fSrdHiDFjhNIQe9eTPiLxyuwHbeH22cN78hQiDxvT1mzrgvxBhIoMhSuZeWgLf9cQ lf1niy0FkAy/6WP7EgEXHWXQMssaL+OeeuLXnbkE5HXwKV0kEG9x3wwUdrsM0FPvp6CD NjfxOXDtgM6iokaOQMr+90YguzYJDVT18xw7i2TFQoNfGr51sEH2LCq8NIsp0oDzzjlx BP3Q== X-Gm-Message-State: AOJu0YzDyK1OBXAoRqGH4p2CGAshaginAHwdU6KcEPu+ZtoHAomrPUKr oJmXhsxNQWovErerajjKFMYJ6/8oXObXlIsA0SrEbjxHt9AN9lqBXEgj0qIbZ4APLaK6tFHru5c = X-Google-Smtp-Source: AGHT+IGvoLanVK8O8Qe7p6il9oCWUUvslUlkoHNJzXqF3qbhoNoId7vjvz1uPdAKJkxm2uujl/Rrcw== X-Received: by 2002:a05:6a00:896:b0:71e:7174:3ae with SMTP id d2e1a72fcca58-71ea320dfa0mr2290324b3a.11.1729238393114; Fri, 18 Oct 2024 00:59:53 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (27.247.221.35.bc.googleusercontent.com. [35.221.247.27]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ea345b0c3sm901274b3a.172.2024.10.18.00.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 00:59:52 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang , Yudhistira Erlandinata Subject: [PATCH 3/4] libcamera: Detect IPC disconnection with poll Date: Fri, 18 Oct 2024 07:57:36 +0000 Message-ID: <20241018075942.1150378-4-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241018075942.1150378-1-chenghaoyang@chromium.org> References: <20241018075942.1150378-1-chenghaoyang@chromium.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Co-developed-by: Yudhistira Erlandinata Signed-off-by: Yudhistira Erlandinata --- 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 &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 *