author | Michael Krelin <hacker@klever.net> | 2005-03-07 21:04:49 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-03-07 21:04:49 (UTC) |
commit | b0e2dda829db4560e2c0ed7556803124a396b89f (patch) (side-by-side diff) | |
tree | 0f0ef795bd175ea997941b75ef2ed5a3210b267e /lib | |
parent | dd855cb44cb06cf630e4fe9aba09fa2e43a63aed (diff) | |
download | sitecing-b0e2dda829db4560e2c0ed7556803124a396b89f.zip sitecing-b0e2dda829db4560e2c0ed7556803124a396b89f.tar.gz sitecing-b0e2dda829db4560e2c0ed7556803124a396b89f.tar.bz2 |
prebuffering of output is controllable now.
-rw-r--r-- | lib/sitecing_interface_cgi.cc | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/sitecing_interface_cgi.cc b/lib/sitecing_interface_cgi.cc index 5c3d295..f2bd093 100644 --- a/lib/sitecing_interface_cgi.cc +++ b/lib/sitecing_interface_cgi.cc @@ -4,7 +4,7 @@ namespace sitecing { sitecing_interface_cgi::sitecing_interface_cgi(sitespace *s) - : sitecing_interface(&prebuffer), ss(s), cgigw(NULL) { + : outs(&prebuffer), sitecing_interface(&outs), ss(s), cgigw(NULL), headers_flushed(false) { } void sitecing_interface_cgi::prepare(kingate::cgi_gateway *cg) { @@ -12,14 +12,40 @@ namespace sitecing { headers.clear(); headers["Content-Type"] = "text/html"; prebuffer.str(""); + headers_flushed = false; + set_buffering(true); } - void sitecing_interface_cgi::flush() { + void sitecing_interface_cgi::flush(bool keep_buffering) { assert(cgigw); + flush_headers(); + if(is_buffering()) { + streampos count = prebuffer.pubseekoff(0,ios_base::cur,ios_base::out); + cgigw->out().write(prebuffer.str().c_str(),count); + prebuffer.str(""); + } + cgigw->out().flush(); + set_buffering(keep_buffering); + } + + void sitecing_interface_cgi::set_buffering(bool do_buffer) { + if(!do_buffer) + flush_headers(); + outs.rdbuf(do_buffer?&prebuffer:cgigw->out().rdbuf()); + } + + bool sitecing_interface_cgi::is_buffering() { + return outs.rdbuf()==&prebuffer; + } + + void sitecing_interface_cgi::flush_headers() { + assert(cgigw); + if(headers_flushed) + return; for(headers_t::const_iterator i=headers.begin();i!=headers.end();i++) cgigw->out() << i->first << ": " << i->second << "\n"; - (cgigw->out() << "\n").write(prebuffer.str().c_str(),prebuffer.tellp()); - cgigw->out().flush(); + cgigw->out() << "\n"; + headers_flushed = true; } } |