Esempio n. 1
0
	void doFetch(std::list<RequestInfo>::iterator iter, ServiceIterator::ErrorType reason) {
		/* FIXME: this does not acquire a lock--which will cause a problem
		 * if this class is destructed while we are executing doFetch.
		 */
		RequestInfo &info = *iter;
		if (cleanup || !info.serviter) {
			SILOG(transfer,error,"None of the services registered for " <<
					info.fileId.uri() << " were successful.");
			CacheLayer::getData(info.fileId, info.range, info.callback);
			boost::unique_lock<boost::mutex> transfer_lock(mActiveTransferLock);
			mActiveTransfers.erase(iter);
			mCleanupCV.notify_one();
			return;
		}
		URI lookupUri;
		std::tr1::shared_ptr<DownloadHandler> handler;
		ServiceParams params;
		if (mService->getNextProtocol(info.serviter,reason,info.fileId.uri(),lookupUri,params,handler)) {
			// info IS GETTING FREED BEFORE download RETURNS TO SET info.httpreq!!!!!!!!!
			info.httpreq = DownloadHandler::TransferDataPtr();
			handler->download(&info.httpreq, params, lookupUri, info.range,
					std::tr1::bind(&NetworkCacheLayer::httpCallback, this, iter, _1, _2));
			// info may be deleted by now (not so unlikely as it sounds -- it happens if you connect to localhost)
		} else {
			info.serviter = NULL; // deleted.
			doFetch(iter, ServiceIterator::UNSUPPORTED);
		}
	}
Esempio n. 2
0
	void doNameLookup(const Callback &cb, const URI &origNamedUri, ServiceIterator *services, ServiceIterator::ErrorType reason) {
		URI lookupUri;
		ServiceParams params;
		std::tr1::shared_ptr<NameLookupHandler> handler;
		if (mNameServ->getNextProtocol(services,reason,origNamedUri,lookupUri,params,handler)) {
			/// FIXME: Need a way of aborting a name lookup that is taking too long.
			handler->nameLookup(NULL, lookupUri,
				std::tr1::bind(&NameLookupManager::gotNameLookup, this, cb, origNamedUri, services, _1, _2, _3));
		} else {
			SILOG(transfer,warn,"None of the services registered for " <<
					origNamedUri << " were successful for NameLookup.");
			/// Hashed download.
			if (mDownloadServ) {
				mDownloadServ->lookupService(origNamedUri.context(),
					std::tr1::bind(&NameLookupManager::hashedDownload, this, cb, origNamedUri, _1));
			} else {
				cb(origNamedUri, NULL);
			}
			return;
		}
	}