curl-library
Re: Using CURLOPT_UNIX_SOCKET_PATH
Date: Mon, 29 Feb 2016 18:03:17 +0100
On Mon, Feb 29, 2016 at 05:31:19PM +0100, Boutin Maël wrote:
> Dear all,
>
> I'm trying to use libcurl using unix domain sockets but i'm facing an issue.
> When i call curl_easy_perform i get this output:
>
> * About to connect() to localhost port 80 (#0)
> * Trying 127.0.0.1... * Connection refused
> * couldn't connect to host
> * Closing connection #0
> * Couldn't connect to server
> Duration: 0, Nb Bytes sent: 0
>
> So i tested it using the curl binary :
>
> curl -vS --unix-socket "/home/boutinm/test" http://localhost
> * Rebuilt URL to: http://localhost/
> * Trying /home/boutinm/test...
> * Connected to localhost (/home/boutinm/test) port 80 (#0)
> > GET / HTTP/1.1
> > Host: localhost
> > User-Agent: curl/7.47.1
> > Accept: */*
> >
>
> It works this way (my server receives the request). The verbose output is
> clearly not the same as the one i obtained with libcurl. It seems like the
> CURLOPT_UNIX_SOCKET_PATH option is not taken into account.
>
> Here is how i initialize my curl handle:
You can use the --libcurl option to the command-line tool to see what code it
would write for your request, and compare.
> //Initialize curl handle
> m_pCurlHandle = curl_easy_init();
> curl_easy_setopt(m_pCurlHandle, CURLOPT_POST, 1L);
> curl_easy_setopt(m_pCurlHandle, CURLOPT_READFUNCTION, pushBuffer);
> curl_easy_setopt(m_pCurlHandle, CURLOPT_VERBOSE, 1L);
> curl_easy_setopt(m_pCurlHandle, CURLOPT_UNIX_SOCKET_PATH, "/home/boutinm/
> test");
> //Curl headers
> m_pstCurlHeaders = curl_slist_append(m_pstCurlHeaders, "Transfer-Encoding:
> chunked");
> m_pstCurlHeaders = curl_slist_append(m_pstCurlHeaders, "Expect:");
> curl_easy_setopt(m_pCurlHandle, CURLOPT_HTTPHEADER, m_pstCurlHeaders);
> curl_easy_setopt(m_pCurlHandle, CURLOPT_URL, "http://localhost/");
> curl_easy_setopt(m_pCurlHandle, CURLOPT_READDATA, m_pstDataBuffer);
> res = curl_easy_perform(m_pCurlHandle);
>
> Am i missing something ?
>
> FYI the code works when i use network sockets, but i'd like to use unix domain
> sockets for performance (i believe it'll be better than using ip stack)
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-02-29