Esempio n. 1
1
int main(){
    Poco::RWLock lock;
    Task task1(1, &lock);
    Task task2(2, &lock);
    Poco::ThreadPool pool;
    pool.start(task1);
    pool.start(task2);
    pool.joinAll();
    return 0;
}
Esempio n. 2
1
	int main(const std::vector<std::string>& args)
	{
		if(_helpRequested)
		{
			displayHelp();
		}
		else
		{
			/// get parameters from configuration file
			core::server().conf().name(config().getRawString("HTTPWebServer.name", core::server().conf().name()));
			core::server().conf().url(config().getRawString("HTTPWebServer.url", core::server().conf().url()));
			core::server().conf().portUPnP((std::uint16_t)config().getInt("HTTPWebServer.portUPnP", core::server().conf().portUPnP()));
			core::server().conf().port((std::uint16_t)config().getInt("HTTPWebServer.port", core::server().conf().port()));
			core::server().conf().timeOut(config().getInt("HTTPWebServer.timeOut", core::server().conf().timeOut()));
			core::server().conf().lifeTime(config().getInt("HTTPWebServer.lifeTime", core::server().conf().lifeTime()));
			core::server().conf().changeIdTimeOut(config().getInt("HTTPWebServer.changeIdTimeOut", core::server().conf().changeIdTimeOut()));
			core::server().conf().activationTimeOut(config().getInt("HTTPWebServer.activationTimeOut", core::server().conf().activationTimeOut()));
			core::server().conf().https(config().getBool("HTTPWebServer.https", core::server().conf().https()));
			core::server().conf().defaultPage(config().getRawString("HTTPWebServer.defaultPage", core::server().conf().defaultPage()));
			core::server().conf().dateFormat(config().getRawString("HTTPWebServer.dateFormat", core::server().conf().dateFormat()));
			core::server().conf().dateTimeZone((std::int32_t)config().getInt("HTTPWebServer.dateTimeZone", core::server().conf().dateTimeZone()));

			/// Sql database connection
			core::server().conf().sqlConnector(config().getRawString("HTTPWebServer.sql.connector", core::server().conf().sqlConnector()));
			core::server().conf().sqlConnectionString(config().getRawString("HTTPWebServer.sql.connectionString", core::server().conf().sqlConnectionString()));
			core::server().conf().sqlMinSessions((std::int32_t)config().getInt("HTTPWebServer.sql.minSessions", core::server().conf().sqlMinSessions()));
			core::server().conf().sqlMaxSessions((std::int32_t)config().getInt("HTTPWebServer.sql.maxSessions", core::server().conf().sqlMaxSessions()));
			core::server().conf().sqlIdleTime((std::int32_t)config().getInt("HTTPWebServer.sql.idleTime", core::server().conf().sqlIdleTime()));

			printff("sqlConnector='%s'\n", core::server().conf().sqlConnector().c_str());
			printff("sqlConnectionString='%s'\n", core::server().conf().sqlConnectionString().c_str());

			/// get mail parameters for user verification emails
			core::server().conf().smtpHost(config().getRawString("HTTPWebServer.smtp.host", core::server().conf().smtpHost()));
			core::server().conf().smtpPort((std::uint16_t)config().getInt("HTTPWebServer.smtp.port", core::server().conf().smtpPort()));
			core::server().conf().smtpUsername(config().getRawString("HTTPWebServer.smtp.username", core::server().conf().smtpUsername()));
			core::server().conf().smtpPassword(config().getRawString("HTTPWebServer.smtp.password", core::server().conf().smtpPassword()));

			/// emoticons
			std::uint32_t emoticonIndex = 1;
			for(std::string val; !(val=config().getRawString("HTTPWebServer.emoticon" +
					std::to_string(emoticonIndex), "")).empty(); ++emoticonIndex)
			{
				const char *name = val.c_str(), *comma = strstr(name, ","), *src = comma + 1;
				if(comma) core::server().conf().emoticon(std::string(name, comma - name), src);
			}

			/// define controller and service classes
			core::server().creator(new core::Creator<ctrl::Controller, model::Service>());

			/// this code tries to open default page in firefox
			LocalHostTest localHostTest;
			Poco::ThreadPool threadpool;
			if(config().getBool("HTTPWebServer.testLocalhost", false))
				threadpool.start(localHostTest);

			/// set-up a server socket
			std::unique_ptr<ServerSocket> svs(std::unique_ptr<ServerSocket>(core::server().conf().https() ?
				new SecureServerSocket(core::server().conf().port()) : new ServerSocket(core::server().conf().port()) ));
			/// set-up a HTTPServer instance
			HTTPServer srv(new WebServerHandlerFactory, *svs, new HTTPServerParams);
			/// start the HTTPServer
			srv.start();
			/// wait for CTRL-C or kill
			waitForTerminationRequest();
			/// Stop the HTTPServer
			srv.stop();
		}
		return Application::EXIT_OK;
	}
Esempio n. 3
0
TCPServerDispatcher::TCPServerDispatcher(TCPServerConnectionFactory::Ptr pFactory, Poco::ThreadPool& threadPool, TCPServerParams::Ptr pParams):
	_rc(1),
	_pParams(pParams),
	_currentThreads(0),
	_totalConnections(0),
	_currentConnections(0),
	_maxConcurrentConnections(0),
	_refusedConnections(0),
	_stopped(false),
	_pConnectionFactory(pFactory),
	_threadPool(threadPool)
{
	poco_check_ptr (pFactory);

	if (!_pParams)
		_pParams = new TCPServerParams;
	
	if (_pParams->getMaxThreads() == 0)
		_pParams->setMaxThreads(threadPool.capacity());
}