Commit Graph

15410 Commits

Author SHA1 Message Date
Max Kellermann
c7409d1e04 util/AllocatedString: add missing include 2024-05-23 20:22:44 +02:00
Max Kellermann
b64d01677b storage/nfs: optimize OpenFile() 2024-05-17 13:39:42 +02:00
Max Kellermann
9e8128ecb5 lib/nfs/FileReader: convert path to std::string 2024-05-17 12:54:08 +02:00
Max Kellermann
131dcce0a1 playlist/Mapper: use Storage::OpenFile() 2024-05-17 12:54:08 +02:00
Max Kellermann
6dfdd8c1c2 db/update/Walk: use Storage::OpenFile() 2024-05-17 12:54:08 +02:00
Max Kellermann
1b6c279850 db/update/Paylist: use Storage::OpenFile() 2024-05-17 12:54:08 +02:00
Max Kellermann
81c778a529 SongUpdate: use Storage::OpenFile() 2024-05-17 12:54:08 +02:00
Max Kellermann
f578a1cb2b storage/Interface: add virtual method OpenFile()
This should replace most InputStream::Open() calls because it is a
chance to reuse existing resources (e.g. the NFS connection).  No such
optimization is implemented, currently (and the method is not yet used
by anybody).
2024-05-17 12:54:08 +02:00
Max Kellermann
2576e66a55 input/nfs: cancel the pending read operation on seek 2024-05-17 12:54:08 +02:00
Max Kellermann
58e3b830e9 lib/nfs/FileReader: clear the read_buffer in CancelRead()
Fixes assertion failure with libnfs 6.
2024-05-17 12:53:35 +02:00
Max Kellermann
1d35031024 lib/nfs/Connection: merge CancelAndClose() into Cancel() 2024-05-17 12:53:30 +02:00
Max Kellermann
96b61755da lib/nfs/FileReader: fix doc typo 2024-05-15 21:31:30 +02:00
Max Kellermann
9f174c56ce playlist/Mapper: postpone the stored playlist error
Fixes another regression by commit
f53cd44c7a - an exception thrown by
playlist_open_in_playlist_dir() would skip over
playlist_open_in_storage().
2024-05-15 21:08:46 +02:00
Max Kellermann
c8be9662bb playlist/Print: add missing exception handler
This went missing in commit f53cd44c7a
2024-05-15 20:53:55 +02:00
Max Kellermann
f53cd44c7a playlist/{Stream,Mapper,Any}: propagate exceptions, do not catch&log them
Let the caller handle all the exceptions.
2024-05-15 20:19:57 +02:00
Max Kellermann
9303764a83 playlist/Print: throw PlaylistError::NoSuchList instead of returning false 2024-05-15 20:19:09 +02:00
Max Kellermann
a5456a89dc playlist/Length: throw PlaylistError::NoSuchList instead of returning false 2024-05-15 20:15:16 +02:00
Max Kellermann
c974fc664c playlist/Plugin: add noexcept 2024-05-15 20:02:12 +02:00
Max Kellermann
eceead671e playlist/Stream: add API documentation 2024-05-15 19:59:57 +02:00
Max Kellermann
4e7b554605 TagAny, playlist/Mapper: use if with initializer 2024-05-15 15:02:59 +02:00
Max Kellermann
a701da6386 db/update/InotifyUpdate: use OpenLocalInputStream() 2024-05-15 14:48:32 +02:00
Max Kellermann
1f47fe47c7 input/Open: move code to WaitReady() 2024-05-15 14:39:40 +02:00
Max Kellermann
31e583e9f8 lib/nfs: initial support for libnfs API 2
Commit
5e8f7ce273
introduced the libnfs API version 2 which may eventually become libnfs
version 6.

This version detection depends on my pull request
https://github.com/sahlberg/libnfs/pull/468
2024-05-15 06:01:42 +02:00
Max Kellermann
0ac24e5a24 lib/nfs/FileReader: move code to ReadCallback() 2024-05-15 06:00:37 +02:00
Max Kellermann
98f53b6d3d lib/nfs/Connection: add DisposablePointer parameter to CancelAndClose()
Just in case somebody needs to free a buffer after the NFS
cancellation has completed.
2024-05-15 06:00:35 +02:00
Max Kellermann
f5092cb73d util/DisposablePointer: new class 2024-05-15 05:58:23 +02:00
Max Kellermann
48d3bd1cca lib/nfs/Connection: add API documentation 2024-05-14 19:57:50 +02:00
Max Kellermann
5cffd4f673 lib/nfs/Connection: remove EnableCloseOnExec() call
SOCK_CLOEXEC has been added to libnfs version 2, and since we require
at least version 4, we can safely remove this call.
2024-05-14 19:51:52 +02:00
Max Kellermann
416f65fe01 util/RoundPowerOfTwo: new library 2024-05-13 20:25:57 +02:00
Max Kellermann
64c291ba78 lib/nfs/Connection: suppress bogus clang warning
We do need to capture "this" because we use "this->active_leases", but
clang 18 is too dumb to understand this.
2024-05-13 18:30:05 +02:00
Max Kellermann
dcde2a0bae lib/nfs/Connection: fix -Wunused-lambda-capture 2024-05-13 18:27:38 +02:00
Max Kellermann
f0ac0c19b7 lib/nfs/Connection: remove obsolete debug field "in_destroy"
This is obsolete because PrepareDestroyContext() no longer calls
nfs_destroy_context().
2024-05-13 16:53:18 +02:00
Max Kellermann
ba1b8533a5 lib/nfs/Connection: fix assertion failure on mount timeout
When nfs_destroy_context() is called while nfs_mount_async() is in
progress, libnfs invokes MountCallback(-EINTR) (but only if a NFS RPC
call is in progress; if the TCP connect is in progress, that callback
is not invoked).

If the mount operation had timed out, OnMountTimeout() set
mount_state=FINISHED, which triggered an assertion failure in
MountCallback(); this commit adds a check on whether the mount has
timed out and ignores the MountCallback.
2024-05-13 16:51:44 +02:00
Max Kellermann
84e8927b1b lib/nfs/FileReader: remove obsolete stat64 cast
Obsoleted (and broken) by commit 9947d3e67f
2024-05-13 12:33:03 +02:00
Max Kellermann
556300d59a input/InputStream: add [[nodiscard]] 2024-05-13 12:29:16 +02:00
Max Kellermann
34f7b38f39 input/InputStream: pass std::span<std::byte> to Read() 2024-05-13 12:28:40 +02:00
Max Kellermann
f28d10d934 decoder/dsdiff: convert pointers to references 2024-05-13 11:34:05 +02:00
Max Kellermann
6d5dab38dd input/async: pass std::string_view to constructor 2024-05-13 10:18:18 +02:00
jcorporation
f8271fec12 command_available return stickernames only if stickerdb is enabled 2024-05-12 21:23:29 +02:00
Max Kellermann
4800f1d8f2 storage/Interface: add [[nodiscard]] 2024-05-10 19:08:57 +02:00
Max Kellermann
227ab998bc lib/nfs/Connection: pass status and data to the NfsClientError ctor
This way, we avoid calling the FormatNfsClientError() which crashes
when nfs_get_error() returns nullptr; that can happen on RPC errors:
then, libnfs's check_nfs4_error() doesn't call nfs_set_error().

Closes https://github.com/MusicPlayerDaemon/MPD/issues/2040
2024-05-10 16:36:29 +02:00
Max Kellermann
9384bff6f9 lib/nfs/Manager: add method MakeConnection()
This uses the libnfs function nfs_parse_url_dir() which means MPD
gains support for the libnfs arguments like "version".

Closes https://github.com/MusicPlayerDaemon/MPD/issues/2039
2024-05-07 21:22:43 +02:00
Max Kellermann
9947d3e67f lib/nfs/Connection: use nfs_fstat64_async()
This is 64-bit-safe and anyway, nfs_fstat_async() doesn't work with
NFSv4.
2024-05-07 21:22:40 +02:00
Max Kellermann
67f01fbdb6 db/plugins/simple/Song: pass StorageFileInfo to UpdateFile()
Eliminates a redundant GetInfo() call.
2024-05-07 21:22:39 +02:00
Max Kellermann
164b5b0cf3 db/Song, SongUpdate: remove unnecessary c_str() calls
Just case implicitly to std::string_view, which is both simpler and
safer.
2024-05-07 21:13:38 +02:00
Max Kellermann
56bb1dddd7 lib/nfs/Connection: simplify error handling in OnSocketReady() 2024-05-06 18:35:58 +02:00
Max Kellermann
e6b1cf540b lib/nfs/Connection: remove unnecessary initializers from MountInternal() 2024-05-06 18:24:36 +02:00
Max Kellermann
d61c83ace8 lib/nfs/Connection: create the nfs_context in the constructor
Another lifetime simplification.
2024-05-06 18:22:23 +02:00
Max Kellermann
4139024b3d lib/nfs/Connection: return from OnSocketReady() after error 2024-05-06 18:20:42 +02:00
Max Kellermann
48fe8666c9 lib/nfs/Connection: call nfs_destroy_context() only in the destructor
This simplifies the lifetime of the nfs_context object.
2024-05-06 18:16:11 +02:00
Max Kellermann
90a44a0c07 lib/nfs/Connection: replace flag "mount_finished" with enum 2024-05-06 18:16:11 +02:00
Max Kellermann
e013c19223 storage/nfs: remove unused method EnsureConnected() 2024-05-06 18:16:11 +02:00
Max Kellermann
4684d05fa6 player/Thread: reset the decoder_starting flag in StopDecoder()
Fixes crash bug (assertion failure) if a new "play" command is handled
while the player thread waits for decoder startup.
2024-05-06 17:38:58 +02:00
Max Kellermann
1c3a1c842d lib/nfs/Lease: use InstrusiveList instead of std::list 2024-05-06 17:22:36 +02:00
Max Kellermann
f5127686fe lib/nfs/Connection: pass std::exception_ptr by value 2024-05-06 17:03:21 +02:00
Max Kellermann
2b0275a1c8 lib/nfs/Connection: pass server and export_name as std::string_view 2024-05-06 17:01:15 +02:00
Max Kellermann
028693c380 lib/nfs/Manager: forward-declare class ManagedConnection 2024-05-06 16:58:41 +02:00
Max Kellermann
63920be17e lib/nfs/Connection: make server and export_name const 2024-05-06 16:55:57 +02:00
Max Kellermann
96888cce9c storage/nfs: pass std::string_view to the NfsStorage ctor 2024-05-06 15:28:01 +02:00
Max Kellermann
bcc39be784 lib/nfs/Base: use std::string_view 2024-05-06 15:25:55 +02:00
Max Kellermann
b6314b4c4b lib/nfs/Base: use std::array 2024-05-06 15:22:49 +02:00
Max Kellermann
23d895415a lib/nfs/meson.build: require libnfs 4.0
All Linux distributions have at least version 4, and thus I cannot
test with older versions.
2024-05-06 14:54:04 +02:00
Max Kellermann
518ce0187a remove macOS support
There were a few macOS related bug reports on the bug tracker which
have been open for years without a volunteer caring for them.  The
GitHub actions build has also been broken for a long time due to bugs
in the ancient LLVM toolchain shipped with macOS, making macOS an
unsuitable non-Linux target for testing MPD's portability.

All of this makes macOS support an annoying liability for me.  To
avoid more frustration, I'm hereby dropping macOS support completely
from MPD.  Maybe this causes enough pain for a new maintainer to
spawn, but maybe nobody cares, so... let's see.
2024-05-06 14:11:50 +02:00
Max Kellermann
615f6f50ce lib/yajl: drop "yajl/" prefix from #include paths
According to the yajl API documentation, #include lines should have
the "yajl/" path prefix, but the actual pkg-config file contains:

 includedir=${dollar}{prefix}/include/yajl

.. which already contains this directory name, and thus the "yajl/"
prefix cannot work.  Unfortunately, the yajl project hasn't been
maintained for nearly 10 years, and there's little chance this bug
will ever be fixed.
2024-05-06 13:31:34 +02:00
Max Kellermann
03b674ce73 net/meson.build: compile IPv[46]Address.cxx only if TCP is enabled 2024-05-06 12:57:55 +02:00
Max Kellermann
9c421997bf net/SocketDescriptor: WriteNoWait() uses MSG_NOSIGNAL 2024-05-06 12:55:02 +02:00
Max Kellermann
73509fc189 net/LocalSocketAddress: new class wrapping struct sockaddr_un 2024-05-06 12:54:45 +02:00
Max Kellermann
7c9b7fa311 net/SocketAddress: use std::string_view::find() instead of std::memchr() 2024-05-06 12:54:45 +02:00
Max Kellermann
cbba22c947 net/SocketAddress: include IPv[46]Address.hxx only ifdef HAVE_TCP 2024-05-06 12:50:44 +02:00
Max Kellermann
f8529d4fe6 net/{Allocated,Static}SocketAddress: inline GetLocalRaw() 2024-05-06 12:50:29 +02:00
Max Kellermann
2a206ef309 net/StaticSocketAddress: add method GetLocalPath() 2024-05-06 12:50:24 +02:00
Max Kellermann
6200c0dc46 net/StaticSocketAddress: include <string_view> only ifdef HAVE_UN 2024-05-06 12:50:19 +02:00
Max Kellermann
1760310123 Revert "util/IntrusiveList: allow the last disposer to destroy the IntrusiveList"
This reverts commit 669cbcd25a
("util/IntrusiveList: allow the last disposer to destroy the
IntrusiveList").  It was bad because it could lead to off-by-one crash
bugs when the last item was removed inside the previous item's
disposer.

We need a different solution for the other crash bug that was fixed by
the reverted commit.
2024-05-06 12:49:30 +02:00
Max Kellermann
56d4784b11 util/IntrusiveList: add API documentation 2024-05-06 12:48:53 +02:00
Max Kellermann
4d3adaa557 event/SocketEvent: erase IMPLICIT_FLAGS in Cancel{Read,Write}()
Without this, calling CancelRead() after ScheduleRead() would leave
the HANGUP scheduled, and the caller could receive HANGUP events over
and over which are never properly handled, leading to a busy loop.

The semantics of this API are hard to get right, because the
IMPLICIT_FLAGS (a property of epoll) are somewhat weird.  But it seems
that this change repairs a side effect of the SocketEvent interface
that seemed counterintuitive.
2024-05-06 12:48:42 +02:00
Max Kellermann
6830cf9dcf net/AllocatedSocketAddress: add SetLocal() overload with std::string_view 2024-05-06 12:48:42 +02:00
Max Kellermann
7ebe56fdd9 util/SpanCast: allow ToStringView() only with integral char types
This avoids std::string_view specialization that make no sense.
2024-04-16 12:37:08 +02:00
Max Kellermann
fae235197f util/SpanCast: allow ReferenceAsBytes() only with trivially-copyable
Addd the std::has_unique_object_representations_v constraint so we
cast stuff to std::byte only if this would make sense.
2024-04-16 12:33:36 +02:00
Max Kellermann
0c1ecc96a8 *: let libfmt quote strings 2024-04-16 11:50:18 +02:00
Max Kellermann
39c9e92f42 lib/fmt: require libfmt 9
Version 9 added the "debug format" which I'd like to use.
2024-04-16 11:50:18 +02:00
Max Kellermann
0d8498f1d1 lib/fmt/SocketAddressFormatter: simpler template syntax 2024-04-16 11:02:36 +02:00
Max Kellermann
7198db758d lib/fmt/PathFormatter: eliminate AllocatedPath specialization with std::convertible_to<Path> 2024-04-16 11:00:21 +02:00
Max Kellermann
7a4743d00e config/File: add missing include 2024-04-16 11:00:21 +02:00
Max Kellermann
ae85c2a979 db/Configured: log debug message when there is no cache directory
Closes https://github.com/MusicPlayerDaemon/MPD/issues/1525
2024-04-16 10:57:28 +02:00
Max Kellermann
9c7b930f8f Merge branch 'alsa-drain-recovery' of https://github.com/borine/MPD 2024-04-15 22:21:53 +02:00
Max Kellermann
57212d5a35 player/Thread: remove unnecessary StartDecoder() call
Let Run() do this in the next loop iteration.
2024-04-15 21:49:11 +02:00
Max Kellermann
7236f83999 player/Thread: do not start the decoder twice
Upon receiving PlayerCommand::QUEUE, call StartDecoder() only if the
decoder is not already starting.  Checking just
DecoderControl::IsIdle() is not enough because the decoder may already
have finished decoding the song before the player has started playing
it and before it had a chance to call CheckDecoderStartup().

Omitting the StartDecoder() call now means it will be started later in
the Run() main loop, after CheckDecoderStartup() has succeeded (which
effectively switches to the song that has already been decoded by the
current decoder).

This fixes an assertion failure when compiled in debug mode
(`-Db_ndebug=false`) and random noise playback in non-debug mode
(`-Db_ndebug=true`).

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1900
2024-04-15 21:39:53 +02:00
Max Kellermann
c8ece786dd player/Thread: add assert() to StartDecoder()
StartDecoder() must not be called when a decoder is still being
started.  This detects the bug
https://github.com/MusicPlayerDaemon/MPD/issues/1900 earlier.
2024-04-15 21:36:11 +02:00
Max Kellermann
1e4bf90c60 io, net, evnet: quote file names in error messages 2024-04-10 13:36:05 +02:00
Max Kellermann
b3a31b69ee util/RedBlackTree: fix lost "right" child while swapping with successor
Fixes a tree corruption bug that led to assertion failures.
2024-04-10 13:35:31 +02:00
Max Kellermann
88475f2e2b util/RedBlackTree: swap colors when swapping with successor
Swapping was incomplete without swapping the colors; this led to
assertion failures under certain conditions.
2024-04-10 13:35:28 +02:00
Max Kellermann
e0a53d4747 util/IntrusiveTreeSet: add debug method Check()
Only for the unit test.
2024-04-10 13:35:21 +02:00
Max Kellermann
669cbcd25a util/IntrusiveList: allow the last disposer to destroy the IntrusiveList
Fixes a use-after-free bug in Co::MultiAwaitable::SetReady() when the
last callback frees the Co::MultiAwaitable owner.
2024-04-10 13:35:09 +02:00
Max Kellermann
2f7c19f139 util/SpanCast: rewrite ToStringView(std::span<std::byte>) to avoid cast ambiguities 2024-04-10 13:34:51 +02:00
Max Kellermann
e131f22642 util/SpanCast: merge two ToStringView() using std::remove_const_t 2024-04-10 13:34:25 +02:00
jcorporation
c613d25f29 Add operators contains and starts_with to sticker find 2024-04-06 20:08:59 +02:00
Max Kellermann
4c56e87e36 lib/curl/Global: remove empty line 2024-04-04 09:18:34 +02:00
Max Kellermann
011b96ff98 net/UniqueSocketDescriptor: add method MoveToFileDescriptor() 2024-04-04 09:16:44 +02:00
Max Kellermann
d563f5fc87 decoder/mpg123: use mpg123_ssize_t only on MPG123_API_VERSION >= 47 2024-04-03 23:21:54 +02:00
Max Kellermann
9c2df5ce19 decoder/mpg123: implement stream_decode 2024-04-03 23:12:26 +02:00