Ferreteria/v0.6/clade/IO/Aspect/Connx
< Ferreteria | v0.6 | clade | IO | Aspect
Jump to navigation
Jump to search
About
- Purpose: encapsulates a connection to a Socket (...I think...)
- Services:
- keeps track of how many requests there are for a thing to be open
- internally requests the actual opening and closing as needed (when req-qty changes to/from zero)
Subspaces
History
- 2024-11-28 extracted relevant code from ssh/Shell so that Buffer and fsys/Node could use it too.
- 2025-03-28 moved from [WFe]
IO\Connx\Aux\xOpener-> [WFe]IO\xConnx;added Base clade, caConnx - 2025-05-27 moved from [WFe]
IO⇒ [WFe]IO\Aspect; correspondingly re-parented
Code
interface iConnx extends BaseIface {
// LIFECYCLE
function IsOpen() : bool;
function Open() : ActionIface;
function Shut() : ActionIface;
}
trait tConnx {
use BaseTrait;
abstract protected function ActualOpen() : ActionIface;
abstract protected function ActualShut() : ActionIface;
private int $nOpens = 0;
public function IsOpen() : bool { return $this->nOpens > 0; }
private $oAct; // 2025-04-12 For now, this only saves the status of the ActualOpen() operation, not ActualShut().
public function ItWent() : ActionIface { return $this->oAct; }
public function Open() : ActionIface {
$nOpens = $this->nOpens++;
#echo get_called_class()." OPENS: [$nOpens]".CRLF;
if ($nOpens === 0) {
#echo ' - actual open:'.CRLF;
$oAct = $this->ActualOpen();
$this->oAct = $oAct;
#echo ' - - $oAct class: '.get_class($oAct).CRLF;
} else {
#echo ' - opening existing $oAct'.CRLF;
// Report results of actual open, which happened earlier.
$oAct = $this->oAct;
}
return $oAct;
}
public function Shut() : ActionIface {
$nOpens = --$this->nOpens;
if ($nOpens == 0) {
$oAct = $this->ActualShut();
} else {
$oAct = new ActionClass;
$oAct->SetNoOp();
// Only the final/real Shut() actually does anything.
}
return $oAct;
}
}
abstract class caConnx extends BaseClass implements SelfIface {
use tConnx;
}