本文整理汇总了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;未经允许,请勿转载。 |
请发表评论