cURL / Mailing Lists / curl-library / Single Mail



From: Ray Satiro via curl-library <>
Date: Mon, 29 Feb 2016 15:12:03 -0500

On 2/29/2016 11:31 AM, 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 * 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:
> //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)

I don't see anything wrong with your code as long as you're setting
m_pstCurlHeaders to NULL beforehand. You aren't checking the setopt
return codes and while that is not strictly required it can help to do
that to identify options like this that may not be available. My guess
is unix sockets is either not supported or disabled in the libcurl that
is being used. In other words I think the libcurl used by your curl tool
is different from the libcurl used by your program. To use
CURLOPT_UNIX_SOCKET_PATH [1] you need 7.40+ and that it wasn't disabled
by passing --disable-unix-sockets to configure.

   curl_version_info_data *ver;
   ver = curl_version_info(CURLVERSION_NOW);
   printf("\nYou are using libcurl/%s\nUnix Socket Support: %s\n\n",
          (ver->features & CURL_VERSION_UNIX_SOCKETS) ? "Yes" : "No");


   CURLcode ec;
   ec = curl_easy_setopt(hnd, CURLOPT_UNIX_SOCKET_PATH,
   if(ec != CURLE_OK) {
     fprintf(stderr, "problem!\n");

If that is the problem and your libcurl is static check if there is more
than one libcurl.a. If your libcurl is shared you may be able to fix it
by using either LD_PRELOAD or rpath to load the libcurl with unix socket
support. For example in Ubuntu 14 the curl package is curl 7.35 and I
have that installed but I also build and install the latest curl and
install in /usr/local.

gcc -o x x.c -I/usr/local/include -L/usr/local/lib -lcurl
LD_PRELOAD=/usr/local/lib/ ./x
gcc -o x x.c -Wl,-rpath,/usr/local/lib -I/usr/local/include
-L/usr/local/lib -lcurl

And if that's not the problem reply with the libcurl version used by
your program and a self contained example and maybe someone will try to


List admin:
Received on 2016-02-29