I am using libcurl to send an API command to a local service (i.e. on 127.0.0.1).
The program is intended to replace a shell script (that uses the curl
program.)
Everything is working, except that there is a 1-second delay somewhere, i.e 1 second elapses from the time I call curl_easy_perform()
to when my read callback function is first called.
The C program is using these options (error checking & callback code omitted):
curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:12345/x");
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long)getLengthOfCommandObject());
curl_easy_setopt(curl, CURLOPT_READFUNCTION, &myReadFunction);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &myWriteFunction);
But if I run curl
from the shell like this:
$ curl --data-binary '<command>' http://127.0.0.1:12345/x
it sends the request immediately, without suffering from the 1-second delay.
What might be causing the delay, and is there an option I can set to prevent it?
Edit The server is based on mongoose