• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ ofThreadChannel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ofThreadChannel的典型用法代码示例。如果您正苦于以下问题:C++ ofThreadChannel类的具体用法?C++ ofThreadChannel怎么用?C++ ofThreadChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ofThreadChannel类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: threadedFunction

void ofURLFileLoaderImpl::threadedFunction() {
	setThreadName("ofURLFileLoader " + ofToString(getThreadId()));
	while( isThreadRunning() ){
		int cancelled;
		while(cancelRequestQueue.tryReceive(cancelled)){
			cancelledRequests.insert(cancelled);
		}
		ofHttpRequest request;
		if(requests.receive(request)){
			if(cancelledRequests.find(request.getId())==cancelledRequests.end()){
				ofHttpResponse response(handleRequest(request));
				int status = response.status;
				if(!responses.send(move(response))){
					break;
				}
				if(status==-1){
					// retry
					requests.send(request);
				}
			}else{
				cancelledRequests.erase(cancelled);
			}
		}else{
			break;
		}
	}
}
开发者ID:Catchoom,项目名称:openFrameworks,代码行数:27,代码来源:ofURLFileLoader.cpp


示例2: getAsync

int ofURLFileLoaderImpl::getAsync(string url, string name){
	if(name=="") name=url;
	ofHttpRequest request(url,name);
	requests.send(request);
	start();
	return request.getID();
}
开发者ID:Bolvangar,项目名称:openFrameworks,代码行数:7,代码来源:ofURLFileLoader.cpp


示例3: update

void ofURLFileLoaderImpl::update(ofEventArgs & args){
	ofHttpResponse response;
	while(responses.tryReceive(response)){
		ofNotifyEvent(ofURLResponseEvent(),response);
	}

}
开发者ID:anthonycouret,项目名称:openFrameworks,代码行数:7,代码来源:ofURLFileLoader.cpp


示例4: update

void ofURLFileLoaderImpl::update(ofEventArgs & args){
	ofHttpResponse response;
	while(responses.tryReceive(response)){
		try{
			response.request.done(response);
		}catch(...){

		}

		ofNotifyEvent(ofURLResponseEvent(),response);
	}

}
开发者ID:Catchoom,项目名称:openFrameworks,代码行数:13,代码来源:ofURLFileLoader.cpp


示例5: clear

void ofURLFileLoaderImpl::clear(){
	ofHttpResponse resp;
	ofHttpRequest req;
	while(requests.tryReceive(req)){}
	while(responses.tryReceive(resp)){}
}
开发者ID:Catchoom,项目名称:openFrameworks,代码行数:6,代码来源:ofURLFileLoader.cpp


示例6: remove

void ofURLFileLoaderImpl::remove(int id){
	cancelRequestQueue.send(id);
}
开发者ID:Catchoom,项目名称:openFrameworks,代码行数:3,代码来源:ofURLFileLoader.cpp


示例7: saveAsync

int ofURLFileLoaderImpl::saveAsync(const string& url, const std::filesystem::path& path){
	ofHttpRequest request(url,path.string(),true);
	requests.send(request);
	start();
	return request.getId();
}
开发者ID:Catchoom,项目名称:openFrameworks,代码行数:6,代码来源:ofURLFileLoader.cpp


示例8: getAsync

int ofURLFileLoaderImpl::getAsync(const string& url, const string& name){
	ofHttpRequest request(url, name.empty() ? url : name);
	requests.send(request);
	start();
	return request.getId();
}
开发者ID:Catchoom,项目名称:openFrameworks,代码行数:6,代码来源:ofURLFileLoader.cpp


示例9: handleRequestAsync

int ofURLFileLoaderImpl::handleRequestAsync(const ofHttpRequest& request){
	requests.send(request);
	start();
	return request.getId();
}
开发者ID:Catchoom,项目名称:openFrameworks,代码行数:5,代码来源:ofURLFileLoader.cpp


示例10: stop

void ofURLFileLoaderImpl::stop() {
	stopThread();
	requests.close();
	responses.close();
	waitForThread();
}
开发者ID:Catchoom,项目名称:openFrameworks,代码行数:6,代码来源:ofURLFileLoader.cpp


示例11: threadedFunction

void ofURLFileLoaderImpl::threadedFunction() {
	thread.setName("ofURLFileLoader " + thread.name());
	while( isThreadRunning() ){
		int cancelled;
		while(cancelRequestQueue.tryReceive(cancelled)){
			cancelledRequests.insert(cancelled);
		}
		ofHttpRequest request;
		if(requests.receive(request)){
			if(cancelledRequests.find(request.getID())==cancelledRequests.end()){
				ofHttpResponse response(handleRequest(request));
				int status = response.status;
#if __cplusplus>=201103
				if(!responses.send(move(response))){
#else
				if(!responses.send(response)){
#endif
					break;
				}
				if(status==-1){
					// retry
					requests.send(request);
				}
			}else{
				cancelledRequests.erase(cancelled);
			}
		}else{
			break;
		}
	}
}

ofHttpResponse ofURLFileLoaderImpl::handleRequest(ofHttpRequest request) {
	try {
		URI uri(request.url);
		std::string path(uri.getPathAndQuery());
		if (path.empty()) path = "/";

		HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
		HTTPResponse res;
		shared_ptr<HTTPSession> session;
		istream * rs;
		if(uri.getScheme()=="https"){
			 //const Poco::Net::Context::Ptr context( new Poco::Net::Context( Poco::Net::Context::CLIENT_USE, "", "", "rootcert.pem" ) );
			HTTPSClientSession * httpsSession = new HTTPSClientSession(uri.getHost(), uri.getPort());//,context);
			httpsSession->setTimeout(Poco::Timespan(20,0));
			httpsSession->sendRequest(req);
			rs = &httpsSession->receiveResponse(res);
			session = shared_ptr<HTTPSession>(httpsSession);
		}else{
			HTTPClientSession * httpSession = new HTTPClientSession(uri.getHost(), uri.getPort());
			httpSession->setTimeout(Poco::Timespan(20,0));
			httpSession->sendRequest(req);
			rs = &httpSession->receiveResponse(res);
			session = shared_ptr<HTTPSession>(httpSession);
		}
		if(!request.saveTo){
			return ofHttpResponse(request,*rs,res.getStatus(),res.getReason());
		}else{
			ofFile saveTo(request.name,ofFile::WriteOnly,true);
			char aux_buffer[1024];
			rs->read(aux_buffer, 1024);
			std::streamsize n = rs->gcount();
			while (n > 0){
				// we resize to size+1 initialized to 0 to have a 0 at the end for strings
				saveTo.write(aux_buffer,n);
				if (rs->good()){
					rs->read(aux_buffer, 1024);
					n = rs->gcount();
				}
				else n = 0;
			}
			return ofHttpResponse(request,res.getStatus(),res.getReason());
		}

	} catch (const Exception& exc) {
        ofLogError("ofURLFileLoader") << "handleRequest(): "+ exc.displayText();

        return ofHttpResponse(request,-1,exc.displayText());

    } catch (...) {
    	return ofHttpResponse(request,-1,"ofURLFileLoader: fatal error, couldn't catch Exception");
    }

	return ofHttpResponse(request,-1,"ofURLFileLoader: fatal error, couldn't catch Exception");
	
}	

void ofURLFileLoaderImpl::update(ofEventArgs & args){
	ofHttpResponse response;
	while(responses.tryReceive(response)){
		ofNotifyEvent(ofURLResponseEvent(),response);
	}

}
开发者ID:Bolvangar,项目名称:openFrameworks,代码行数:95,代码来源:ofURLFileLoader.cpp


示例12: saveAsync

int ofURLFileLoaderImpl::saveAsync(string url, string path){
	ofHttpRequest request(url,path,true);
	requests.send(request);
	start();
	return request.getID();
}
开发者ID:Bolvangar,项目名称:openFrameworks,代码行数:6,代码来源:ofURLFileLoader.cpp



注:本文中的ofThreadChannel类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ofTrueTypeFont类代码示例发布时间:2022-05-31
下一篇:
C++ ofTexture类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap