作为项目的一部分,我需要在自定义 WindowsCE 设备上实现 libcurl,然后通过有线局域网与服务器通信并获取、发布和删除数据(我使用的编程语言是 C).这是我取得的进展:
我找到了一些教程来为我的 CE 设备重新实现库。 ( http://stasyan.wordpress.com/2009/12/08/libcurl-for-windows-mobile-and-windows-ce/ 和 http://rxwen.blogspot.com/2012/05/port-libcurl-to-wince.html做得很好。)
我能够构建一个 DLL 和一个静态 libcurl 库,然后将其链接到我的 Visual Studio 2005 应用程序。
我将自定义 CE 设备和服务器连接到交换机。我能够从 CE 设备对服务器执行 ping 操作,反之亦然,因此我知道它们都能够相互发送和接收数据。
我的服务器 (Linux) 使用 lighttpd 网络服务器,当我从也连接到 N/W 开关的 Windows PC 请求 URL(如下代码所示)时,它工作得非常好。
这是我用于测试应用的代码:
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
printf("STARTING APP...\n");
CURL *curl;
CURLcode res;
printf("curl = curl_easy_init();\n");
curl = curl_easy_init();
if(curl)
{
printf("Enabling followlocation...\n");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1l);
printf("Setting Verbose...\n");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
printf("Setting Connect time out...\n");
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5);
printf("Setting Server time out...\n");
curl_easy_setopt(curl, CURLOPT_ACCEPTTIMEOUT_MS , 5000);
printf("Setting URL...\n");
curl_easy_setopt(curl, CURLOPT_URL, "http://165.26.79.10:8080");
/* Perform the request, res will get the return code */
printf("Perform(curl)...;\n");
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
else
printf("\nGET sucessful.\n");
/* always cleanup */
curl_easy_cleanup(curl);
}
getchar();
return 0;
}
getchar();
return 0;
}
我的问题是应用程序永远不会返回。它甚至没有超过 curl_easy_perform(curl)。
这是我得到的输出(Google 云端硬盘链接):[http://goo.gl/IKgiqW]
我可能做错了什么??
最佳答案
我设法找出问题所在。
由于兼容性库中的一个文件中的错误,curl_easy_perform(...) 命令进入无限循环。它在 cURL 开发论坛(google it)中被引用,但我总结如下:
我使用的 WCE 兼容性库 (https://github.com/mauricek/wcecompat/) 有一个名为 wce211_string.c 的文件。文件中的一个函数 _CRTIMP char* __cdecl strrchr(const char* s, int c) 使用了一个不递减的 const char* p 指针。要修复此错误,请在“return (char*)p;”行之后添加行:p-=1;,因此函数将如下所示:
_CRTIMP char* __cdecl strrchr(const char* s, int c)
{
const char* p = s + strlen(s) - 1;
while (p >= s)
{
if (*p == c)
return (char*)p;
p -= 1;
}
return NULL;
}
这解决了无限循环问题。
关于c - Windows CE 上的 libcurl - curl_easy_perform(...) 不返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22640158/