Skip to content
Snippets Groups Projects
Verified Commit 3901507d authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Actually pass lambda as a function pointer

It seems like lambdas DON'T automatically decay to a function pointer
with C varargs functions. Add an explicit + to do so.
parent 18470f1c
No related branches found
No related tags found
No related merge requests found
Pipeline #1582 passed
......@@ -217,20 +217,23 @@ Request &Request::connection_timeout(long t) {
this->connection_timeout_ = t;
#ifdef TCP_USER_TIMEOUT
curl_easy_setopt(this->easy, CURLOPT_SOCKOPTFUNCTION, [](void *clientp, curl_socket_t curlfd, curlsocktype) -> int {
unsigned int val = static_cast<Request *>(clientp)->connection_timeout_ * 1000 /*ms*/;
setsockopt(curlfd, SOL_TCP, TCP_USER_TIMEOUT, (const char *)&val, sizeof(val));
return CURLE_OK;
});
curl_easy_setopt(this->easy, CURLOPT_SOCKOPTDATA, this);
// The + is needed to convert this to a function pointer!
curl_easy_setopt(
this->easy, CURLOPT_SOCKOPTFUNCTION, +[](void *clientp, curl_socket_t curlfd, curlsocktype) -> int {
unsigned int val = static_cast<Request *>(clientp)->connection_timeout_ * 1000 /*ms*/;
setsockopt(curlfd, SOL_TCP, TCP_USER_TIMEOUT, (const char *)&val, sizeof(val));
return CURLE_OK;
});
#elif defined(TCP_MAXRT)
curl_easy_setopt(this->easy, CURLOPT_SOCKOPTFUNCTION, [](void *clientp, curl_socket_t sock, curlsocktype) -> int {
unsigned int maxrt = static_cast<Request *>(clientp)->connection_timeout_ /*s*/;
setsockopt(sock, IPPROTO_TCP, TCP_MAXRT, (const char *)&maxrt, sizeof(maxrt));
return CURLE_OK;
});
curl_easy_setopt(this->easy, CURLOPT_SOCKOPTDATA, this);
// The + is needed to convert this to a function pointer!
curl_easy_setopt(
this->easy, CURLOPT_SOCKOPTFUNCTION, +[](void *clientp, curl_socket_t sock, curlsocktype) -> int {
unsigned int maxrt = static_cast<Request *>(clientp)->connection_timeout_ /*s*/;
setsockopt(sock, IPPROTO_TCP, TCP_MAXRT, (const char *)&maxrt, sizeof(maxrt));
return CURLE_OK;
});
#endif
curl_easy_setopt(this->easy, CURLOPT_SOCKOPTDATA, this);
return *this;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment