}
while (U) {
- while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(cm, &U));
+ curl_multi_perform(cm, &U);
if (U) {
FD_ZERO(&R);
struct ev_io fifo_event;
struct ev_timer timer_event;
CURLM *multi;
- int prev_running;
int still_running;
FILE* input;
} GlobalInfo;
switch ( code )
{
case CURLM_CALL_MULTI_PERFORM: s="CURLM_CALL_MULTI_PERFORM"; break;
- case CURLM_OK: s="CURLM_OK"; break;
case CURLM_BAD_HANDLE: s="CURLM_BAD_HANDLE"; break;
case CURLM_BAD_EASY_HANDLE: s="CURLM_BAD_EASY_HANDLE"; break;
case CURLM_OUT_OF_MEMORY: s="CURLM_OUT_OF_MEMORY"; break;
/* Check for completed transfers, and remove their easy handles */
-static void check_run_count(GlobalInfo *g)
+static void check_multi_info(GlobalInfo *g)
{
- DPRINT("%s prev %i still %i\n", __PRETTY_FUNCTION__,
- g->prev_running, g->still_running);
- if ( g->prev_running > g->still_running )
- {
- char *eff_url=NULL;
- CURLMsg *msg;
- int msgs_left;
- ConnInfo *conn=NULL;
- CURL*easy;
- CURLcode res;
-
- fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running);
- /*
- I am still uncertain whether it is safe to remove an easy
- handle from inside the curl_multi_info_read loop, so here I
- will search for completed transfers in the inner "while"
- loop, and then remove them in the outer "do-while" loop...
- */
- do
- {
- easy=NULL;
- while ( (msg = curl_multi_info_read(g->multi, &msgs_left)) )
- {
- if ( msg->msg == CURLMSG_DONE )
- {
- easy=msg->easy_handle;
- res=msg->data.result;
- }
-
- if ( easy )
- {
- curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn);
- curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url);
- fprintf(MSG_OUT, "DONE: %s => (%d) %s\n", eff_url, res, conn->error);
- curl_multi_remove_handle(g->multi, easy);
- free(conn->url);
- curl_easy_cleanup(easy);
- free(conn);
- }
- }
- } while ( easy );
+ char *eff_url;
+ CURLMsg *msg;
+ int msgs_left;
+ ConnInfo *conn;
+ CURL *easy;
+ CURLcode res;
+
+ fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running);
+ while ((msg = curl_multi_info_read(g->multi, &msgs_left))) {
+ if (msg->msg == CURLMSG_DONE) {
+ easy = msg->easy_handle;
+ res = msg->data.result;
+ curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn);
+ curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url);
+ fprintf(MSG_OUT, "DONE: %s => (%d) %s\n", eff_url, res, conn->error);
+ curl_multi_remove_handle(g->multi, easy);
+ free(conn->url);
+ curl_easy_cleanup(easy);
+ free(conn);
+ }
}
- g->prev_running = g->still_running;
}
+
/* Called by libevent when we get action on a multi socket */
static void event_cb(EV_P_ struct ev_io *w, int revents)
{
int action = (revents&EV_READ?CURL_POLL_IN:0)|
(revents&EV_WRITE?CURL_POLL_OUT:0);
- do
- {
- rc = curl_multi_socket_action(g->multi, w->fd, action, &g->still_running);
- } while ( rc == CURLM_CALL_MULTI_PERFORM );
- mcode_or_die("event_cb: curl_multi_socket", rc);
- check_run_count(g);
+ rc = curl_multi_socket_action(g->multi, w->fd, action, &g->still_running);
+ mcode_or_die("event_cb: curl_multi_socket_action", rc);
+ check_multi_info(g);
if ( g->still_running <= 0 )
{
fprintf(MSG_OUT, "last transfer done, kill timeout\n");
GlobalInfo *g = (GlobalInfo *)w->data;
CURLMcode rc;
- do
- {
- rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &g->still_running);
- } while ( rc == CURLM_CALL_MULTI_PERFORM );
- mcode_or_die("timer_cb: curl_multi_socket", rc);
- check_run_count(g);
+ rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &g->still_running);
+ mcode_or_die("timer_cb: curl_multi_socket_action", rc);
+ check_multi_info(g);
}
/* Clean up the SockInfo structure */
fprintf(MSG_OUT,
"Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url);
- rc =curl_multi_add_handle(g->multi, conn->easy);
+ rc = curl_multi_add_handle(g->multi, conn->easy);
mcode_or_die("new_conn: curl_multi_add_handle", rc);
- mcode_or_die("new_conn: curl_multi_socket_all", rc);
- check_run_count(g);
+ /* note that the add_handle() will set a time-out to trigger very soon so
+ that the necessary socket_action() call will be called by this app */
}
/* This gets called whenever data is received from the fifo */
curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g);
curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb);
curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g);
- do
- {
- rc = curl_multi_socket_all(g.multi, &g.still_running);
- } while ( CURLM_CALL_MULTI_PERFORM == rc );
+
+ /* we don't call any curl_multi_socket*() function yet as we have no handles
+ added! */
ev_loop(g.loop, 0);
curl_multi_cleanup(g.multi);
default:
/* timeout or readable/writable sockets */
- /* note we *could* be more efficient and not wait for
- * CURLM_CALL_MULTI_PERFORM to clear here and check it on re-entry
- * but that gets messy */
- while(curl_multi_perform(multi_handle, &file->still_running) ==
- CURLM_CALL_MULTI_PERFORM);
-
+ curl_multi_perform(multi_handle, &file->still_running);
break;
}
} while(file->still_running && (file->buffer_pos < want));
curl_multi_add_handle(multi_handle, file->handle.curl);
/* lets start the fetch */
- while(curl_multi_perform(multi_handle, &file->still_running) ==
- CURLM_CALL_MULTI_PERFORM );
+ curl_multi_perform(multi_handle, &file->still_running);
if((file->buffer_pos == 0) && (!file->still_running))
{
typedef struct _GlobalInfo {
CURLM *multi;
guint timer_event;
- int prev_running;
int still_running;
- int requested; /* count: curl_easy_init() */
- int completed; /* count: curl_easy_cleanup() */
} GlobalInfo;
const char *s;
switch (code) {
case CURLM_CALL_MULTI_PERFORM: s="CURLM_CALL_MULTI_PERFORM"; break;
- case CURLM_OK: s="CURLM_OK"; break;
case CURLM_BAD_HANDLE: s="CURLM_BAD_HANDLE"; break;
case CURLM_BAD_EASY_HANDLE: s="CURLM_BAD_EASY_HANDLE"; break;
case CURLM_OUT_OF_MEMORY: s="CURLM_OUT_OF_MEMORY"; break;
/* Check for completed transfers, and remove their easy handles */
-static void check_run_count(GlobalInfo *g)
+static void check_multi_info(GlobalInfo *g)
{
- if (g->prev_running > g->still_running) {
- char *eff_url=NULL;
- CURLMsg *msg;
- int msgs_left;
- ConnInfo *conn=NULL;
- CURL*easy;
- CURLcode res;
-
- MSG_OUT("REMAINING: %d\n", g->still_running);
- /*
- I am still uncertain whether it is safe to remove an easy handle
- from inside the curl_multi_info_read loop, so here I will search
- for completed transfers in the inner "while" loop, and then remove
- them in the outer "do-while" loop...
- */
- do {
- easy=NULL;
- while ((msg = curl_multi_info_read(g->multi, &msgs_left))) {
- if (msg->msg == CURLMSG_DONE) {
- easy=msg->easy_handle;
- res=msg->data.result;
- break;
- }
- }
- if (easy) {
- curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn);
- curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url);
- MSG_OUT("DONE: %s => (%d) %s\n", eff_url, res, conn->error);
- curl_multi_remove_handle(g->multi, easy);
- g_free(conn->url);
- curl_easy_cleanup(easy);
- g_free(conn);
- g->completed++;
- }
- } while ( easy );
- MSG_OUT("Requested: %d Completed:%d\n", g->requested, g->completed);
+ char *eff_url;
+ CURLMsg *msg;
+ int msgs_left;
+ ConnInfo *conn;
+ CURL *easy;
+ CURLcode res;
+
+ MSG_OUT("REMAINING: %d\n", g->still_running);
+ while ((msg = curl_multi_info_read(g->multi, &msgs_left))) {
+ if (msg->msg == CURLMSG_DONE) {
+ easy = msg->easy_handle;
+ res = msg->data.result;
+ curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn);
+ curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url);
+ MSG_OUT("DONE: %s => (%d) %s\n", eff_url, res, conn->error);
+ curl_multi_remove_handle(g->multi, easy);
+ free(conn->url);
+ curl_easy_cleanup(easy);
+ free(conn);
+ }
}
- g->prev_running = g->still_running;
}
-
/* Called by glib when our timeout expires */
static gboolean timer_cb(gpointer data)
{
GlobalInfo *g = (GlobalInfo *)data;
CURLMcode rc;
- do {
- rc = curl_multi_socket(g->multi, CURL_SOCKET_TIMEOUT, &g->still_running);
- } while (rc == CURLM_CALL_MULTI_PERFORM);
- mcode_or_die("timer_cb: curl_multi_socket", rc);
- check_run_count(g);
+ rc = curl_multi_socket_action(g->multi,
+ CURL_SOCKET_TIMEOUT, 0, &g->still_running);
+ mcode_or_die("timer_cb: curl_multi_socket_action", rc);
+ check_multi_info(g);
return FALSE;
}
GlobalInfo *g = (GlobalInfo*) data;
CURLMcode rc;
int fd=g_io_channel_unix_get_fd(ch);
- do {
- rc = curl_multi_socket(g->multi, fd, &g->still_running);
- } while (rc == CURLM_CALL_MULTI_PERFORM);
- mcode_or_die("event_cb: curl_multi_socket", rc);
- check_run_count(g);
+
+ int action =
+ (condition & G_IO_IN ? CURL_CSELECT_IN : 0) |
+ (condition & G_IO_OUT ? CURL_CSELECT_OUT : 0);
+
+ rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running);
+ mcode_or_die("event_cb: curl_multi_socket_action", rc);
+
+ check_multi_info(g);
if(g->still_running) {
return TRUE;
} else {
MSG_OUT("Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url);
rc =curl_multi_add_handle(g->multi, conn->easy);
mcode_or_die("new_conn: curl_multi_add_handle", rc);
- g->requested++;
- do {
- rc = curl_multi_socket_all(g->multi, &g->still_running);
- } while (CURLM_CALL_MULTI_PERFORM == rc);
- mcode_or_die("new_conn: curl_multi_socket_all", rc);
- check_run_count(g);
+
+ /* note that the add_handle() will set a time-out to trigger very soon so
+ that the necessary socket_action() call will be called by this app */
}
curl_multi_setopt(g->multi, CURLMOPT_SOCKETDATA, g);
curl_multi_setopt(g->multi, CURLMOPT_TIMERFUNCTION, update_timeout_cb);
curl_multi_setopt(g->multi, CURLMOPT_TIMERDATA, g);
- do {
- rc = curl_multi_socket_all(g->multi, &g->still_running);
- } while (CURLM_CALL_MULTI_PERFORM == rc);
+
+ /* we don't call any curl_multi_socket*() function yet as we have no handles
+ added! */
+
g_main_loop_run(gmain);
curl_multi_cleanup(g->multi);
return 0;
struct event fifo_event;
struct event timer_event;
CURLM *multi;
- int prev_running;
int still_running;
FILE* input;
} GlobalInfo;
const char *s;
switch (code) {
case CURLM_CALL_MULTI_PERFORM: s="CURLM_CALL_MULTI_PERFORM"; break;
- case CURLM_OK: s="CURLM_OK"; break;
case CURLM_BAD_HANDLE: s="CURLM_BAD_HANDLE"; break;
case CURLM_BAD_EASY_HANDLE: s="CURLM_BAD_EASY_HANDLE"; break;
case CURLM_OUT_OF_MEMORY: s="CURLM_OUT_OF_MEMORY"; break;
/* Check for completed transfers, and remove their easy handles */
-static void check_run_count(GlobalInfo *g)
+static void check_multi_info(GlobalInfo *g)
{
- if (g->prev_running > g->still_running) {
- char *eff_url=NULL;
- CURLMsg *msg;
- int msgs_left;
- ConnInfo *conn=NULL;
- CURL*easy;
- CURLcode res;
-
- fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running);
- /*
- I am still uncertain whether it is safe to remove an easy handle
- from inside the curl_multi_info_read loop, so here I will search
- for completed transfers in the inner "while" loop, and then remove
- them in the outer "do-while" loop...
- */
- do {
- easy=NULL;
- while ((msg = curl_multi_info_read(g->multi, &msgs_left))) {
- if (msg->msg == CURLMSG_DONE) {
- easy=msg->easy_handle;
- res=msg->data.result;
- break;
- }
- }
- if (easy) {
- curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn);
- curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url);
- fprintf(MSG_OUT, "DONE: %s => (%d) %s\n", eff_url, res, conn->error);
- curl_multi_remove_handle(g->multi, easy);
- free(conn->url);
- curl_easy_cleanup(easy);
- free(conn);
- }
- } while ( easy );
+ char *eff_url;
+ CURLMsg *msg;
+ int msgs_left;
+ ConnInfo *conn;
+ CURL *easy;
+ CURLcode res;
+
+ fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running);
+ while ((msg = curl_multi_info_read(g->multi, &msgs_left))) {
+ if (msg->msg == CURLMSG_DONE) {
+ easy = msg->easy_handle;
+ res = msg->data.result;
+ curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn);
+ curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url);
+ fprintf(MSG_OUT, "DONE: %s => (%d) %s\n", eff_url, res, conn->error);
+ curl_multi_remove_handle(g->multi, easy);
+ free(conn->url);
+ curl_easy_cleanup(easy);
+ free(conn);
+ }
}
- g->prev_running = g->still_running;
}
CURLMcode rc;
int action =
- (kind&EV_READ?CURL_CSELECT_IN:0)|
- (kind&EV_WRITE?CURL_CSELECT_OUT:0);
-
- do {
- rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running);
- } while (rc == CURLM_CALL_MULTI_PERFORM);
+ (kind & EV_READ ? CURL_CSELECT_IN : 0) |
+ (kind & EV_WRITE ? CURL_CSELECT_OUT : 0);
+ rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running);
mcode_or_die("event_cb: curl_multi_socket_action", rc);
- check_run_count(g);
+ check_multi_info(g);
if ( g->still_running <= 0 ) {
fprintf(MSG_OUT, "last transfer done, kill timeout\n");
if (evtimer_pending(&g->timer_event, NULL)) {
(void)fd;
(void)kind;
- do {
- rc = curl_multi_socket_action(g->multi,
+ rc = curl_multi_socket_action(g->multi,
CURL_SOCKET_TIMEOUT, 0, &g->still_running);
- } while (rc == CURLM_CALL_MULTI_PERFORM);
mcode_or_die("timer_cb: curl_multi_socket_action", rc);
- check_run_count(g);
+ check_multi_info(g);
}
curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn);
fprintf(MSG_OUT,
"Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url);
- rc =curl_multi_add_handle(g->multi, conn->easy);
+ rc = curl_multi_add_handle(g->multi, conn->easy);
mcode_or_die("new_conn: curl_multi_add_handle", rc);
/* note that the add_handle() will set a time-out to trigger very soon so
curl_multi_add_handle(multi_handle, handles[i]);
/* we start some action by calling perform right away */
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(multi_handle, &still_running));
+ curl_multi_perform(multi_handle, &still_running);
while(still_running) {
struct timeval timeout;
default:
/* one or more of curl's file descriptors say there's data to read
or write */
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(multi_handle, &still_running));
+ curl_multi_perform(multi_handle, &still_running);
break;
}
}
curl_multi_add_handle(multi_handle, http_handle);
/* we start some action by calling perform right away */
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(multi_handle, &still_running));
+ curl_multi_perform(multi_handle, &still_running);
while(still_running) {
struct timeval timeout;
case 0:
default:
/* timeout or readable/writable sockets */
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(multi_handle, &still_running));
+ curl_multi_perform(multi_handle, &still_running);
break;
}
}
curl_multi_add_handle(multi_handle, http_handle2);
/* we start some action by calling perform right away */
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(multi_handle, &still_running));
+ curl_multi_perform(multi_handle, &still_running);
while(still_running) {
struct timeval timeout;
case 0:
default:
/* timeout or readable/writable sockets */
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(multi_handle, &still_running));
+ curl_multi_perform(multi_handle, &still_running);
break;
}
}
curl_multi_add_handle(multi_handle, curl);
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(multi_handle, &still_running));
+ curl_multi_perform(multi_handle, &still_running);
while(still_running) {
struct timeval timeout;
default:
/* timeout or readable/writable sockets */
printf("perform!\n");
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(multi_handle, &still_running));
+ curl_multi_perform(multi_handle, &still_running);
printf("running: %d!\n", still_running);
break;
}
curl_multi_add_handle(multi_handle, http_handle);
/* we start some action by calling perform right away */
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(multi_handle, &still_running));
+ curl_multi_perform(multi_handle, &still_running);
while(still_running) {
struct timeval timeout;
case 0:
default:
/* timeout or readable/writable sockets */
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(multi_handle, &still_running));
+ curl_multi_perform(multi_handle, &still_running);
break;
}
}