1

As part of a project, I need to implement libcurl on a Custom WindowsCE device that then talks to a server over wired LAN and GETs, POSTs and DELETEs data ( The programming language I am using is C). This is as far as I've progressed:

  1. I found a couple of tutorials to re-implement the library for my CE device. ( http://stasyan.wordpress.com/2009/12/08/libcurl-for-windows-mobile-and-windows-ce/ , and http://rxwen.blogspot.com/2012/05/port-libcurl-to-wince.html do a really good job.)

  2. I was able to build a DLL and a Static libcurl library, which I then linked to my Visual Studio 2005 application.

  3. I connected my custom CE device and the server to a switch. I am able to ping the server from the CE device and vice versa, so I know that they are both able to send and receive data to each other.

  4. My server (Linux) uses a lighttpd web-server which works perfectly fine when I request the URL (shown in code, below) from my Windows PC which is also connected to the N/W switch.

This is the code I used for my test app:

#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;
}

My problem is that the app never returns. It doesn't even progress past curl_easy_perform(curl).

This is the output I get (Google Drive link): [http://goo.gl/IKgiqW]

What could I possibly be doing wrong??

ash
  • 11
  • 4

1 Answers1

0

I managed to find out what the problem was.

The curl_easy_perform(...) command goes into an infinite loop caused due to a bug in one of the files in the compatibility library. It is referenced in a cURL development forum (google it), but I've summarized it below:

The WCE compatibility library I used (https://github.com/mauricek/wcecompat/) has a file called wce211_string.c. A function within the file, _CRTIMP char* __cdecl strrchr(const char* s, int c), uses a const char* p pointer that isn't decremented. To fix this bug, add the line: p-=1; after the line 'return (char*)p;', so the function will read as follows:

_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;
}

This fixes the infinite looping problem.

ash
  • 11
  • 4