Acceptor::Acceptor( boost::asio::io_service& aIOS, const std::string& aAddress, const std::string& aPort, Creator aCreator ) : mAcceptor( aIOS ), mCreator( aCreator ) { // create a resolver, and resolve the address boost::asio::ip::tcp::resolver iResolver( aIOS ); boost::asio::ip::tcp::resolver::query iQuery( aAddress, aPort ); boost::asio::ip::tcp::endpoint iResult = *iResolver.resolve( iQuery ); // prepare the acceptor mAcceptor.open( iResult.protocol() ); mAcceptor.set_option( boost::asio::ip::tcp::acceptor::reuse_address(true) ); mAcceptor.bind( iResult ); // start listening mAcceptor.listen(); // create first connection mConnection = mCreator(); // asynchronously accept on our first worker, if succeeded, run accept mAcceptor.async_accept( mConnection->getSocket(), boost::bind( &Acceptor::accept, this, boost::asio::placeholders::error ) ); // note that this wont happen yet, because there's no io_service running }
void SyncJournalDb::updateBlacklistEntry( const SyncJournalBlacklistRecord& item ) { QMutexLocker locker(&_mutex); QSqlQuery query(_db); if( !checkConnect() ) { return; } QString sql("SELECT retrycount FROM blacklist WHERE path=:path"); if( Utility::fsCasePreserving() ) { // if the file system is case preserving we have to check the blacklist // case insensitively sql += QLatin1String(" COLLATE NOCASE"); } query.prepare(sql); query.bindValue(":path", item._file); if( !query.exec() ) { qDebug() << "SQL exec blacklistitem failed:" << query.lastError().text(); return; } QSqlQuery iQuery(_db); if( query.next() ) { int retries = query.value(0).toInt(); retries--; if( retries < 0 ) retries = 0; iQuery.prepare( "UPDATE blacklist SET lastTryEtag = :etag, lastTryModtime = :modtime, " "retrycount = :retries, errorstring = :errStr WHERE path=:path"); iQuery.bindValue(":etag", item._lastTryEtag); iQuery.bindValue(":modtime", QString::number(item._lastTryModtime)); iQuery.bindValue(":retries", retries); iQuery.bindValue(":errStr", item._errorString); iQuery.bindValue(":path", item._file); } else { // there is no entry yet. iQuery.prepare("INSERT INTO blacklist (path, lastTryEtag, lastTryModtime, retrycount, errorstring) " "VALUES (:path, :lastEtag, :lastMTime, :retrycount, :errorstring);"); iQuery.bindValue(":path", item._file ); iQuery.bindValue(":lastEtag", item._lastTryEtag); iQuery.bindValue(":lastMTime", QString::number(item._lastTryModtime)); iQuery.bindValue(":retrycount", item._retryCount); iQuery.bindValue(":errorstring", item._errorString); } if( !iQuery.exec() ) { qDebug() << "SQL exec blacklistitem insert/update failed: "<< iQuery.lastError().text(); } }