CURLOPT_UNIX_SOCKET_PATH.3 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. .\" generated by cd2nroff 0.1 from CURLOPT_UNIX_SOCKET_PATH.md
  2. .TH CURLOPT_UNIX_SOCKET_PATH 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_UNIX_SOCKET_PATH \- Unix domain socket
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_UNIX_SOCKET_PATH, char *path);
  9. .fi
  10. .SH DESCRIPTION
  11. Enables the use of Unix domain sockets as connection endpoint and sets the
  12. path to \fIpath\fP. If \fIpath\fP is NULL, then Unix domain sockets are
  13. disabled.
  14. When enabled, curl connects to the Unix domain socket instead of establishing
  15. a TCP connection to the host. Since no network connection is created, curl
  16. does not resolve the DNS hostname in the URL.
  17. The maximum path length on Cygwin, Linux and Solaris is 107. On other platforms
  18. it might be even less.
  19. Proxy and TCP options such as \fICURLOPT_TCP_NODELAY(3)\fP are not
  20. supported. Proxy options such as \fICURLOPT_PROXY(3)\fP have no effect either
  21. as these are TCP\-oriented, and asking a proxy server to connect to a certain
  22. Unix domain socket is not possible.
  23. The application does not have to keep the string around after setting this
  24. option.
  25. .SH DEFAULT
  26. NULL \- no Unix domain sockets are used.
  27. .SH PROTOCOLS
  28. This functionality affects all supported protocols
  29. .SH EXAMPLE
  30. .nf
  31. int main(void)
  32. {
  33. CURL *curl = curl_easy_init();
  34. if(curl) {
  35. curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, "/tmp/httpd.sock");
  36. curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/");
  37. curl_easy_perform(curl);
  38. }
  39. }
  40. .fi
  41. If you are on Linux and somehow have a need for paths larger than 107 bytes,
  42. you can use the proc filesystem to bypass the limitation:
  43. .nf
  44. int dirfd = open(long_directory_path_to_socket, O_DIRECTORY | O_RDONLY);
  45. char path[108];
  46. snprintf(path, sizeof(path), "/proc/self/fd/%d/httpd.sock", dirfd);
  47. curl_easy_setopt(curl_handle, CURLOPT_UNIX_SOCKET_PATH, path);
  48. /* Be sure to keep dirfd valid until you discard the handle */
  49. .fi
  50. .SH AVAILABILITY
  51. Added in curl 7.40.0
  52. .SH RETURN VALUE
  53. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  54. .SH SEE ALSO
  55. .BR CURLOPT_ABSTRACT_UNIX_SOCKET (3),
  56. .BR CURLOPT_OPENSOCKETFUNCTION (3),
  57. .BR unix (7)