X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2Fspush%2Fbrisk-spush.phh;h=e9382ddf4cb5c166ff1a530111b70f3353f3e4c3;hb=0e17eb7ed18d621be70d7890f531a2dc1cab2a42;hp=00380385223dc47abede9844fb3a37e1e55dfa91;hpb=d96c30d2cdb27c9314474b8902f70fe69d88119b;p=brisk.git diff --git a/web/spush/brisk-spush.phh b/web/spush/brisk-spush.phh index 0038038..e9382dd 100644 --- a/web/spush/brisk-spush.phh +++ b/web/spush/brisk-spush.phh @@ -24,4 +24,58 @@ $DOCUMENT_ROOT=""; $HTTP_HOST="dodo.birds.lan"; -?> \ No newline at end of file +define('USOCK_PATH', "/tmp/brisk.sock"); + +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, $enc, $curtime, $kalive, $header_out, $body) + { + printf("TRY FLUSH CREATE\n"); + $body_out = ZLibStream::compress($enc, $body); + if ($enc != 'plain') + $header_out['Content-Encoding'] = $enc; + $body_out_sz = mb_strlen($body_out, "ASCII"); + $hea = headers_render($header_out, $body_out_sz); + $hea_sz = mb_strlen($hea, "ASCII"); + + $this->socket = $socket; + $this->kalive = $curtime + $kalive; + $this->msg = $hea.$body_out; + $this->msg_sz = $hea_sz + $body_out_sz; + } + + /* return TRUE if is removable from it's list */ + function try_flush($curtime) + { + printf("TRY FLUSH IN\n"); + if ($this->kalive < $curtime) { + printf("TRY FLUSH CLOSE 1\n"); + fclose($this->socket); + return TRUE; + } + + $wret = @fwrite($this->socket, $this->msg); + if ($wret == FALSE && $wret !== FALSE) { + printf("TRY FLUSH PageFlush::try_flush: wret 0 but not FALSE\n"); + } + if ($wret == $this->msg_sz) { + printf("TRY FLUSH CLOSE 2\n"); + fclose($this->socket); + return TRUE; + } + $this->msg_sz -= $wret; + $this->msg = mb_substr($this->msg, $wret, $this->msg_sz, "ASCII"); + + printf("TRY FLUSH RETURN FALSE\n"); + + return FALSE; + } + +} + +?>