Ferreteria/v0.6/clade/IO/Aspect/Connx/Process/Local/@removed

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | IO‎ | Aspect‎ | Connx‎ | Process/Local
Jump to navigation Jump to search
Removed Code

2026-01-17

Removed now because nothing seems to use it, and it's marked as unfinished:

#
    // ACTION: Send the contents of $oSrce to the Process output stream ($oaPipes->DestStream()).
    public function SendStream(StreamIface $oSrce) : CommOpObjIface {
        // SETUP
        $oScrn = self::Screen();
        $oReadout = $this->Readout();
        $ofLogIO = self::LogFile()->InOut();  // logfile for debugging

        $oaPipes = $this->OAPipes();
        $oDest = $oaPipes->DestStream();

        // WORKING HERE 2026-01-05
    }

Renamed with suffix _DEPRECATED about a week ago:

#
    // ACTION: Streams content from $oSrce to $oDest
    public function Convey_DEPRECATED(StreamIface $oSrce, StreamIface $oDest) {
        $oScrn = self::Screen();
        $oReadout = $this->Readout();

        // Need to set these for the Readout:
        $this->RecverStream($oDest);  // should really be *dest* stream
        $this->SenderStream($oSrce);  // should really be *srce* stream

        $oSrce->Open();
        $oDest->Open();
        $oItWent = $this->Open();

        $oaPipes = $this->OAPipes();

        /*
        $this->AmHereShort(CRLF
          .' - FROM : '.$oSrce->Inspect()->Render().CRLF
          .' - TO   : '.$oDest->Inspect()->Render().CRLF
          .' - # OPEN = '.$oaPipes->CountOpen()
          );
          */

        // Set the streams to non-blocking mode:
        $n = $oaPipes->Block(FALSE);
        self::SoftAssert($n === 3,"Could only unblock $n pipe".($n==1?'':'s'));

        $ofLogIO = self::LogFile()->InOut();
        $ofLogIO->Open();
        $ofLogIO->WriteEntry("++++ Convey()");

        $qrDestPipe = $oaPipes->DestStream(); // where we are sending the data
        $qrErrsPipe = $oaPipes->ErrsStream(); // errors from the receiver
        $qrSrcePipe = $oaPipes->SrceStream(); // non-error responses from receiver

        $doSendLoop = TRUE;
        $nlDone = '-';  // initial value
        $nlTried = '-';
        $sPiece = NULL;
        $nlSrceTotal = $oSrce->NTotalBytes();
        $nlDoneTotal = 0;
        $oSender = new SenderClass;
        $oSender->OUpdater($this);
        $oSender->OLogger($ofLogIO);
        $oReadout->StartClock();  // reset the time counter

        $oItWent = $oSender->Convey($oSrce,$oDest);

        $oSrce->Shut();
        $oDest->Shut();
        $this->Shut();
        $ofLogIO->WriteEntry("---- Convey()");
        $ofLogIO->Shut();
    }

    // ++ ACTION: internal ++ //

    // ACTION: Read from the process (OAPipes source-pipe) into the given stream. If no input, and $doWait is TRUE, then wait for input before returning.
    // TODO 2026-01-04
    //    * Rename to ProcessToStream() or maybe just ToStream().
    //    * What is $oDest going to? Oh, it's redundant... or, actually, not right. Replacing with $oData.
    //    * The main I/O here is:
    //      * process stream for sending replies -- $oaPipes->SrceStream()
    //      * process stream for receiving commands -- $oaPipes->DestStream()
    //      * file source-stream for commands to process -- $oData
    protected function PipeToStream_DEPRECATED(StreamIface $oData, bool $doWait) : CommOpObjIface {
        $oScrn = self::Screen();
        $oReadout = $this->Readout();
        $ofLogIO = self::LogFile()->InOut();  // logfile for debugging

        #$oRecv = $this->RecverStream();  // 2026-01-04 Do we need this at some point? (Rewrite in progress...)

        $oaPipes = $this->OAPipes();
        $oSrce = $oaPipes->SrceStream();
        /* debugging
        $this->AmHereShort(CRLF
          .' - FROM : '.$oaPipes->SrceStream()->Inspect()->Render().CRLF
          .' - TO   : '.$oDest->Inspect()->Render().CRLF
          .' - # OPEN = '.$oaPipes->CountOpen()
          );
          //*/

        /* 2026-01-04 I am now questioning this...
        $this->RecverStream($oDest);
        $this->SenderStream($oSrce);
        */

        // Set the streams to non-blocking mode:
        $n = $oaPipes->Block(FALSE);
        self::SoftAssert($n === 3,"Could only unblock $n pipe".($n===1?'':'s'));

        $qrDestPipe = $oaPipes->DestStream(); // where we are sending the data
        $qrErrsPipe = $oaPipes->ErrsStream(); // errors from the receiver
        $qrSrcePipe = $oaPipes->SrceStream(); // non-error responses from receiver
        $doSendLoop = TRUE;
        $nlDone = '-';  // initial value
        $nlTried = '-';
        $oReadout->StartClock();  // reset the time counter
        $ok = TRUE;
        $okErrs = FALSE;
        $didWait = $doWait;
        $nStart = time();   // start timeout timer
        $sRecd = '';
        $sXtraMsg = '';
        $isEOS = FALSE;
        $isTimeOut = FALSE;
        while ($ok && $doWait) {

            // READ input stream
            $oOpDat = $qrSrcePipe->PullBytes(self::IBUFF_SIZE);  // read everything from source; wait if empty

            $ok = $oOpDat->GetOkay();
            $okSrce = $ok;
            if ($ok) {
                // Request successful, so there may be data.

                $qsDat = $oOpDat->QData();  // Any data?
                if ($qsDat->HasIt()) {
                    // Yes -- got some actual bytes.

                    $nStart = time();   // got data, so reset timeout
                    $sToSend = $qsDat->GetIt(); // add received data to what we're sending to the Destination
                    $sRecd .= $sToSend;
                    $nToSend = strlen($sToSend);
                    $nSent = $oDest->PushBytes($sToSend);

                    $sXtraMsg = 'bytes: '.$oReadout->FormatOfInt()->format($oDest->NPulledBytes());
                    $ofLogIO->WriteEntry("PipeToStream (bytes sent=[$nSent of $nToSend]): $sToSend");
                }
                if (!$qrSrcePipe->MoreBytes()) {
                    $doWait = FALSE;  // no need to keep waiting: nothing more to fetch
                    $isEOS = TRUE;    // End-of-Stream reached
                    // TODO 2026-01-04 Make some use of this information in the return status.
                } else {
                    // Time-out if I/O hangs for more than TIMEOUT_SEC seconds:
                    $doWait = (time() <= ($nStart+self::TIMEOUT_SEC));    // turns off after TIMEOUT_SEC seconds of no data
                    $isTimeOut = !$doWait;
                }
            }

            // READ error stream
            $oOpErr = $qrErrsPipe->PullBytes(self::IBUFF_SIZE);   // read everything from error-pipe, don't wait if no errors

            $qsErr = $oOpErr->QData();
            if ($qsErr->HasIt() && ($qsErr->Length() > 0)) {
                $sErr = $qsErr->GetIt();

                /* 2026-01-01 Maybe we need to parse the message here, so we know whether to quit?
                echo CRLF.$oScrn->ErrorIt('Received Error Message').': '.$sErr.CRLF;
                $ok = FALSE;
                $okErrs = FALSE;
                */

                $oOpDat->AddMsgString($sErr);
            }
            $oReadout->Message($sXtraMsg);
            $oReadout->OnStatusChange();
        }
        echo CRLF;  // done with readout line

        if ($isTimeOut) {
            echo $oScrn->YellowIt('Note').': timed out waiting for response.'.CRLF;
        }
        if (!$ok) {
            if (!$okSrce) {
                echo $oScrn->ErrorIt('Error').': There was some kind of problem receiving from the stream.'.CRLF;
            }
            if (!$okErrs) {
                echo 'There was also an error message.'.CRLF;
            }
        }

        $oOpDat->QData()->SetIt($sRecd); // Return accumulated response.
        return $oOpDat; // 2025-12-26 Q&D kluge
    }
    // ACTION: Write from the given stream to the given pipe resource.
    protected function StreamToPipe_DEPRECATED(BufferIface $oData, $rPipe) {
        $ofLogIO = self::LogFile()->InOut();  // logfile for debugging

        // Process the stream in a loop
        $oData->Open();
        while ($oData->IsMore()) {
            // Time-out if I/O hangs for more than 5 seconds:
            #$ok = set_time_limit(5); // NOTE: seems to always return FALSE
            $sPiece = $oData->RemoveBytes();
            // WORKING HERE
            $this->AmHere('WORKING HERE - not complete!');
            $ok = fwrite($rPipe,$sPiece);   // TODO: this should check $ok to make sure it wrote the entire buffer -- remaining part needs to be sent again
            $ofLogIO->WriteEntry("StreamToPipe (ok=[$ok]): $sPiece");
            if ($ok === FALSE) {
                $this->AmHere('TODO: handle write error');
            } elseif($ok !== strlen($sPiece)) {
                $nlDone = $ok;
                $nlPiece = strlen($sPiece);
                #$this->AmHere("TODO: handle incomplete write (sent: $nlPiece actual: $ok)");
                $sRem = substr($sPiece,$nlDone);
                $oSrceBuff->RestoreBytes($sRem);
            } else {
                $this->AmHere('TODO: handle whatever is supposed to happen here.');
            }
        }
        $oData->Shut();
    }

2026-01-14

Removed 2026-01-07:

#
    // 2026-01-07 old API
    static public function FromCommand(string|array $sa) : SelfIface {
        $oThis = new static;
        $oThis->SetCommand($sa);
        return $oThis;
    }
#
    // 2026-01-07 old API
    private $saCmd = NULL;
    protected function SetCommand(string|array $sa) { $this->saCmd = $sa; }
    protected function GetCommand() : string|array { return $this->saCmd; }

2025-12-13

Removed 2025-12-08:

#
    // 2025-12-08 moved to APipes
    protected function BlockPipes(bool $bBlock) : int {
        $ar = $this->arPipes;
        $n = 0;
        foreach ($ar as $rPipe) {
            $ok = stream_set_blocking($rPipe,$bBlock);
            if ($ok) $n++;
        }
        return $n;
    }
    protected function ShutPipes() : int {
        $ar = $this->arPipes;
        $n = 0;
        foreach ($ar as $rPipe) {
            $ok = fclose($rPipe);
            if ($ok) $n++;
        }
        return $n;
    }
    protected function CountOpenPipes() : int {
        $ar = $this->arPipes;
        $n = 0;
        foreach ($ar as $ndx => $rPipe) {
            $arStat = fstat($rPipe);
            if (is_array($arStat)) {
                $n++;
            } else {
                echo "PIPE #$ndx is closed.".CRLF;
            }
        }
        return $n;
    }

Removed because the array is now in IO\Aspect\Connx\aux\APipes:

#
    private $arPipes;
    protected function DestRsrc() : mixed { return $this->arPipes[0]; } // was IPipe (WRITE to this)
    protected function SrceRsrc() : mixed { return $this->arPipes[1]; } // was SrcePipe (READ from this)
    protected function ErrsRsrc() : mixed { return $this->arPipes[2]; } // was EPipe (READ from this)

Removed 2025-11-29:

#
    // 2025-11-29 upgrading to QObj
    private $oBufRecv = NULL;
    public function SetRecvBuff(BufferIface $o) { $this->oBufRecv = $o; }
    protected function GetRecvBuff() : BufferIface { return $this->oBufRecv; }

    private $oBufSend = NULL;
    public function SetSendBuff(BufferIface $o) { $this->oBufSend = $o; }
    protected function GetSendBuff() : BufferIface { return $this->oBufSend; }

2025-06-02

Commented out awhile ago:

#
    static public function FromBuffers(BufferIface $oRecv, ?BufferIface $oSend=NULL) : iProcess {
        $oThis = new static;
        $oThis->SetRecvBuff($oRecv);
        if (is_object($oSend)) {
            $oThis->SetSendBuff($oSend);
        }
        return $oThis;
    }