cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Patch for CURLOPT_CONNECT_ONLY

From: Karl M <karlm30_at_hotmail.com>
Date: Tue, 21 Mar 2006 07:12:13 -0800

Hi All...

I just tried the following code with 7.15.3 and MSVC on an XP Pro machine:

#include <fcntl.h>
#include <io.h>
#include <curl/curl.h>

#if LIBCURL_VERSION_NUM < 0x070f02
#error "Requires libcurl version 7.15.2 or higher."
#endif

int main(void) {
  CURL *curl;
  CURLcode res;
  long last_sock=0;

  char *postthis="moo mooo moo moo";

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://yahoo.com");
    curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1);

    res = curl_easy_perform(curl);
    res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &last_sock);
    printf("Return code frm curl_easy_getinfo [%d][%s]\n", res,
curl_easy_strerror(res)); // this gives res=43
    printf("curl_easy_getinfo returned CURLINFO_LASTSOCKET [%ld]\n",
last_sock); // last_sock is still 0
    if(CURLE_OK == res) {
      printf("curl_easy_getinfo returned CURLINFO_LASTSOCKET [%ld]\n",
last_sock);
    }

   //curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis);

   /* if we don't provide POSTFIELDSIZE, libcurl will strlen() by
      itself */
   //curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(postthis));

   //res = curl_easy_perform(curl);

   /* always cleanup */
   curl_easy_cleanup(curl);
  }
  return 0;
}

and got the following output:

Return code frm curl_easy_getinfo [0][no error]
curl_easy_getinfo returned CURLINFO_LASTSOCKET [1940]
curl_easy_getinfo returned CURLINFO_LASTSOCKET [1940]

I commented out the second half of your code because with
CURLOPT_CONNECT_ONLY, I don't think the put could work on the same curl
handle.

Does your testwebserver exist?

Perhaps you could check the error code at each step and see where something
first goes wrong.

HTH,

...Karl

>From: Nilesh
>Subject: Re: Patch for CURLOPT_CONNECT_ONLY
>Date: Fri, 17 Mar 2006 11:55:55 +0530
>
>
>
>>>Also if I can get working example for this option, that will be helpful.
>>
>>
>>I would like that too, for inclusion in the package.
>
>Following is what I am trying to do to test CONNECT_ONLY option. ( I used
>simplepost.c example with small modification )
>
>/int main(void)
>{
> CURL *curl;
> CURLcode res;
> long last_sock=0;
>
> char *postthis="moo mooo moo moo";
>
> curl = curl_easy_init();
> if(curl) {
>* curl_easy_setopt(curl, CURLOPT_URL, "http://testwebserver");
> curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1);
>
> res = curl_easy_perform(curl);
> res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &last_sock);
> printf("Return code frm curl_easy_getinfo [%d][%s]\n", res,
>curl_easy_strerror(res)); // this gives res=43
> printf("curl_easy_getinfo returned CURLINFO_LASTSOCKET [%ld]\n",
>last_sock); // last_sock is still 0
> if(CURLE_OK == res)
> {
> printf("curl_easy_getinfo returned CURLINFO_LASTSOCKET [%ld]\n",
>last_sock);
> }
>*
> curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis);
>
> /* if we don't provide POSTFIELDSIZE, libcurl will strlen() by
> itself */
> curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(postthis));
>
> res = curl_easy_perform(curl);
>
> /* always cleanup */
> curl_easy_cleanup(curl);
> }
> return 0;
>}
>/
>Getting following output:
>
>*/Return code frm curl_easy_getinfo [43][a libcurl function was given a bad
>argument]
>curl_easy_getinfo returned CURLINFO_LASTSOCKET [0]
>/
>*Can you help me to understand how CONNECT_ONLY be used ?
>
>Thanks,
>Nilesh
>
>
>
>
>
Received on 2006-03-21