Re: [Cppcms-users] One SSE stream per session
Brought to you by:
artyom-beilis
|
From: Christian G. <chr...@gm...> - 2013-03-13 14:42:11
|
2013/3/13 Artyom Beilis <art...@ya...>:
>
>
>>________________________________
>> From: Christian Gmeiner <chr...@gm...>
>>
>>Hi all.
>>
>>at the moment I am looking how to have one SSE stream per session. In
>>general I would put the SSE stream object into the session storage but
>>I am not sure how I could access it from other cppcms-apps.
>>
>
> I don't really understand what exactly you are doing as you can't
> store "sse" object in session storage as is - you can probably
> create its unique identification and store it in session object.
>
Maybe I could "store it" in kind of pointer address :)
>
>>Here is brief overview:
>>
>>I have an SSE application mounted at /sse/
>>
>> booster::intrusive_ptr<SSE> sse = new SSE(srv);
>> Configuration::instance()->sse = sse.get();
>> srv.applications_pool().mount(sse, cppcms::mount_point("/sse(.*)", 1));
>>
>>It is possible for all other cppcms apps running to send data via SSE
>>to the browser.
>>
>> Configuration::instance()->sse->enqueue("event", "data");
>>
>>
>
>>class SSE : public cppcms::application {
>>public:
>> SSE(cppcms::service &srv);
>>
>> void post();
>> void get();
>> void redirect();
>>
>> void enqueue(std::string const &event, std::string const &data);
>>
>>private:
>> booster::shared_ptr<sse::bounded_event_queue> stream_;
>>};
>>
>
>
> Yes, however you should remember that SEE object is asynchronous one
> and runs in the event loop stream.
>
> That means that you can't just call sse->enqueue("event","data")
> from synchronous applications from the other thread
> but rather you need to "post" it to event loop's thread:
>
> Using C++11 lambdass:
>
> std::string message = ...;
> service().post([=]() {
> see->equeue("event",message);
> });
>
okay got it...
>>
>
>>
>>At the moment all clients are using the same SSE stream and this is a
>>no-go security wise.
>>So I want to extend my current approach to have multiple SSE streams -
>>for each session one.
>>As this "website" is used for embedded device configuration I think I
>>will not run into any
>>resource problems.
>>
>>Or is there a better way to deliver each session their own data-packages only?
>
>
> Use multiple sse stream object and for each one of them create unique id that
> would be stored in session and thus if user request sse with some id
> give it to him, this way you can even give multiple users same sse stream.
>
Sounds like a good idea. The only thing that comes to my mind is: where to store
the hashmap from key to sse object? Is there a concept for global
available data?
In theory a singleton class/object should to it.
thanks
--
Christian Gmeiner, MSc
|