curl-library
Re: Couldn't Connect Error - Address already in use
Date: Thu, 29 Apr 2010 16:59:02 +0530 (IST)
Thanks for the reply.
I would have loved to create a small application and showed it to you. However, this is part of a bigger code and can't be seperated out easily.
We are using HTTP. We are using libCurl version 7.19.6 on Windows Server 2003 and every request is sent using new curl handle(using easy interface).This is a multithreaded application
I am pasting the code snippet here(to POST a file). I am getting similar error for other requests too.
CURLcode curlcode = InitializeCurlOptions();
RETURN_CURLCODE_IF_FAILED(curlcode);
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_READFUNCTION, ReadFile_Callback);
RETURN_CURLCODE_IF_FAILED(curlcode);
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_WRITEFUNCTION, WriteFile_Callback);
RETURN_CURLCODE_IF_FAILED(curlcode);
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_POST, 1L);
RETURN_CURLCODE_IF_FAILED(curlcode);
int fdFileToWrite = ::_open(rkstrSrcFilePath,_O_RDONLY);
if(fdFileToWrite == -1)
RETURN_CURLCODE_IF_FAILED(CURLE_FILE_COULDNT_READ_FILE);
struct _stat fileStat;
_fstat(fdFileToWrite,&fileStat);
::_close(fdFileToWrite);
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_URL, rkstrURL);
RETURN_CURLCODE_IF_FAILED(curlcode);
FILE* pFILEToUpload = ::fopen(rkstrSrcFilePath,"rb");
if(!pFILEToUpload)
RETURN_CURLCODE_IF_FAILED(CURLE_FILE_COULDNT_READ_FILE);
CallBackArgs callBackArgsForFile;
callBackArgsForFile.pointerType = POINTER_FILE;
callBackArgsForFile.ptr = pFILEToUpload;
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_READDATA, &callBackArgsForFile);
RETURN_CURLCODE_IF_FAILED(curlcode);
std::string strHTTPResponseHeader = "";
CallBackArgs callBackArgsForHeader;
callBackArgsForHeader.pointerType = POINTER_STLSTRING;
callBackArgsForHeader.ptr = &strHTTPResponseHeader;
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_WRITEHEADER, &callBackArgsForHeader);
RETURN_CURLCODE_IF_FAILED(curlcode);
std::string strHTTPResponseData = "";
CallBackArgs callBackArgsForResponseFile;
callBackArgsForResponseFile.pointerType = POINTER_STLSTRING;
callBackArgsForResponseFile.ptr = &strHTTPResponseData;
curlcode = curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_WRITEDATA, &callBackArgsForResponseFile);
RETURN_CURLCODE_IF_FAILED(curlcode);
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)fileStat.st_size);
RETURN_CURLCODE_IF_FAILED(curlcode);
struct curl_slist* headers_list=NULL;
ParseHeaderFields(headerFields, &headers_list);
if(headers_list != NULL)
{
//Set Header fields in the request
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_HTTPHEADER, headers_list);
RETURN_CURLCODE_IF_FAILED(curlcode);
}
curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_DEBUGFUNCTION, TraceCurl_Callback);
curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_VERBOSE, 1L);
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_NOBODY, 0L);
RETURN_CURLCODE_IF_FAILED(curlcode);
curlcode = ::curl_easy_perform(m_pCurlEasyHandle);
::fclose(pFILEToUpload);
::fclose(pDestinationFile);
if(headers_list != NULL)
{
curl_slist_free_all(headers_list);
}
//RETURN_CURLCODE_IF_FAILED(curlcode);
if(curlcode != CURLE_OK)
{
LogErrorMessage();
return curlcode;
}
return CURLE_OK;
The InitializeCurlOptions() sets following options: Please note that the purpose of setting these options is to be able to reuse the handle(to reset the options which has been set earlier) in some other case. But in this case(where we are getting this error), we are not reusing the handle.
//Disable Upload. This needs to be set when writing to HCAP (PUT related HTTP requests)
CURLcode curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_UPLOAD, 0L);
RETURN_CURLCODE_IF_FAILED(curlcode);
//Disable PUT. This needs to be set when writing to HCAP (PUT related HTTP requests)
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_PUT, 0L);
RETURN_CURLCODE_IF_FAILED(curlcode);
//Set GET. This is the default setting when CURL is initialized
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_HTTPGET, 1L);
RETURN_CURLCODE_IF_FAILED(curlcode);
//Disable NOBODY. This is the default setting when CURL is initialized. By default we get the file body
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_NOBODY, 0L);
RETURN_CURLCODE_IF_FAILED(curlcode);
//Disable CUSTOMREQUEST. This is the default setting when CURL is initialized.
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_CUSTOMREQUEST, NULL);
RETURN_CURLCODE_IF_FAILED(curlcode);
//Set the DNS cache timeout to 30.
curlcode = ::curl_easy_setopt(m_pCurlEasyHandle, CURLOPT_DNS_CACHE_TIMEOUT, 30);
RETURN_CURLCODE_IF_FAILED(curlcode);
Detailed curl debug logs:
Please note that CURLINFO_TEXT logs "Already in use".
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::TraceCurl_Callback::942:About to connect() to 10.0.8.252 port 80 (#0)
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::TraceCurl_Callback::942: Trying 10.0.8.252...
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:6836, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:065, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::942:About to connect() to 10.0.8.251 port 80 (#0)
{TR, 04/29/2010 02:53:01:065, P:1968, T:6836, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:6836, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:065, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::942: Trying 10.0.8.251...
{TR, 04/29/2010 02:53:01:065, P:1968, T:6836, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::TraceCurl_Callback::942:Address already in use
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::TraceCurl_Callback::942:couldn't connect to host
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::TraceCurl_Callback::942:Closing connection #0
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::TraceCurl_Callback::942:Couldn't connect to server
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} ++CurlHTTPCpp::LogErrorMessage:
{ER, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} CurlHTTPCpp::LogErrorMessage::689:ÀžV R
{TR, 04/29/2010 02:53:01:065, P:1968, T:2788, C:0} --CurlHTTPCpp::LogErrorMessage:
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::942:Address already in use
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::942:couldn't connect to host
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::942:Closing connection #0
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::942:Couldn't connect to server
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} ++CurlHTTPCpp::LogErrorMessage:
{ER, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} CurlHTTPCpp::LogErrorMessage::689:
{TR, 04/29/2010 02:53:01:081, P:1968, T:6836, C:0} --CurlHTTPCpp::LogErrorMessage:
{TR, 04/29/2010 02:53:01:643, P:1968, T:6836, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:643, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:643, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::942:About to connect() to 10.0.8.252 port 80 (#0)
{TR, 04/29/2010 02:53:01:643, P:1968, T:6836, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:643, P:1968, T:6836, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:643, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:643, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::942: Trying 10.0.8.252...
{TR, 04/29/2010 02:53:01:643, P:1968, T:6836, C:0} --CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:643, P:1968, T:6836, C:0} ++CurlHTTPCpp::TraceCurl_Callback:
{TR, 04/29/2010 02:53:01:643, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::908:CURLINFO_TEXT
{TR, 04/29/2010 02:53:01:643, P:1968, T:6836, C:0} CurlHTTPCpp::TraceCurl_Callback::942:connected
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-04-29