curl-library
Re: Recommended architecture for streaming over multiple sockets
Date: Wed, 9 Mar 2016 18:06:12 +0100
*>*I bet this is the piece of code i need to change:
>
> if (bSomethingToDo)
> {
> // Call multi_perform
> curl_multi_perform(m_pstCurlMultiHandle, &iRunningFDs);
> }
> else
> {
> usleep(10000);
> }
>This might seem trivial for you but i'm still learning libcurl and i find
the documentation quite misleading for starters like me..
>
> You could get the finished transfers (from whatever reason) with
> curl_multi_info_read [1]
> Instead of usleep, you should call curl_multi_wait [2] which will return
> to your thread code once there is an event on the sockets / timeout.
> Please look at the code example on curl_multi_wait, it might help you a
> lot.
Ok for curl_multi_info_read. I changed my code as follow :
curlret = curl_multi_perform(m_pstCurlMultiHandle, &iRunningFDs);
if (!iRunningFDs)
{
usleep(10000);
}
else
{
if(curlret == CURLM_OK) {
int iWaitFDs = 0;
/* wait for activity, timeout or "nothing" */
curlret = curl_multi_wait(m_pstCurlMultiHandle, NULL, 0, 10000,
&iWaitFDs);
if (iWaitFDs)
{
struct CURLMsg *m;
do {
int msgq = 0;
m = curl_multi_info_read(m_pstCurlMultiHandle, &msgq);
if(m && (m->msg == CURLMSG_DONE)) {
//Find the connection using this handle
if (m->data.result != CURLE_OK)
{
for (int i = 0; i < MAX_CONNECTIONS; i++)
{
if (m->easy_handle == m_plstCURLHandles[i]->m_pstHandle)
{
CHSSConnection * poConnection = m_plstConnectionList[i];
//Discard all buffers and put session back in PREINIT
poConnection->resetConnection();
//Remove curl handle from multihandle
curl_multi_remove_handle(m_pstCurlMultiHandle,
m->easy_handle);
}
}
}
}
} while(m);
}
}
}
However this does not work, as multi_wait will here "wait" for the
duration. I dont want this behaviour because the data to be sent are coming
from another thread and i want to send them as soon as they are available.
Maybe i should add a specific file descriptor in the multi_wait that would
trigger it ? Seems like quite complicated
Regards
2016-03-09 16:29 GMT+01:00 Yehezkel Horowitz <horowity_at_checkpoint.com>:
> *>*I bet this is the piece of code i need to change:
>
> >
>
> > if (bSomethingToDo)
>
> > {
>
> > // Call multi_perform
>
> > curl_multi_perform(m_pstCurlMultiHandle, &iRunningFDs);
>
> > }
>
> > else
>
> > {
>
> > usleep(10000);
>
> > }
>
>
>
> >This might seem trivial for you but i'm still learning libcurl and i
> find the documentation quite misleading for starters like me..
>
> >
>
> You could get the finished transfers (from whatever reason) with
> curl_multi_info_read [1]
>
> Instead of usleep, you should call curl_multi_wait [2] which will return
> to your thread code once there is an event on the sockets / timeout.
>
> Please look at the code example on curl_multi_wait, it might help you a
> lot.
>
> [1] https://curl.haxx.se/libcurl/c/curl_multi_info_read.html
>
> [2] https://curl.haxx.se/libcurl/c/curl_multi_wait.html
>
> HTH
>
> Yehezkel Horowitz
>
> -------------------------------------------------------------------
> List admin: https://cool.haxx.se/list/listinfo/curl-library
> Etiquette: https://curl.haxx.se/mail/etiquette.html
>
-- Maël BOUTIN
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-03-09