cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Patch for CURLOPT_CONNECT_ONLY

From: Nilesh <nilesh_at_kenati.com>
Date: Wed, 22 Mar 2006 10:35:57 +0530

Thanks Karl !

I think only difference here is curl version I was trying with 7.15.2
and you tried with 7.15.3

Let me try the same code again with my test webserver and also check the
error code at each step.

As you said same curl handle cannot be used for HTTP POST, what is the
use of CONNECT_ONLY option ?
May be I am not clear on use of this feature. What I understood and
wanted to do is as follows,

- With first perform I can check if connection can be established with
webserver.
- Only after successfull connection establishment, I can transfer data
using same curl handle. Ofcourse while doing data transfer, connection
may go down, that time perform call may fail which is fine.

If not CONNECT_ONLY, what is the way I can get above implemented.

Thanks again for your kind involvement into this.

Thanks,
Nilesh

Karl M wrote:

> 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-22