Ferreteria/v0.6/clade/IO/Aspect/Connx/Process/@fx/StreamToPipe

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

About

  • Action: Write from the given stream to the given pipe resource.

Code

As of 2025-12-23:

#
    protected function StreamToPipe(BufferIface $oData, $rPipe) {
        // 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
            $ok = fwrite($rPipe,$sPiece);   // TODO: this should check $ok to make sure it wrote the entire buffer -- remaining part needs to be sent again
            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);
                $oSendBuff->RestoreBytes($sRem);
            } else {
                $this->AmHere('TODO: handle whatever is supposed to happen here.');
            }
        }
        $oData->Shut();
    }