cURL / Mailing Lists / curl-library / Single Mail

curl-library

Problem in sending data to http server - threading related?

From: adam galarneau <machoman81_1_at_yahoo.com>
Date: Fri, 31 Aug 2012 21:50:38 -0700 (PDT)

Hello!  I'm having problems sending data through curl to an http server. When trying to send 50 requests in one iteration, the data is sent in bursts (4-5 requests send every 3 seconds or so). I was able to remove the problem by adding a sleep in between sending requests AND processing the messages for all the handles in between each RequestFiltering but that's not a solution... RequestFiltering and ReadMessages' code is shown below. Initial pseudo-code that doesn't work (executed each thread iteration): while having messages RequestFiltering(pMsg); while having requests to process ReadMessages(request) DOESN'T WORK: while having messages RequestFiltering(pMsg) sleep while having requests to process ReadMessages(request) DOESN'T WORK: while having messages RequestFiltering(pMsg) ReadMessages for previous msg only sleep while having requests to process ReadMessages(request) WORKS: while having messages RequestFiltering(pMsg) while having requests to process ReadMessages(request) sleep This is the code: RequestFiltering - sends an http request to the server.  m_RequestsList.push_back(FilterRequest(pMsg, m_pOwner, curl_multi_init(), curl_easy_init(), 0)); FilterRequest &filterRequest = m_RequestsList.back(); curl_easy_setopt(filterRequest.m_pCurlE, CURLOPT_PROTOCOLS, CURLPROTO_HTTP); curl_easy_setopt(filterRequest.m_pCurlE, CURLOPT_URL, filterRequest.m_strAddress.c_str()); curl_easy_setopt(filterRequest.m_pCurlE, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(filterRequest.m_pCurlE, CURLOPT_WRITEFUNCTION, MemoryCallback); curl_easy_setopt(filterRequest.m_pCurlE, CURLOPT_WRITEDATA, filterRequest.m_pMem); CURLMcode res = curl_multi_add_handle(filterRequest.m_pCurlM, filterRequest.m_pCurlE); switch( res ) { case CURLM_CALL_MULTI_PERFORM: //ReadMessages(filterRequest);  // is that needed? case CURLM_OK: // everything's good! return true; break; default: ServerInstance->Logs->Log("DREAMWORLD", DEFAULT, "Cannot process chat message (%s).", curl_multi_strerror(res)); break; }; ReadMessages - read all the messages for one multi handle (one multi for each request so only one easy handle) CURLMcode res = curl_multi_perform(filterRequest.m_pCurlM, &filterRequest.m_nRunningHandles); //if( res == CURLM_CALL_MULTI_PERFORM  ) //continue; // read all messages for this handle int nMsgInQueue = 0; CURLMsg *pMessage = curl_multi_info_read(filterRequest.m_pCurlM, &nMsgInQueue);  while( pMessage != 0 ) { switch( pMessage->msg ) { case CURLMSG_DONE: // thats the only message type defined in the doc switch( pMessage->data.result ) { case CURLE_OK: // its done! running handles is 0 so no need to do anything else break; default: // error in process - just cancel it ServerInstance->Logs->Log("DREAMWORLD", DEFAULT, "Curl error processing the filter request! ('%s') - '%s'.",  curl_easy_strerror(pMessage->data.result), filterRequest.m_pMsg->m_strText.c_str()); filterRequest.m_nRunningHandles = 0; break; }; break; default: // doc says thats impossible ServerInstance->Logs->Log("DREAMWORLD", DEFAULT, "Something impossible happenned! (%d)", (int)pMessage->msg); break; }; pMessage = curl_multi_info_read(filterRequest.m_pCurlM, &nMsgInQueue); } Any ideas? Thanks! Adam

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-09-01