From 9d9c4045e20b603dce6060030a168fde6ed51139 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max.kellermann@gmail.com>
Date: Mon, 29 Jul 2024 15:28:06 +0200
Subject: [PATCH] output/alsa: move redundant code to UnregisterSockets()

---
 src/output/plugins/AlsaOutputPlugin.cxx | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx
index dbc43091d..c3c929d46 100644
--- a/src/output/plugins/AlsaOutputPlugin.cxx
+++ b/src/output/plugins/AlsaOutputPlugin.cxx
@@ -258,6 +258,11 @@ public:
 	}
 
 private:
+	void UnregisterSockets() noexcept {
+		MultiSocketMonitor::Reset();
+		defer_invalidate_sockets.Cancel();
+	}
+
 	std::map<std::string, std::string, std::less<>> GetAttributes() const noexcept override;
 	void SetAttribute(std::string &&name, std::string &&value) override;
 
@@ -1103,8 +1108,7 @@ AlsaOutput::CancelInternal() noexcept
 	active = false;
 	waiting = false;
 
-	MultiSocketMonitor::Reset();
-	defer_invalidate_sockets.Cancel();
+	UnregisterSockets();
 	silence_timer.Cancel();
 }
 
@@ -1159,8 +1163,7 @@ AlsaOutput::Close() noexcept
 {
 	/* make sure the I/O thread isn't inside DispatchSockets() */
 	BlockingCall(GetEventLoop(), [this](){
-		MultiSocketMonitor::Reset();
-		defer_invalidate_sockets.Cancel();
+		UnregisterSockets();
 		silence_timer.Cancel();
 	});
 
@@ -1317,8 +1320,7 @@ try {
 			   event (but after setting the "waiting"
 			   flag) */
 			if (!CopyRingToPeriodBuffer()) {
-				MultiSocketMonitor::Reset();
-				defer_invalidate_sockets.Cancel();
+				UnregisterSockets();
 
 				/* just in case Play() doesn't get
 				   called soon enough, schedule a