开发者

boost pion comet-like httpserver

I'm trying to efficiently implement comet-like functionality using HTTPServer class of boost::pio开发者_如何学Cn.

Basically, in my 'handleURI' function, I would like to postpone returning results to the client, until the server is ready to respond (for instance, until another user has sent a message to the first user, to use a simple comet 'hello world' application).

What should I do? Put the state on the stack, and exit silently, without creating a HTTPResponseWriter?

Cheers!


Setup a timeout ASIO event for your connection so that you can reap the connection after 20min or something reasonable like that. I don't know about Boost Pion, but in ASIO you'd want to register a read handler that catches when the connection closes and a timeout handler to alert you for when the connection has actually timed out. Enable TCP keep alives on your socket to detect when the socket should be reaped in the event that it just vanishes (though tcp keep alives aren't a guarantee so don't rely exclusively on them - not all clients support tcp keep alives). As for the timer, check out the following timer example:

https://github.com/sean-/Boost.Examples/blob/master/asio/timer/timer.cc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜