Thread: [Cppcms-users] comet question
Brought to you by:
artyom-beilis
From: Frank E. <fra...@an...> - 2010-07-13 13:19:49
|
hi, i try to build the example from the blogpost http://art-blog.no-ip.info/cppcms/blog/post/47 and i'm kind of stuck. the example seems not to be really compatible with the current cppcms version. i adapted the source as follows: class lpTest : public cppcms::application { public: lpTest(cppcms::service &srv) : cppcms::application(srv) { dispatcher().assign("^/postMessage$", &lpTest::postMessage, this); dispatcher().assign("^/consumeMessage/(\\d+)$", &lpTest::consumeMessage, this, 1); } void postMessage() { if(request().request_method() == "POST") { if(request().post().find("message") != request().post().end()) { messages.push_back(request().post().find("message")->second); broadcast(); } } release_context()->async_complete_response(); } void consumeMessage(std::string id) { unsigned pos = atoi(id.c_str()); if(pos < messages.size()) { response().set_plain_text_header(); response().out() << messages[pos]; release_context()->async_complete_response(); } else if(pos == messages.size()) { waiters.push_back(release_context()); } else { response().status(404); release_context()->async_complete_response(); } } void broadcast() { // send the message to all waiters for(unsigned i=0; i<waiters.size(); i++) { waiters[i]->response().set_plain_text_header(); waiters[i]->response().out() << messages.back(); waiters[i]->async_complete_response(); } waiters.clear(); } private: std::vector<std::string> messages; std::vector<booster::shared_ptr<cppcms::http::context> > waiters; }; and for main: cppcms::service srv(argc, argv); booster::intrusive_ptr<lpTest> app = new lpTest(srv); srv.applications_pool().mount(app); srv.run(); as far as i understand this should work. my problem is that if i start the application and do a request it gives me the following exception: Catched excepion [Access to unassigned context] (.../http_context.cpp:144) it seems like the framework tries to do something with the context though it has been released by release_context() - what am i missing? frank |
From: Artyom <art...@ya...> - 2010-07-13 13:59:37
|
Hi, I've tested your code and it mostly works. Also I don't see any "Access to unassigned context" errors The only problem is that you need to add "response().finalize();" before calling async_complete_response() in case you do not write anything to output (i.e. not accessed to out()) I've updated the blog post. About unassigned context - what version of CppCMS are you using. - In what case it happens (which URL is accessed and in what method)? This exception is thrown in case you try to use any request/response related information after calling release_context(), do you call any functions after release_context() In what location the exception is thrown? Artyom See where to add finalize() in the code below. > > i try to build the example from the blogpost > > http://art-blog.no-ip.info/cppcms/blog/post/47 > > and i'm kind of stuck. the example seems not to be really compatible > with the current cppcms version. i adapted the source as follows: > > class lpTest : public cppcms::application { > public: > lpTest(cppcms::service &srv) : > cppcms::application(srv) { > > dispatcher().assign("^/postMessage$", > &lpTest::postMessage, this); > dispatcher().assign("^/consumeMessage/(\\d+)$", > &lpTest::consumeMessage, this, 1); > } > > void postMessage() { > if(request().request_method() == "POST") { > if(request().post().find("message") != request().post().end()) { > messages.push_back(request().post().find("message")->second); > broadcast(); > } > } > NEED response().finalize() THERE > release_context()->async_complete_response(); > } > > void consumeMessage(std::string id) { > unsigned pos = atoi(id.c_str()); > > if(pos < messages.size()) { > response().set_plain_text_header(); > response().out() << messages[pos]; > release_context()->async_complete_response(); > } else if(pos == messages.size()) { > waiters.push_back(release_context()); > } else { > response().status(404); NEED response().finalize() THERE > release_context()->async_complete_response(); > } > } > > void broadcast() { > // send the message to all waiters > for(unsigned i=0; i<waiters.size(); i++) { > waiters[i]->response().set_plain_text_header(); > waiters[i]->response().out() << messages.back(); > waiters[i]->async_complete_response(); > } > > waiters.clear(); > } > > private: > std::vector<std::string> messages; > std::vector<booster::shared_ptr<cppcms::http::context> > waiters; > }; > > and for main: > > cppcms::service srv(argc, argv); > booster::intrusive_ptr<lpTest> app = new lpTest(srv); > srv.applications_pool().mount(app); > srv.run(); > > as far as i understand this should work. my problem is that if i start > the application and do a request it gives me the following exception: > > Catched excepion [Access to unassigned context] (.../http_context.cpp:144) > > it seems like the framework tries to do something with the context > though it has been released by release_context() - what am i missing? > > frank > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Frank E. <fra...@an...> - 2010-07-13 14:16:33
|
hi, i added the finalize calls. - i use cppcms from svn (revision 1314) - it happens when i try to access the url for postMessage or consumeMessage using chrome (or i guess any other browser) the application runs in scgi mode behind nginx. could this be the problem? frank. Am 13.07.2010 15:59, schrieb Artyom: > Hi, > > I've tested your code and it mostly works. > > Also I don't see any "Access to unassigned context" errors > > The only problem is that you need to add "response().finalize();" before calling > async_complete_response() in case you do not write anything to output (i.e. not > accessed to out()) > > I've updated the blog post. > > About unassigned context > > - what version of CppCMS are you using. > - In what case it happens (which URL is accessed and in what method)? > > This exception is thrown in case you try to use any request/response related > information > after calling release_context(), do you call any functions after > release_context() > In what location the exception is thrown? > > Artyom > > See where to add finalize() in the code below. > > >> >> i try to build the example from the blogpost >> >> http://art-blog.no-ip.info/cppcms/blog/post/47 >> >> and i'm kind of stuck. the example seems not to be really compatible >> with the current cppcms version. i adapted the source as follows: >> >> class lpTest : public cppcms::application { >> public: >> lpTest(cppcms::service &srv) : >> cppcms::application(srv) { >> >> dispatcher().assign("^/postMessage$", >> &lpTest::postMessage, this); >> dispatcher().assign("^/consumeMessage/(\\d+)$", >> &lpTest::consumeMessage, this, 1); >> } >> >> void postMessage() { >> if(request().request_method() == "POST") { >> if(request().post().find("message") != request().post().end()) { >> messages.push_back(request().post().find("message")->second); >> broadcast(); >> } >> } >> > > NEED response().finalize() THERE > >> release_context()->async_complete_response(); >> } >> >> void consumeMessage(std::string id) { >> unsigned pos = atoi(id.c_str()); >> >> if(pos < messages.size()) { >> response().set_plain_text_header(); >> response().out() << messages[pos]; >> release_context()->async_complete_response(); >> } else if(pos == messages.size()) { >> waiters.push_back(release_context()); >> } else { >> response().status(404); > > NEED response().finalize() THERE > >> release_context()->async_complete_response(); >> } >> } >> >> void broadcast() { >> // send the message to all waiters >> for(unsigned i=0; i<waiters.size(); i++) { >> waiters[i]->response().set_plain_text_header(); >> waiters[i]->response().out() << messages.back(); >> waiters[i]->async_complete_response(); >> } >> >> waiters.clear(); >> } >> >> private: >> std::vector<std::string> messages; >> std::vector<booster::shared_ptr<cppcms::http::context> > waiters; >> }; >> >> and for main: >> >> cppcms::service srv(argc, argv); >> booster::intrusive_ptr<lpTest> app = new lpTest(srv); >> srv.applications_pool().mount(app); >> srv.run(); >> >> as far as i understand this should work. my problem is that if i start >> the application and do a request it gives me the following exception: >> >> Catched excepion [Access to unassigned context] (.../http_context.cpp:144) >> >> it seems like the framework tries to do something with the context >> though it has been released by release_context() - what am i missing? >> >> frank >> >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by Sprint >> What will you do first with EVO, the first 4G phone? >> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first >> _______________________________________________ >> Cppcms-users mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cppcms-users >> > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users -- Dipl.-Ing. (FH) Frank Enderle anamica UG (haftungsbeschränkt) Beinsteinerstr. 6 71334 Waiblingen Telefon: +49 151 14981091 Telefax: +49 7151 1335770 E-Mail: fra...@an... Internet: www.anamica.de Handelsregister: AG Stuttgart HRB 732357 Geschäftsführer: Yvonne Holzwarth, Frank Enderle |
From: Artyom <art...@ya...> - 2010-07-13 15:01:10
|
Hello, Ok, there was a bug, fixed in changeset 1315, take update from svn. Now should work. It happened after some code re-factoring that was done recently. Artyom > From: Frank Enderle <fra...@an...> > > hi, > > i added the finalize calls. > > - i use cppcms from svn (revision 1314) > - it happens when i try to access the url for postMessage or > consumeMessage using chrome (or i guess any other browser) > > the application runs in scgi mode behind nginx. could this be the problem? > > frank. > > Am 13.07.2010 15:59, schrieb Artyom: > > Hi, > > > > I've tested your code and it mostly works. > > > > Also I don't see any "Access to unassigned context" errors > > > > The only problem is that you need to add "response().finalize();" before >calling > > async_complete_response() in case you do not write anything to output (i.e. >not > > > accessed to out()) > > > > I've updated the blog post. > > > > About unassigned context > > > > - what version of CppCMS are you using. > > - In what case it happens (which URL is accessed and in what method)? > > > > This exception is thrown in case you try to use any request/response related > > > information > > after calling release_context(), do you call any functions after > > release_context() > > In what location the exception is thrown? > > > > Artyom > > > > See where to add finalize() in the code below. > > > > > >> > >> i try to build the example from the blogpost > >> > >> http://art-blog.no-ip.info/cppcms/blog/post/47 > >> > >> and i'm kind of stuck. the example seems not to be really compatible > >> with the current cppcms version. i adapted the source as follows: > >> > >> class lpTest : public cppcms::application { > >> public: > >> lpTest(cppcms::service &srv) : > >> cppcms::application(srv) { > >> > >> dispatcher().assign("^/postMessage$", > >> &lpTest::postMessage, this); > >> dispatcher().assign("^/consumeMessage/(\\d+)$", > >> &lpTest::consumeMessage, this, 1); > >> } > >> > >> void postMessage() { > >> if(request().request_method() == "POST") { > >> if(request().post().find("message") != request().post().end()) { > >> messages.push_back(request().post().find("message")->second); > >> broadcast(); > >> } > >> } > >> > > > > NEED response().finalize() THERE > > > >> release_context()->async_complete_response(); > >> } > >> > >> void consumeMessage(std::string id) { > >> unsigned pos = atoi(id.c_str()); > >> > >> if(pos < messages.size()) { > >> response().set_plain_text_header(); > >> response().out() << messages[pos]; > >> release_context()->async_complete_response(); > >> } else if(pos == messages.size()) { > >> waiters.push_back(release_context()); > >> } else { > >> response().status(404); > > > > NEED response().finalize() THERE > > > >> release_context()->async_complete_response(); > >> } > >> } > >> > >> void broadcast() { > >> // send the message to all waiters > >> for(unsigned i=0; i<waiters.size(); i++) { > >> waiters[i]->response().set_plain_text_header(); > >> waiters[i]->response().out() << messages.back(); > >> waiters[i]->async_complete_response(); > >> } > >> > >> waiters.clear(); > >> } > >> > >> private: > >> std::vector<std::string> messages; > >> std::vector<booster::shared_ptr<cppcms::http::context> > waiters; > >> }; > >> > >> and for main: > >> > >> cppcms::service srv(argc, argv); > >> booster::intrusive_ptr<lpTest> app = new lpTest(srv); > >> srv.applications_pool().mount(app); > >> srv.run(); > >> > >> as far as i understand this should work. my problem is that if i start > >> the application and do a request it gives me the following exception: > >> > >> Catched excepion [Access to unassigned context] >(.../http_context.cpp:144) > >> > >> it seems like the framework tries to do something with the context > >> though it has been released by release_context() - what am i missing? > >> > >> frank > >> > >> > >> >------------------------------------------------------------------------------ > >> This SF.net email is sponsored by Sprint > >> What will you do first with EVO, the first 4G phone? > >> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > >> _______________________________________________ > >> Cppcms-users mailing list > >> Cpp...@li... > >> https://lists.sourceforge.net/lists/listinfo/cppcms-users > >> > > > > > > > > > > >------------------------------------------------------------------------------ > > This SF.net email is sponsored by Sprint > > What will you do first with EVO, the first 4G phone? > > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > > _______________________________________________ > > Cppcms-users mailing list > > Cpp...@li... > > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > -- > Dipl.-Ing. (FH) Frank Enderle > > anamica UG (haftungsbeschränkt) > Beinsteinerstr. 6 > 71334 Waiblingen > > Telefon: +49 151 14981091 > Telefax: +49 7151 1335770 > E-Mail: fra...@an... > Internet: www.anamica.de > > Handelsregister: AG Stuttgart HRB 732357 > Geschäftsführer: Yvonne Holzwarth, Frank Enderle > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Frank E. <fra...@an...> - 2010-07-13 15:05:47
|
hi, the exception is now gone. thanks. frank. Am 13.07.2010 17:00, schrieb Artyom: > Hello, > > Ok, there was a bug, fixed in changeset 1315, take update from svn. > Now should work. It happened after some code re-factoring that was done > recently. > > Artyom > > > > >> From: Frank Enderle <fra...@an...> >> >> hi, >> >> i added the finalize calls. >> >> - i use cppcms from svn (revision 1314) >> - it happens when i try to access the url for postMessage or >> consumeMessage using chrome (or i guess any other browser) >> >> the application runs in scgi mode behind nginx. could this be the problem? >> >> frank. >> >> Am 13.07.2010 15:59, schrieb Artyom: >>> Hi, >>> >>> I've tested your code and it mostly works. >>> >>> Also I don't see any "Access to unassigned context" errors >>> >>> The only problem is that you need to add "response().finalize();" before >> calling >>> async_complete_response() in case you do not write anything to output (i.e. >> not >> >>> accessed to out()) >>> >>> I've updated the blog post. >>> >>> About unassigned context >>> >>> - what version of CppCMS are you using. >>> - In what case it happens (which URL is accessed and in what method)? >>> >>> This exception is thrown in case you try to use any request/response related >> >>> information >>> after calling release_context(), do you call any functions after >>> release_context() >>> In what location the exception is thrown? >>> >>> Artyom >>> >>> See where to add finalize() in the code below. >>> >>> >>>> >>>> i try to build the example from the blogpost >>>> >>>> http://art-blog.no-ip.info/cppcms/blog/post/47 >>>> >>>> and i'm kind of stuck. the example seems not to be really compatible >>>> with the current cppcms version. i adapted the source as follows: >>>> >>>> class lpTest : public cppcms::application { >>>> public: >>>> lpTest(cppcms::service &srv) : >>>> cppcms::application(srv) { >>>> >>>> dispatcher().assign("^/postMessage$", >>>> &lpTest::postMessage, this); >>>> dispatcher().assign("^/consumeMessage/(\\d+)$", >>>> &lpTest::consumeMessage, this, 1); >>>> } >>>> >>>> void postMessage() { >>>> if(request().request_method() == "POST") { >>>> if(request().post().find("message") != request().post().end()) { >>>> messages.push_back(request().post().find("message")->second); >>>> broadcast(); >>>> } >>>> } >>>> >>> >>> NEED response().finalize() THERE >>> >>>> release_context()->async_complete_response(); >>>> } >>>> >>>> void consumeMessage(std::string id) { >>>> unsigned pos = atoi(id.c_str()); >>>> >>>> if(pos < messages.size()) { >>>> response().set_plain_text_header(); >>>> response().out() << messages[pos]; >>>> release_context()->async_complete_response(); >>>> } else if(pos == messages.size()) { >>>> waiters.push_back(release_context()); >>>> } else { >>>> response().status(404); >>> >>> NEED response().finalize() THERE >>> >>>> release_context()->async_complete_response(); >>>> } >>>> } >>>> >>>> void broadcast() { >>>> // send the message to all waiters >>>> for(unsigned i=0; i<waiters.size(); i++) { >>>> waiters[i]->response().set_plain_text_header(); >>>> waiters[i]->response().out() << messages.back(); >>>> waiters[i]->async_complete_response(); >>>> } >>>> >>>> waiters.clear(); >>>> } >>>> >>>> private: >>>> std::vector<std::string> messages; >>>> std::vector<booster::shared_ptr<cppcms::http::context> > waiters; >>>> }; >>>> >>>> and for main: >>>> >>>> cppcms::service srv(argc, argv); >>>> booster::intrusive_ptr<lpTest> app = new lpTest(srv); >>>> srv.applications_pool().mount(app); >>>> srv.run(); >>>> >>>> as far as i understand this should work. my problem is that if i start >>>> the application and do a request it gives me the following exception: >>>> >>>> Catched excepion [Access to unassigned context] >> (.../http_context.cpp:144) >>>> >>>> it seems like the framework tries to do something with the context >>>> though it has been released by release_context() - what am i missing? >>>> >>>> frank >>>> >>>> >>>> >> ------------------------------------------------------------------------------ >>>> This SF.net email is sponsored by Sprint >>>> What will you do first with EVO, the first 4G phone? >>>> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first >>>> _______________________________________________ >>>> Cppcms-users mailing list >>>> Cpp...@li... >>>> https://lists.sourceforge.net/lists/listinfo/cppcms-users >>>> >>> >>> >>> >>> >>> >> ------------------------------------------------------------------------------ >>> This SF.net email is sponsored by Sprint >>> What will you do first with EVO, the first 4G phone? >>> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first >>> _______________________________________________ >>> Cppcms-users mailing list >>> Cpp...@li... >>> https://lists.sourceforge.net/lists/listinfo/cppcms-users >> >> >> -- >> Dipl.-Ing. (FH) Frank Enderle >> >> anamica UG (haftungsbeschränkt) >> Beinsteinerstr. 6 >> 71334 Waiblingen >> >> Telefon: +49 151 14981091 >> Telefax: +49 7151 1335770 >> E-Mail: fra...@an... >> Internet: www.anamica.de >> >> Handelsregister: AG Stuttgart HRB 732357 >> Geschäftsführer: Yvonne Holzwarth, Frank Enderle >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by Sprint >> What will you do first with EVO, the first 4G phone? >> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first >> _______________________________________________ >> Cppcms-users mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cppcms-users >> > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users -- Dipl.-Ing. (FH) Frank Enderle anamica UG (haftungsbeschränkt) Beinsteinerstr. 6 71334 Waiblingen Telefon: +49 151 14981091 Telefax: +49 7151 1335770 E-Mail: fra...@an... Internet: www.anamica.de Handelsregister: AG Stuttgart HRB 732357 Geschäftsführer: Yvonne Holzwarth, Frank Enderle |