cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: can Curl use socket() created by application?

From: amit paliwal <amit.ambitions_at_gmail.com>
Date: Fri, 19 Aug 2011 16:53:27 -0400

On Sat, Aug 13, 2011 at 4:27 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:

> On Sat, 13 Aug 2011, amit paliwal wrote:
>
> Just want to know that is it possible for Curl to use socket created by
>> application to use in further calls to curl_easy_perform().
>>
>
> Yes!
>
> You use CURLOPT_OPENSOCKETFUNCTION to pass in the socket, and then you use
> the CURLOPT_SOCKOPTFUNCTION to return CURL_SOCKOPT_ALREADY_**CONNECTED.
>
> Requires a fairly new libcurl.
>

---- I have taken new curl and tried something like this:

/* Create the listening socket */
    if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
    fprintf(stderr, "ECHOCLNT: Error creating listening socket.\n");
    exit(EXIT_FAILURE);
    }

    struct sockaddr_in servaddr; /* socket address structure */
    //fuill structure attributes

  //connect
   if (connect(sockfd,(struct sockaddr *) &servaddr, sizeof(servaddr)) ==
-1)
        {
        }

/* send all data to this function */
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_URL, "
http://10.10.1.1:808/generic?sessinfo=0023BEBDD0240424D0BDBE");
res = curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
res = curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
res = curl_easy_perform(curl);

I can see that after my connect() call Client was connected to the server
but when curl try to do a perform I saw following output:

Rdvr: Option CURLOPT_OPENSOCKETFUNCTION Set with status: No error

Rdvr: Option CURLOPT_SOCKOPTFUNCTION Set with status: No error
* About to connect() to 10.10.1.1 port 8080 (#0)
Inside opensocketECHOCLNT: socket fd: 4
* Trying 10.10.1.1... Inside sockopt_callback::4* couldn't connect to host
* Closing connection #0
* Couldn't connect to server
Error: Argument list too long

Why is it trying to connect to the server again??????? As per the options
set it should not try this.

Btw, the callback function for set options are:

curl_socket_t opensocket (void *clientp,
                            curlsocktype purpose,
                            struct curl_sockaddr *address)
{
    return sockfd; //here i am returning the socket fd created by socket()
call
}

int sockopt_callback(void *clientp, curl_socket_t curlfd, curlsocktype
purpose)
{
    return CURL_SOCKOPT_ALREADY_CONNECTED;
}

WHAT IS WRONG HERE????????????????

>
> --
>
> / daniel.haxx.se
> ------------------------------**------------------------------**-------
> List admin: http://cool.haxx.se/list/**listinfo/curl-library<http://cool.haxx.se/list/listinfo/curl-library>
> Etiquette: http://curl.haxx.se/mail/**etiquette.html<http://curl.haxx.se/mail/etiquette.html>
>

-- 
Regards,
Amit

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-08-19