Пример #1
0
/* Called before all the file descriptors are polled by the glib main loop.
   We must have a look at all fds that libcurl wants polled. If any of them
   are new/no longer needed, we have to (de)register them with glib. */
gboolean prepare(GSource* source, gint* timeout) {
  D((stderr, "prepare\n"));
  assert(source == &curlSrc->source);

  if (curlSrc->multiHandle == 0) return FALSE;

  registerUnregisterFds();

  // Handle has been added. we are ready
  if (curlSrc->callPerform == -1) {
      s_currTimeout = *timeout = 0;
      return TRUE;
  }

  long curlTimeout = 0;
  curl_multi_timeout(curlSrc->multiHandle, &curlTimeout);

  // Curl tells us it is ready
  if (curlTimeout == 0) {
      s_currTimeout = *timeout = 0;
      return TRUE;
  }

  // Curl says wait forever. do it only when if we don't have pending
  // connections
  if (curlTimeout < 0) {
      s_currTimeout = *timeout = (s_numEasyHandles > 0) ? GLIBCURL_TIMEOUT : -1;
      return FALSE;
  }

  s_currTimeout = *timeout = MIN(GLIBCURL_TIMEOUT, curlTimeout);
  return FALSE;
}
Пример #2
0
/* Called before all the file descriptors are polled by the glib main loop.
   We must have a look at all fds that libcurl wants polled. If any of them
   are new/no longer needed, we have to (de)register them with glib. */
gboolean prepare(GSource* source, gint* timeout) {
  D((stderr, "prepare\n"));
  assert(source == &curlSrc->source);

  if (curlSrc->multiHandle == 0) return FALSE;

  registerUnregisterFds();

  *timeout = GLIBCURL_TIMEOUT;
/*   return FALSE; */
  return curlSrc->callPerform == -1 ? TRUE : FALSE;
}
Пример #3
0
gboolean dispatch(GSource* source, GSourceFunc callback,
                  gpointer user_data) {
  CURLMcode x;

  assert(source == &curlSrc->source);
  assert(curlSrc->multiHandle != 0);
  do {
    x = curl_multi_perform(curlSrc->multiHandle, &curlSrc->callPerform);
/*     D((stderr, "dispatched %d\n", x)); */
  } while (x == CURLM_CALL_MULTI_PERFORM);

  /* If no more calls to curl_multi_perform(), unregister left-over fds */
  if (curlSrc->callPerform == 0) registerUnregisterFds();

  if (callback != 0) (*callback)(user_data);

  return TRUE; /* "Do not destroy me" */
}
Пример #4
0
void finalize(GSource* source) {
  assert(source == &curlSrc->source);
  registerUnregisterFds();
}