Browse Source

Added option for manual output stream control

master
Artyom Beilis 15 years ago
parent
commit
ce778da239
6 changed files with 48 additions and 1 deletions
  1. +1
    -0
      application.h
  2. +26
    -0
      hello_world.cpp
  3. +4
    -0
      session_interface.cpp
  4. +2
    -1
      session_interface.h
  5. +13
    -0
      worker_thread.cpp
  6. +2
    -0
      worker_thread.h

+ 1
- 0
application.h View File

@@ -31,6 +31,7 @@ struct application {
void set_header(HTTPHeader *h) { worker.set_header(h); }
void add_header(string s) { worker.add_header(s); }
void set_cookie(cgicc::HTTPCookie const &c) { worker.set_cookie(c); }
void set_user_io() { worker.set_user_io(); }

HTTPHeader &header() { return worker.header(); }



+ 26
- 0
hello_world.cpp View File

@@ -13,14 +13,40 @@ public:
url.add("^/test$",boost::bind(&my_hello_world::test,this));
url.add("^/test2$",boost::bind(&my_hello_world::test2,this));
url.add("^/cache$",boost::bind(&my_hello_world::cache_test,this));
url.add("^/png$",boost::bind(&my_hello_world::png,this));
use_template("view2");
};
void test();
void png();
void test2();
void std();
void cache_test();
};

void my_hello_world::png()
{
ifstream file("test.png");
if(!file) {
cout<<"File test.png not found";
return ;
}
vector<char> buffer(1024);
set_user_io();

ostream &cout=cgi_conn->cout();
set_header(new cgicc::HTTPContentHeader("image/png"));
session.save();
cout<<header();

for(;;) {
file.read(&buffer.front(),1024);
cout.write(&buffer.front(),file.gcount());
if(file.eof())
break;
}
file.close();
}


void my_hello_world::test2()
{


+ 4
- 0
session_interface.cpp View File

@@ -94,6 +94,7 @@ bool session_interface::load()
timeout_val=timeout_val_def;
how=how_def;
string ar;
saved=false;
if(!storage.get() || !storage->load(this,ar,timeout_in)) {
return false;
}
@@ -210,6 +211,8 @@ void session_interface::update_exposed()

void session_interface::save()
{
if(saved)
return;
check();
new_session = data_copy.empty() && !data.empty();
if(data.empty()) {
@@ -242,6 +245,7 @@ void session_interface::save()
temp_cookie.clear();

update_exposed();
saved=true;
}

void session_interface::on_start()


+ 2
- 1
session_interface.h View File

@@ -42,13 +42,13 @@ class session_interface : private boost::noncopyable {
// Information from session data
time_t timeout_in;
bool new_session;
bool saved;

int cookie_age();
time_t session_age();

void check();
bool load();
void save();
void update_exposed();

std::string temp_cookie;
@@ -87,6 +87,7 @@ public:
void set_expiration(int h);
void set_age();
void set_expiration();
void save();

// Special interface
void set_session_cookie(std::string const &data);


+ 13
- 0
worker_thread.cpp View File

@@ -50,6 +50,11 @@ void worker_thread::set_cookie(cgicc::HTTPCookie const &c)
response_header->setCookie(c);
}

void worker_thread::set_user_io()
{
user_io=true;
}

void worker_thread::set_lang(string const &s)
{
lang=s;
@@ -80,6 +85,7 @@ void worker_thread::run(cgicc_connection &cgi_conn)
set_header(new HTTPHTMLHeader);

gzip=gzip_done=false;
user_io=false;
string encoding;

if((encoding=cgi_conn.env("HTTP_ACCEPT_ENCODING"))!="") {
@@ -116,6 +122,11 @@ void worker_thread::run(cgicc_connection &cgi_conn)
cgi_out<<*h<<"\n";
}

if(user_io) {
// user controls it's IO
return;
}

string out=out_buf.str();
out_buf.str("");

@@ -170,6 +181,8 @@ void worker_thread::render(string name,base_content &content)
render(current_template,name,content,cout);
};



}




+ 2
- 0
worker_thread.h View File

@@ -41,6 +41,7 @@ class worker_thread: private boost::noncopyable {

list<string> other_headers;
base_cache *caching_module;
bool user_io;
bool gzip;
bool gzip_done;
stringbuf out_buf;
@@ -68,6 +69,7 @@ public:
void set_header(HTTPHeader *h);
void add_header(string s);
void set_cookie(cgicc::HTTPCookie const &c);
void set_user_io();

HTTPHeader &header();



Loading…
Cancel
Save