c++ - Connect HTTP thread handlers to SessionPools. -
we using model set in poco-project library documentation. thread/handler spawned every connection http server. want connect each thread shared sessionpoolcontainer(spc). working on assumption should instantiate spc in handlerfactory , give handler reference spc.
class handler: public poco::net::httprequesthandler{ public: handler(sessionpoolcontainer &spc){ //here goes wrong. "spc private." sessionpool sp = spc.getpool("p1"); //todo fetch session once have sessionpool reference. } void handlerequest(poco::net::httpserverrequest& request, poco::net::httpserverresponse& response){ //do stuff. } }; class handlerfactory : public poco::net::httprequesthandlerfactory{ public: sessionpoolcontainer spc; poco::net::httprequesthandler* createrequesthandler(const poco::net::httpserverrequest &request){ poco::data::mysql::connector::registerconnector(); autoptr<sessionpool> p1 = new sessionpool("mysql", "host=127.0.0.1;port=3306;db=testdb2;user=bachelor;password=bachelor;compress=true;auto-reconnect=true"); spc.add(p1); if (request.getcontenttype().compare("application/json")) { return new handler(spc); } } }; class mywebhttpserverapplication : public poco::util::serverapplication{ protected: int main(const std::vector<std::string> &args){ // instanciate handlerfactory poco::net::httpserver server(new handlerfactory(), socket, pparams); server.start(); //sic } };
the error (from 3rd line): /home/notandi/git/poco-1.7.2-all/cmake_install/debug/include/poco/data/sessionpool.h:187:9: error: 'poco::data::sessionpool::sessionpool(const poco::data::sessionpool&)' private sessionpool(const sessionpool&); ^ /home/notandi/qt/mysqlwithpool/main.cpp:68:41: error: within context sessionpool sp = spc.getpool("p");
from i'm sitting needs work , have reference passed around.
i have tried "friend class handler;" in handler no change in status. relevant part of sessionpoolcontainer looks like:
private: typedef std::map<std::string, autoptr<sessionpool>, poco::ciless> sessionpoolmap; sessionpoolcontainer(const sessionpoolcontainer&); sessionpoolcontainer& operator = (const sessionpoolcontainer&); sessionpoolmap _sessionpools; poco::fastmutex _mutex;
do edit , recompile poco sessionpoolcontainer "friend class handler;"? how around or thinking wrong?
from posted code, looks pool container not needed @ because p1
pool never added pool container; so, if compile, spc
contain no session pools; using sessionpoolcontainer makes sense if connecting multiple databases, in case have add session pool pool container:
spc.add(p1);
however, if there no need sessionpoolcontainer, pass reference sessionpool handler , session it:
class handler: public poco::net::httprequesthandler{ public: handler(sessionpool &sp){ session s = sp.get(); } //... };
look @ this code better understanding how use session pools , containers thereof.
Comments
Post a Comment