c - Windows CE 上的 libcurl - curl_easy_perform(...) 不返回

标签 c windows windows-ce libcurl

作为项目的一部分,我需要在自定义 WindowsCE 设备上实现 libcurl,然后通过有线局域网与服务器通信并获取、发布和删除数据(我使用的编程语言是 C).这是我取得的进展:

  1. 我找到了一些教程来为我的 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做得很好。)

  2. 我能够构建一个 DLL 和一个静态 libcurl 库,然后将其链接到我的 Visual Studio 2005 应用程序。

  3. 我将自定义 CE 设备和服务器连接到交换机。我能够从 CE 设备对服务器执行 ping 操作,反之亦然,因此我知道它们都能够相互发送和接收数据。

  4. 我的服务器 (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/

相关文章:

c - C Linux 中的 Pthread 信号

c - 为什么 while 循环不起作用?

c++ - gettimeofday,如何翻译一个linux函数

.NET 紧凑框架中的 WCF 托管

.net - 未知模块中发生 'System.TypeLoadException' 类型的未处理异常

c - 写入文件时出现段错误

C 程序未按预期运行,输入后挂起

c++ - 在不引用 Windows 上的当前目录的情况下解析相对路径

windows - 为什么这个 FOR 命令不删除除我想保留的文件以外的所有文件?

c# - 如何绕过 Windows CE 中的 SSL 证书错误