今天在测试排查一个奇怪的问题,图片发送有时会发不出去,(50%的概率)一开始觉得是网络
的问题或者是对方服务器有问题,ping了一下,反应还是挺快的,而且其它设备对外网的反应还是
好的,进入设备查看打印,没发送出去的curl_easy_perform返回值28
_pcResponse[0] = '\0';
(void)curl_easy_setopt(pstCurlEasy, CURLOPT_URL, _pcUrl);
(void)curl_easy_setopt(pstCurlEasy, CURLOPT_READFUNCTION, NULL);
(void)curl_easy_setopt(pstCurlEasy, CURLOPT_POST, 1);
(void)curl_easy_setopt(pstCurlEasy, CURLOPT_WRITEFUNCTION, OnCurlRecvData);
(void)curl_easy_setopt(pstCurlEasy, CURLOPT_WRITEDATA, (void *)_pcResponse);
(void)curl_easy_setopt(pstCurlEasy, CURLOPT_POSTFIELDS, _pcPostBuf);
(void)curl_easy_setopt(pstCurlEasy, CURLOPT_POSTFIELDSIZE, (long)strlen(_pcPostBuf));
(void)curl_easy_setopt(pstCurlEasy, CURLOPT_TIMEOUT, 3L);
(void)curl_easy_setopt(pstCurlEasy, CURLOPT_HEADER, 1);
http_headers = curl_slist_append(http_headers, "Accept: application/json,application/VIID+json");
http_headers = curl_slist_append(http_headers, "Content-Type: application/VIID+JSON;charset=UTF-8");
http_headers = curl_slist_append(http_headers, "Connection: keepalive");
http_headers = curl_slist_append(http_headers, cUserIdentify);
http_headers = curl_slist_append(http_headers, _AuthBuf);
http_headers = curl_slist_append(http_headers, "User-Agent: libghttp/1.0");
(void)curl_easy_setopt(pstCurlEasy, CURLOPT_HTTPHEADER, http_headers);
iRet = curl_easy_perform(pstCurlEasy);
if(iRet != CURLE_OK)
{
Gat1400Log_Error("iRet = %d\n", iRet);
goto end;
}
于是进入搜索了一下为什么返回28,查了一下是因为超时,于是根据网络上的添加相应设置
curl_easy_setopt(pEasy, CURLOPT_VERBOSE, 1);
再进行运行,出现了下面的
一看就知道了,和服务器交互的时间很显示大于了设置的时间3L,然后我尝试把超时时间加大
(void)curl_easy_setopt(pstCurlEasy, CURLOPT_TIMEOUT, 30L);
然后再运行,放入测试的环境(在我自己的电脑上3秒就够了,不会出现测试的那种超时现象。。。。)
果然就好使了。