-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Description
I'm sad because libcurl apparently does not accept totally virtual sockets. I can pass my write and read functions but it'll still call some functions (like connect and set options) into a file descriptor.
I'd be nice for libcurl to support totally virtual sockets. This way it'd be more portable.
I did this
I wrote the following libcurl code with my custom write and read socket functions:
//...
CURL *curl;
FILE *fp;
CURLcode res;
char outfilename[FILENAME_MAX] = "file";
curl = curl_easy_init();
/* no progress meter please */
//curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &sharedValue);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_data);
curl_easy_setopt(curl, CURLOPT_READDATA, &sharedValue);
curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sharedValue);
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closecb);
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &sharedValue);
curl_easy_setopt(curl, CURLOPT_URL, hostname.c_str());
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
I didn't know what to do with CURLOPT_SOCKOPTFUNCTION
so I did sockopt_callback
which is
static curl_socket_t opensocket(void *clientp,
curlsocktype purpose,
struct curl_sockaddr *address)
{
return 0;
}
But I get
* Trying 212.183.159.230:80...
* Could not set TCP_NODELAY: Socket operation on non-socket
* connect to 212.183.159.230 port 80 failed: Socket operation on non-socket
libcurl wants to close 0 now
because probably it's trying to write to the socket 0
. Apparently I can't prevent it from calling options on the socket file descriptor, for example setting TCP_NODELAY
and most important, connect
.
I expected the following
I expected libcurl to not call any functions on the file descriptor ever. I also expected to be able to provide my own connect functions and TCP_NODELAY
handler function for example.
curl/libcurl version
libcurl 7_72_0
operating system
debian 10
Linux orwell3 4.19.71-1.pvops.qubes.x86_64 #1 SMP Mon Sep 9 12:04:25 UTC 2019 x86_64 GNU/Linux