Ferreteria/v0.6/clade/IO/Aspect/Connx: Difference between revisions
< Ferreteria | v0.6 | clade | IO | Aspect
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
{{page/clade/v2 | {{page/clade/v2 | ||
|fam= | |fam= | ||
{{!}} align=right {{!}} {{l/ver/clade|IO|Aspect}} | {{!}} align=right {{!}} <code>{{l/ver/clade|IO|Aspect}}</code> | ||
{{!}} align=center {{!}} → {{l/ver/clade|IO\Aspect|Connx}} → | {{!}} align=center {{!}} → <code>{{l/ver/clade|IO\Aspect|Connx}}</code> → | ||
{{!}} align=left {{!}} {{l/ver/clade|IO\Aspect\Connx|Plug}} | {{!}} align=left {{!}} | ||
<code>{{l/ver/clade|IO\Aspect\Connx|Buffer}}</code><br> | |||
<code>{{l/ver/clade|IO\Aspect\Connx|Plug}}</code><br> | |||
<code>{{l/ver/clade|IO\Aspect\Connx|Process}}</code> | |||
|alia= | |alia= | ||
{{!-!}} '''Base'''* [ca,i,t] {{!!}} {{l/ver/clade/full | {{!-!}} '''Base'''* [ca,i,t] {{!!}} <code>{{l/ver/clade/full|IO|Aspect}}</code> | ||
{{!-!}} '''Action'''* [c,i] | {{!-!}} '''Action'''* [c,i] {{!!}} <code>{{l/ver/clade/full|Sys\Events|ItWent}}</code> | ||
{{!-!}} '''SelfIface''' {{!!}} {{l/ver/clade/full | {{!-!}} '''SelfIface''' {{!!}} <code>{{l/ver/clade/full|IO\Aspect|Connx}}</code> | ||
}} | }} | ||
==About== | ==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 | ** 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) | ** internally requests the actual opening and closing as needed (when req-qty changes to/from zero) | ||
==History== | ==History== | ||
* '''{{fmt/date|2024|11|28}}''' extracted relevant code from ssh/Shell so that Buffer and fsys/Node could use it too. | * '''{{fmt/date|2024|11|28}}''' extracted relevant code from ssh/Shell so that Buffer and fsys/Node could use it too. | ||
* '''{{fmt/date|2025|03|28}}''' moved from [WFe]IO\Connx\Aux\xOpener -> [WFe]IO\xConnx; added Base clade, caConnx | * '''{{fmt/date|2025|03|28}}''' moved from [WFe]<code>IO\Connx\Aux\xOpener</code> -> [WFe]<code>IO\xConnx;</code> added Base clade, caConnx | ||
* '''{{fmt/date|2025|05|27}}''' moved from [WFe]IO | * '''{{fmt/date|2025|05|27}}''' moved from [WFe]<code>IO</code> ⇒ [WFe]<code>IO\Aspect</code>; correspondingly re-parented | ||
==Code== | ==Code== | ||
''as of 2025 | ''as of {{fmt/date|2025|10|22}}'' | ||
{{fmt/php/block|1= | {{fmt/php/block|1= | ||
interface iConnx extends BaseIface { | interface iConnx extends BaseIface { | ||
Latest revision as of 03:10, 26 November 2025
| ||||||||||||||||||
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)
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;
}