NAME

IPC::Manager::Role::Client::Connection - Per-connection management for connection-oriented clients

DESCRIPTION

A Role::Tiny role for IPC clients that maintain a per-peer set of live connections (e.g. IPC::Manager::Client::ConnectionUnix, and a planned TCP-based ConnectionIP). It provides a small API for inspecting and terminating individual connections, and for reaping connections that have been idle for too long.

REQUIRED METHODS

The consuming class must provide:

$hashref = $self->_connections

Returns the underlying connection cache as a hashref keyed by peer id. Each value is a hashref with at least:

fh

The live filehandle / socket for that peer.

last_active

A Time::HiRes::time epoch updated whenever the consuming class successfully sends or receives bytes on that connection.

The role only reads last_active and the set of keys; the structure is otherwise opaque to it.

$self->_close_connection($peer_id)

Closes the underlying handle for $peer_id and removes the entry from the connection cache. May be called from inside close_idle_connections; safe to no-op if the connection is already gone.

PROVIDED METHODS

$bool = $self->has_connection($peer_id)

True iff there is a cached connection to $peer_id.

@peer_ids = $self->connections

Sorted list of peer ids that have an active cached connection.

$bool = $self->disconnect_connection($peer_id)

Closes the connection to $peer_id if any, returning true if a connection was present.

$epoch = $self->last_activity($peer_id)

Returns the Time::HiRes epoch at which the connection to $peer_id last sent or received bytes. Returns undef if no such connection exists.

$count = $self->close_idle_connections($max_idle_seconds)

Closes every cached connection whose last_active is older than time - $max_idle_seconds. Returns the number of connections closed.

This method is caller-driven: the role does not run any background timer.

SOURCE

The source code repository for IPC::Manager can be found at https://github.com/exodist/IPC-Manager.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright Chad Granum <exodist7@gmail.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See https://dev.perl.org/licenses/