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::timeepoch updated whenever the consuming class successfully sends or receives bytes on that connection.
The role only reads
last_activeand the set of keys; the structure is otherwise opaque to it. - $self->_close_connection($peer_id)
-
Closes the underlying handle for
$peer_idand removes the entry from the connection cache. May be called from insideclose_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_idif any, returning true if a connection was present. - $epoch = $self->last_activity($peer_id)
-
Returns the
Time::HiResepoch at which the connection to$peer_idlast sent or received bytes. Returnsundefif no such connection exists. - $count = $self->close_idle_connections($max_idle_seconds)
-
Closes every cached connection whose
last_activeis older thantime - $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
AUTHORS
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.