Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from MusicPlayerDaemon:master #24

Merged
merged 10 commits into from
Jan 29, 2025

Conversation

pull[bot]
Copy link

@pull pull bot commented Jan 29, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

Summary by Sourcery

Refactor the input stream handling to use a new MoveTo method in CircularBuffer for reading data. Update client identification to use peer credentials if available, falling back to the socket address. Start the IO threads earlier during initialization.

This logs the client address (or the process id and uid for local
connections) in each log line instead of the number.
From https://github.com/CM4all/libcommon - the new class is mostly
identical, and I want to maintain only one of them.
This might give tiny kernel-side optimizations.
This fixes a regression triggered by commit e309941 -
IORING_SETUP_SINGLE_ISSUER broke because io_uring_setup() was called
fromm the main thread, yet io_uring_submit() in the I/O thread.  This
is because the I/O thread was not yet started when
InitUringInputPlugin() was called, and BlockingCall() was invoked
synchronously in the main thread.  This has always been wrong, but was
never noticed.
This implements wraparound, so AsyncInputStream and ThreadInputStream
can now return all of the buffer contents in one Read() call.
@pull pull bot added the ⤵️ pull label Jan 29, 2025
@pull pull bot merged commit e06d775 into CartoonFan:master Jan 29, 2025
1 check was pending
Copy link

sourcery-ai bot commented Jan 29, 2025

Reviewer's Guide by Sourcery

This pull request refactors the way data is read from the input stream buffers, introduces client names, and adds support for peer credentials.

Sequence diagram for client connection handling

sequenceDiagram
    participant C as Client
    participant S as ServerSocket
    participant L as ClientListener
    C->>S: Connect
    S->>L: OnAccept(fd, address)
    L->>L: GetPeerCredentials()
    L->>L: MakeClientName(address, cred)
    L->>C: Create new client
    Note over C: Initialize with name<br/>instead of number
Loading

Class diagram for AsyncInputStream and ThreadInputStream changes

classDiagram
    class AsyncInputStream {
        -CircularBuffer buffer
        -offset_type offset
        +ReadFromBuffer(dest: std::span<std::byte>) std::size_t
        +Read(lock: std::unique_lock<Mutex>, dest: std::span<std::byte>) size_t
    }
    class ThreadInputStream {
        -CircularBuffer buffer
        -offset_type offset
        +ReadFromBuffer(dest: std::span<std::byte>) std::size_t
        +Read(lock: std::unique_lock<Mutex>, dest: std::span<std::byte>) size_t
    }
    note for AsyncInputStream "Added ReadFromBuffer method
to handle buffer reading logic"
    note for ThreadInputStream "Added ReadFromBuffer method
to handle buffer reading logic"
Loading

Class diagram for Client and SocketPeerCredentials changes

classDiagram
    class Client {
        -string name
        -unsigned permission
        -int uid
        +Client(loop: EventLoop, partition: Partition, fd: UniqueSocketDescriptor, uid: int, permission: unsigned, name: string)
    }
    class SocketPeerCredentials {
        +IsDefined() bool
        +GetPid() int
        +GetUid() int
        +GetGid() int
        +static Undefined() SocketPeerCredentials
    }
    note for Client "Replaced num with name field
for better client identification"
    note for SocketPeerCredentials "New class for handling
peer credentials across
different platforms"
Loading

File-Level Changes

Change Details Files
Refactor buffer reading logic into a dedicated method
  • Introduce ReadFromBuffer method to encapsulate buffer reading logic.
  • Use MoveTo method of CircularBuffer to move data to the destination.
  • Clear the buffer when it becomes empty.
src/input/AsyncInputStream.cxx
src/input/ThreadInputStream.cxx
Introduce client names
  • Add a name field to the Client class.
  • Generate client names based on socket address and peer credentials.
  • Use client names in log messages instead of client numbers.
src/client/New.cxx
src/client/Process.cxx
src/client/Expire.cxx
src/client/Client.hxx
Add support for peer credentials
  • Introduce SocketPeerCredentials class to encapsulate peer credentials.
  • Add GetPeerCredentials method to SocketDescriptor.
  • Pass peer credentials to client_new function.
  • Use peer credentials to generate client names.
  • Remove the uid parameter from client_new and OnAccept methods.
src/client/New.cxx
src/event/ServerSocket.cxx
src/net/SocketDescriptor.cxx
src/client/Listener.cxx
src/net/PeerCredentials.hxx
src/net/SocketDescriptor.hxx
Update io_uring usage
  • Move io_uring related code to a dedicated directory.
  • Update io_uring initialization to use a single issuer.
  • Start io and rtio threads before initializing neighbors.
src/Main.cxx
src/event/Loop.cxx
src/event/meson.build
src/event/uring/Manager.cxx
src/event/uring/Manager.hxx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant