Re: [Cppcms-users] SSE keep-alive
Brought to you by:
artyom-beilis
|
From: Christian G. <chr...@gm...> - 2013-04-02 16:15:56
|
2013/4/2 Artyom Beilis <art...@ya...>:
> Your code is incorrect, you must not use Mutexes...
>
> Instead of this:
>
>> void push(std::string const &event,std::string const &data,bool
>> send=true)
>> {
>> message msg;
>> msg.event = event;
>> msg.data = data;
>>
>> mutex.lock();
>> messages_.push(msg);
>> mutex.unlock();
>>
>> if(send)
>> broadcast();
>> }
>
>
> That I assume is called form an external thread you need to do something different
>
>
> void thread_safe_push(std::string const &event,std::string const &data)
> { message msg;
> msg.event = event;
> msg.data = data;
>
>
> service().post([=] { (lambda expression)
>
> // EXECUTED IN THE EVENT LOOP THREAD!!!
> messages_.push(msg);
> broadcast();
>
> });
>
> }
>
>
> or without C++11
>
> void thread_safe_push(std::string const &event,std::string const &data)
> { message msg;
> msg.event = event;
> msg.data = data;
>
>
> service().post(boost::bind(&event_fifo::thread_unsef_push,this,msg));
>
> }
>
>
> void thread_unsefe_push(message const &msg)
>
> { messages_.push(msg);
> broadcast();
>
> }
>
Thanks... I got rid of the mutex. Is there a way to renew a session? I
have tried to load() and save() the session during keep alive of the
event stream, but it does not work as expected.
void event_source::keep_alive(char const *comment)
{
if(closing_) {
return;
}
for(streamers_type::iterator
it=streamers_.begin();it!=streamers_.end();) {
booster::intrusive_ptr<details::post_send> ps = *it;
streamers_type::iterator tmp = it++;
streamers_.erase(tmp);
ps->stream().context()->response().out() << ':' <<
comment << "\n\n";
ps->stream().context()->async_flush_output(ps);
ps->stream().context()->session().load();
ps->stream().context()->session().save();
}
...
My current session timeout is set to 10 minutes. If a script gets
executed the GUI in the browser
shows a modal dialog with the output of the executed process - send via SSE.
If the script runs longer then session timeout and gc() gets called
the session will be removed. I want
to renew the session in the keep_alive action of the SSE stream.
greets
--
Christian Gmeiner, MSc
|