2017-06-14 94 views

回答

1

你可以使用backcurl >>https://github.com/Taymindis/backcurl,這僅僅只是依賴於基於libcurl的。您可以通過使用bcl::setOpts(....)來隨意自定義請求,它適用於非阻止UI請求。

示例代碼

// Derived from example/main.cpp 
void doGuiWork() { 
    printf("\r %s --- %d", "Drawing thousand Pieces of Color with count elapsed ", countUI++); 
} 


void doUpdate() { 
bcl::LoopBackFire(); 
} 

void doRunOnUI() { 
bool gui_running = true; 
std::cout << "Game is running thread: "; 
bcl::executeOnUI<std::string>([](bcl::Request * req) -> void { 
    bcl::setOpts(req, CURLOPT_URL , "http://www.google.com", 
    CURLOPT_FOLLOWLOCATION, 1L, 
    CURLOPT_WRITEFUNCTION, &bcl::writeContentCallback, 
    CURLOPT_WRITEDATA, req->dataPtr, 
    CURLOPT_USERAGENT, "libcurl-agent/1.0", 
    CURLOPT_RANGE, "0-200000" 
       ); 
}, [&](bcl::Response * resp) { 
    printf("On UI === %s\n", resp->getBody<std::string>()->c_str()); 
    printf("Done , stop gui running with count ui %d\n", countUI); 
    std::this_thread::sleep_for(std::chrono::milliseconds(500)); 
    gui_running = false; 
}); 

while (gui_running) { 
    doGuiWork(); 
    doUpdate(); 
    std::this_thread::sleep_for(std::chrono::milliseconds(1000/16)); 
} 
} 
+0

謝謝,真的是純libcurl的,我喜歡它:) – Oktaheta

相關問題