X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2Fspush%2Fbrisk-spush.phh;h=de6ceba25e575bef341fe49678781b91a3bc58f4;hb=818b1bd911888487f2c217ac84f414d3ec527de5;hp=bc11cca8e4499b427d41f82e4f561f507d3baa52;hpb=a3dd865033d13bc0c1d16128e4f30f647d741ff9;p=brisk.git diff --git a/web/spush/brisk-spush.phh b/web/spush/brisk-spush.phh index bc11cca..de6ceba 100644 --- a/web/spush/brisk-spush.phh +++ b/web/spush/brisk-spush.phh @@ -24,4 +24,48 @@ $DOCUMENT_ROOT=""; $HTTP_HOST="dodo.birds.lan"; + +class PageFlush { + + var $socket; // socket handler of page stream + var $kalive; // if no message are sent after RD_KEEPALIVE_TOUT secs we send a keepalive from server + var $msg; // place where store failed fwrite data + var $msg_sz; // size of content + + function PageFlush($socket, $curtime, $kalive, $header_out, $body) + { + // $body_sz = mb_strlen($body, "ASCII"); + // add length to header_out + $hea = headers_render($header_out); + + $this->socket = $socket; + $this->kalive = $curtime + $kalive; + $this->msg = $hea.$body; + $this->msg_sz = mb_strlen($this->msg, "ASCII"); + } + + /* return TRUE if is removable from it's list */ + function try_flush($curtime) + { + if ($this->kalive < $curtime) { + fclose($this->socket); + return TRUE; + } + + $wret = @fwrite($this->socket, $this->msg); + if ($wret == FALSE && $wret !== FALSE) { + printf("PageFlush::try_flush: wret 0 but not FALSE\n"); + } + if ($wret == $this->msg_sz) { + fclose($this->socket); + return TRUE; + } + $this->msg_sz -= $wret; + $this->msg = mb_substr($this->msg, $wret, $this->msg_sz, "ASCII"); + + return FALSE; + } + +} + ?>