NAME
IPC::MicroSocket::Server
- server role
SYNOPSIS
use v5.36;
use Future::AsyncAwait;
use Object::Pad v0.807;
use IPC::MicroSocket::Server;
class ExampleServer {
apply IPC::MicroSocket::Server;
async method on_connection_request ( $conn, $cmd, @args )
{
say "Connection sends $cmd";
return "Response for $cmd";
}
method on_connection_subscribe {}
}
await ExampleServer->new_unix( path => "my-app.sock" )
->run;
DESCRIPTION
This module provides the server role for IPC::MicroSocket. This is an incomplete role, which requires any class that applies it to provide some methods that contain the actual behaviour for the server.
CONSTRUCTOR
new_unix
$server = IPC::MicroSocket::Server->new_unix( path => $path, %args );
A convenience constructor for creating a new server instance listening on the given UNIX socket path.
Note as this is a role, this must be invoked on a class that applies the role and implements the missing methods.
Takes the following named arguments:
METHODS
publish
$server->publish( $topic, @args );
Sends a PUBLISH
frame to every connected client.
Note that this is not an async
method; the send future for each client becomes owned by the selector for each connected client instance individually.
run
await $server->run;
Returns a Future that represents the indefinite runtime of the server instance.
REQUIRED METHODS
on_connection_request
@response = await $server->on_connection_request( $conn, $cmd, @args );
Invoked on receipt of a REQUEST
frame from a connected client. It should asynchronously return the response list to be sent back to the client.
on_connection_subscribe
$server->on_connection_subscribe( $conn, $topic );
Invoked on receipt of a SUBSCRIBE
frame from a connected client.
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>