cf-socket: give information when unable to open socket

Give ERRNO explanation in a failf() when unable to open a socket.
Helps in finding out what the issue preventing your curl to work
really is. Just had a wrong ulimit after a sys update.

Closes #19158
This commit is contained in:
Stefan Eissing 2025-10-20 11:51:20 +02:00 committed by Daniel Stenberg
parent 4be9db7bc8
commit dbff3eec45
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -344,6 +344,8 @@ static CURLcode socket_open(struct Curl_easy *data,
struct Curl_sockaddr_ex *addr,
curl_socket_t *sockfd)
{
char errbuf[STRERROR_LEN];
DEBUGASSERT(data);
DEBUGASSERT(data->conn);
if(data->set.fopensocket) {
@ -367,13 +369,15 @@ static CURLcode socket_open(struct Curl_easy *data,
*sockfd = CURL_SOCKET(addr->family, addr->socktype, addr->protocol);
}
if(*sockfd == CURL_SOCKET_BAD)
if(*sockfd == CURL_SOCKET_BAD) {
/* no socket, no connection */
failf(data, "failed to open socket: %s",
curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf)));
return CURLE_COULDNT_CONNECT;
}
#ifdef HAVE_FCNTL
if(fcntl(*sockfd, F_SETFD, FD_CLOEXEC) < 0) {
char errbuf[STRERROR_LEN];
failf(data, "fcntl set CLOEXEC: %s",
curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf)));
close(*sockfd);