1
我需要一个程序,每秒轮询一个站点并响应,如果站点在15秒内没有响应。我从一个示例程序中进行了以下攻击。在空运行中,它在15秒内打印7次。我不能让curl_easy_perform在响应之前等待15秒吗?使用libcurl监视网络的状态
int main(void)
{
CURL *curl;
CURLcode res;
char *postthis="moo mooo moo moo";
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.101");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis));
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 15);
while(1)
{
Sleep(1000);
res = curl_easy_perform(curl);
if(res!= CURLE_OK)
printf("nada \n");
}
将试图实现,这是内置的功能。钉住睡眠()和转移时间,然后总是有一个小的处理时间。这不会太重要。 – aitchnyu 2011-02-27 18:23:37