Net::DB...:Server(3)

✨ NAME ✨

Net::DBus::Binding::Server β€” a server to accept incoming connections πŸ’…

okay so this is the Net::DBus::Binding::Server(3) page from the User Contributed Perl Documentation (the header lowkey abbreviates it as Net::DB...:Server(3), but bestie we're using the full name). It's giving "accept incoming connections" main-character energy, no cap. ✨

🌸 SYNOPSIS 🌸

Creating a new server and accepting client connections β€” starter pack, slay:

use Net::DBus::Binding::Server;

my $server = Net::DBus::Binding::Server->new(address => "unix:path=/path/to/socket");

$server->connection_callback(\&new_connection);

sub new_connection {
    my $connection = shift;

    .. work with new connection...
}

iykyk: the synopsis literally says $server->connection_callback(\&new_connection);, and the METHODS section below says set_connection_callback β€” both are exactly as written in the original, so I'm not editing the plot. πŸ’€

Managing the server and new connections in an event loop β€” now we're getting the reactor involved:

my $reactor = Net::DBus::Binding::Reactor->new();

$reactor->manage($server);
$reactor->run();

sub new_connection {
    my $connection = shift;

    $reactor->manage($connection);
}

πŸ¦‹ DESCRIPTION πŸ¦‹

Bestie, this is a server for receiving connection from client programs. The methods defined on this module have a close correspondence to the dbus_server_XXX methods in the C API, so for further details on their behaviour, the C API documentation may be of use. periodt. πŸ’–

πŸ’… METHODS πŸ’…

okay so here's the method rundown, and yes every signature is staying exactly as written. No renaming, no merging, no "fixing" the docs. we don't do that here. πŸ’…

  • my $server = Net::DBus::Binding::Server->new(address => "unix:path=/path/to/socket"); β€” Creates a new server binding it to the socket specified by the address parameter. Slay, you made a server. 🫢
  • $status = $server->is_connected(); β€” Returns zero if the server has been disconnected, otherwise a positive value is returned. So zero = disconnected, positive = connected-ish. The docs say positive, bestie. ⭐
  • $server->disconnect(); β€” Closes this server to the remote host. This method is called automatically during garbage collection (ie in the DESTROY method) if the programmer forgets to explicitly disconnect. So yes, cleanup is automatic, but don't make forgetting the whole plan. 😭
  • $server->set_watch_callbacks(\&add_watch, \&remove_watch, \&toggle_watch); β€” Register a set of callbacks for adding, removing & updating watches in the application's event loop. Each parameter should be a code reference, which on each invocation, will be supplied with two parameters, the server object and the watch object. If you are using a Net::DBus::Binding::Reactor object as the application event loop, then the 'manage' method on that object will call this on your behalf. The 'manage' is in single quotes in the source, so I'm keeping it. πŸ’…
  • $server->set_timeout_callbacks(\&add_timeout, \&remove_timeout, \&toggle_timeout); β€” Register a set of callbacks for adding, removing & updating timeouts in the application's event loop. Each parameter should be a code reference, which on each invocation, will be supplied with two parameters, the server object and the timeout object. If you are using a Net::DBus::Binding::Reactor object as the application event loop, then the 'manage' method on that object will call this on your behalf. Same deal, but for timeouts. ⏰
  • $server->set_connection_callback(\&handler) β€” Registers the handler to use for dealing with new incoming connections from clients. The code reference will be invoked each time a new client connects and supplied with a single parameter which is the Net::DBus::Binding::Connection object representing the client. This is the main-character callback for fresh clients. πŸ‘‘

πŸŽ€ AUTHOR πŸŽ€

Daniel P. Berrange. That's the author, bestie. 🫢

Copyright (C) 2004-2011 Daniel P. Berrange. Keep it exact, keep it iconic. πŸ’œ

🌈 SEE ALSO 🌈

okay so go check out these modules too, they're all listed in the original and I'm listing every single one with no skips:

  • Net::DBus::Binding::Connection
  • Net::DBus::Binding::Bus
  • Net::DBus::Binding::Message::Signal
  • Net::DBus::Binding::Message::MethodCall
  • Net::DBus::Binding::Message::MethodReturn
  • Net::DBus::Binding::Message::Error

and that's the tea β˜• β€” the footer says perl v5.42.0, dated 2019-12-17, and the title down there is still Net::DB...:Server(3). mwah πŸ’‹βœ¨