cURL / Mailing Lists / curl-library / Single Mail


Libcurl dalays SYN (HTTP connection timeout)

From: conchi <>
Date: Tue, 27 Apr 2010 10:27:50 +0200

Hello again,

Maybe I have not explained well the problem.

I have made a test program that make a HTTP request to a Web server.


I invoke the curllib with two timeouts:


curl_easy_setopt(m_pCURL, CURLOPT_TIMEOUT_MS, 2000);

curl_easy_setopt(m_pCURL, CURLOPT_CONNECTTIMEOUT_MS, 2000);


Always invoke the curlib with the remote IP address (not by name)

I have a loop making this request all the time.


Sometimes the Curl_connecthost function returns an CURLE_COULDNT_CONNECT

I sniff the network with Lansleuth (or with wireshark) and I see that the
SYN is delays about 4 seconds, so when the socket is connected the timeout
is expired and the curlib closes the socket.


I can attach the file from wireshark. You can see that the SYN usually are
in the same second, but the last SYN has been delayed 5 seconds and the
curlib has closed the socket when it has connected.

My PC is the The Web server is

My code is very simple:



int res;

ULONG ulContadorTotal=0;

ULONG ulCntFallos=0;








            TRACE("[Trying %d] ERROR\n",ulContadorTotal);


      else if(res==-2) //es otro tipo de error de HTTP.



            TRACE("[Trying %d] ERROR\n",ulContadorTotal);




            TRACE("[Trying %d] OK\n",ulContadorTotal);







int CMyHTTPClientCURL::OpenSession(LPCTSTR szAddress, USHORT uPort, LPCTSTR
szUsername, LPCTSTR szPassword, UINT


      CString strUsrPwd;


      if (m_pCURL != NULL)


            strUsrPwd.Format("%s:%s", szUsername, szPassword);


            curl_easy_setopt(m_pCURL, CURLOPT_USERPWD, strUsrPwd);


            curl_easy_setopt(m_pCURL, CURLOPT_TIMEOUT_MS, uiMsTimeout);

            curl_easy_setopt(m_pCURL, CURLOPT_CONNECTTIMEOUT_MS,


            /* send all data to this function */

            curl_easy_setopt(m_pCURL, CURLOPT_WRITEFUNCTION,

            /* we pass our 'chunk' struct to the callback function */

            curl_easy_setopt(m_pCURL, CURLOPT_WRITEDATA, (void



      m_sAddress = szAddress;

      m_iPort = uPort;

      m_strUsername= szUsername;

      m_strPassword= szPassword;


      return 0;




// Pide una conexion HTTP

int CMyHTTPClientCURL::Request(LPCTSTR szPath, UINT


      CURLcode curl_res;

      int iResult = 0;

      CString sURL;


      sURL.Format(_T("http://%s:%d"), m_sAddress, m_iPort);

      sURL.AppendFormat(szPath[0] == _T('/') ? _T("%s") : _T("/%s"),


      // Init variables for the new request

      curl_easy_setopt(m_pCURL, CURLOPT_TIMEOUT_MS, uiMsTimeout);

      curl_easy_setopt(m_pCURL, CURLOPT_CONNECTTIMEOUT_MS, uiMsTimeout);


      m_dwLastHttpError = 0;


      // Proccess request

      if (m_pCURL != NULL)


            sURL.Replace(_T(" "), _T("%20"));

            curl_easy_setopt(m_pCURL, CURLOPT_URL, sURL);

            curl_res = curl_easy_perform(m_pCURL);



      // Errors ?


      switch (curl_res)



      case CURLE_OK:

            m_pReadPosition = m_stChunk.memory;


            // Obtener el codigo de error devuelto por el servidor

            curl_easy_getinfo(m_pCURL, CURLINFO_RESPONSE_CODE,


            iResult = m_dwLastHttpError;

            if ((m_dwLastHttpError / 100) != 2)


                  iResult = -2;

                  TRACE("HTTPClientCURL Error: %d \n",m_dwLastHttpError);




                  TRACE("HTTPClientCURL OK \n");




            // Se han producido errores que no son HTTP (socket, buffer,

            iResult = -1;

            m_dwLastHttpError = curl_res;

            TRACE("HTTPClientCURL Error : %d\n", m_dwLastHttpError);




      return iResult;




Sorry for my bad English.

List admin:

Received on 2010-04-27