cURL / Mailing Lists / curl-library / Single Mail


curl_easy_perform gives CURLE_COULDNT_RESOLVE_HOST error in multi thread environment

From: Praveen Pvs <>
Date: Fri, 28 Nov 2014 22:20:17 +0530

Hi All,

Can I use CURL in multi threaded application?

My Requirement is as follows:
I have to post the data to the server. suppose if the connection is broken
with the server, i need to store the data and post it when it comes online.
So this activity will happen on back ground (on a separate thread). My main
thread will keep trying to post the data normally. My other thread will
check the connection with the host and post the data.

To test this scenario, I have written the sample code. To simulate this
scenirio, during running of the application i am pulling my ethernet cable
so that i can simulate the connection break down case. Both threads giving
successful response till i pulled the cable. Once i pull the cable and
connect it back, one of the threads which is checking the connection is
keep getting CURLE_COULDNT_RESOLVE_HOST error even though other thread is
successful in posting the data to the host.

Please refer to attached sample code(curlLibraryTest.c):
In the Sample code, we have main thread and waitForHostConnection thread.
Main thread will keep posting the data to the host at regular intervals.
waitForHostConnection thread will keep checking the host connection.

Both threads are working fine and giving succesful response till i pulled
the ethernet cable, once i pulled and put the cable back,
waitForHostConnection thread is giving CURLE_COULDNT_RESOLVE_HOST error.

When i am doing both things posting and checking connection in the same
thread(main) then it works fine even after pulling and connecting the cable
back. When i move connection checking part to the separate thread then the
problem starts.

Could anyone help me to resolve this.

Thank you for your time and help.


List admin:

Received on 2014-11-28