by grepular · 12y ago · 0 comments
CROW_ROUTE(app, "/about")
([](Response res){
res.send("About Crow example");
});
Why you might ask? So you can do this: CROW_ROUTE(app, "/about")
([](Response res){
responses.push_back(res);
});
And then some independent method could come along and do the res.send() when it is ready. The connection would hang until res.send() or similar is called on it. There would also be methods on the Response object so you can see if the connection is still alive etc, and maybe the ability to set timeouts directly on the Response object.[edit] This would allow people using your framework to implement long polling without locking up an io_service thread for each connection. It would also make it easier to add support for web sockets etc at a later date.
[edit2] This is how NodeJS works. Both a request and a response object is passed to the callback, then you can do for example:
function callback (req, res) {
setTimeout(function(){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}, 5000);
}I think supporting both way is better if there is a enough explanation. I don't want to drop a simpler way to do the same job.
CROW_ROUTE(app, "/about")
([](){
return "About Crow example";
});
CROW_ROUTE(app, "/about")
([](Response res){
res.send("About Crow example");
});Also, you said this adds complexity and overhead. I dispute that it adds complexity. For most people: "return stuff" vs "res.send(stuff)". And I wouldn't assume that it would add any overhead either. If you disagree, let me know when you've read the code and understand how boost::asio works.
The difference is a big reason why Apache 2.2 would slow to a crawl and eat up gigabytes of RAM at 100% processor utilization on the same load that Nginx could handle with 10Mb of RAM and 20% processor utilization. [1] (I understand more recent versions of Apache now support polling [2].)
[1] See, for example, this explanation: http://stackoverflow.com/questions/2583350/is-epoll-the-esse...