socket = $socket; $this->kalive = $curtime + $kalive; } static function pendingpage_waiting($socket, $curtime, $kalive, $method, $header, $get, $post, $cookie, $path, $addr, $rest) { $thiz = new PendingPage($socket, $curtime, $kalive); $thiz->status = PENDINGPAGE_WAITDATA; $thiz->method = $method; $thiz->header = $header; $thiz->get = $get; $thiz->post = $post; $thiz->cookie = $cookie; $thiz->path = $path; $thiz->addr = $addr; $thiz->contsz = $header['Content-Length']; $thiz->rest = $rest; return ($thiz); } function try_wait($curtime) { // if completed return TRUE to allow data to be processed, // if timeout or max content dimension is exceeded move to flushing } static function pendingpage_flushing($socket, $curtime, $kalive, $enc, $header_out, $body) { $thiz = new PendingPage($socket, $curtime, $kalive); $thiz->to_flushing($enc, $header_out, $body); return ($thiz); } function to_flushing($enc, &$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->status = PENDINGPAGE_FLUSH; $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) { if ($this->status != PENDINGPAGE_FLUSH) return (FALSE); 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 PendingPage::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; } } ?>