From ff6e434caf6bd3be2aaa0b639c5f81678437a55e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 15 Oct 2020 16:52:36 +0200 Subject: [PATCH] event/SocketEvent: rename Steal() to ReleaseSocket() --- src/db/plugins/ProxyDatabasePlugin.cxx | 4 ++-- src/event/SocketEvent.cxx | 10 ---------- src/event/SocketEvent.hxx | 11 +++++------ src/lib/nfs/Connection.cxx | 9 ++++----- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/db/plugins/ProxyDatabasePlugin.cxx b/src/db/plugins/ProxyDatabasePlugin.cxx index 3debf487c..945c07d54 100644 --- a/src/db/plugins/ProxyDatabasePlugin.cxx +++ b/src/db/plugins/ProxyDatabasePlugin.cxx @@ -573,7 +573,7 @@ ProxyDatabase::Disconnect() noexcept assert(connection != nullptr); idle_event.Cancel(); - socket_event.Steal(); + socket_event.ReleaseSocket(); mpd_connection_free(connection); connection = nullptr; @@ -634,7 +634,7 @@ ProxyDatabase::OnIdle() noexcept LogError(std::current_exception()); } - socket_event.Steal(); + socket_event.ReleaseSocket(); mpd_connection_free(connection); connection = nullptr; return; diff --git a/src/event/SocketEvent.cxx b/src/event/SocketEvent.cxx index d4cf04bfd..22f457a30 100644 --- a/src/event/SocketEvent.cxx +++ b/src/event/SocketEvent.cxx @@ -37,16 +37,6 @@ SocketEvent::Open(SocketDescriptor _fd) noexcept fd = _fd; } -SocketDescriptor -SocketEvent::Steal() noexcept -{ - assert(IsDefined()); - - Cancel(); - - return std::exchange(fd, SocketDescriptor::Undefined()); -} - void SocketEvent::Close() noexcept { diff --git a/src/event/SocketEvent.hxx b/src/event/SocketEvent.hxx index 28cdf729f..0f4f0ec06 100644 --- a/src/event/SocketEvent.hxx +++ b/src/event/SocketEvent.hxx @@ -109,13 +109,12 @@ public: return fd; } - void Open(SocketDescriptor _fd) noexcept; + SocketDescriptor ReleaseSocket() noexcept { + Cancel(); + return std::exchange(fd, SocketDescriptor::Undefined()); + } - /** - * "Steal" the socket descriptor. This abandons the socket - * and returns it. - */ - SocketDescriptor Steal() noexcept; + void Open(SocketDescriptor _fd) noexcept; void Close() noexcept; diff --git a/src/lib/nfs/Connection.cxx b/src/lib/nfs/Connection.cxx index 9b546f941..3ab6813c6 100644 --- a/src/lib/nfs/Connection.cxx +++ b/src/lib/nfs/Connection.cxx @@ -403,8 +403,7 @@ NfsConnection::DestroyContext() noexcept new leases */ defer_new_lease.Cancel(); - if (socket_event.IsDefined()) - socket_event.Steal(); + socket_event.ReleaseSocket(); callbacks.ForEach([](CancellableCallback &c){ c.PrepareDestroyContext(); @@ -434,14 +433,14 @@ NfsConnection::ScheduleSocket() noexcept const int which_events = nfs_which_events(context); - if (which_events == POLLOUT && socket_event.IsDefined()) + if (which_events == POLLOUT) /* kludge: if libnfs asks only for POLLOUT, it means that it is currently waiting for the connect() to finish - rpc_reconnect_requeue() may have been called from inside nfs_service(); we must now unregister the old socket and register the new one instead */ - socket_event.Steal(); + socket_event.ReleaseSocket(); if (!socket_event.IsDefined()) { SocketDescriptor _fd(nfs_get_fd(context)); @@ -495,7 +494,7 @@ NfsConnection::OnSocketReady(unsigned flags) noexcept which is a sure sign that libnfs will close the socket, which can lead to a race condition if epoll_ctl() is called later */ - socket_event.Steal(); + socket_event.ReleaseSocket(); const int result = Service(flags);