#include <event2/buffer.h>
#include "transmission.h"
-#include "list.h"
#include "net.h" /* tr_address */
#include "platform.h" /* mutex */
#include "session.h"
} while( 0 )
#endif
-/***
-****
-***/
-
-struct tr_web
-{
- bool curl_verbose;
- int close_mode;
- tr_list * tasks;
- tr_lock * taskLock;
- char * cookie_filename;
-};
-
-
/***
****
***/
tr_session * session;
tr_web_done_func * done_func;
void * done_func_user_data;
+ struct tr_web_task * next;
};
static void
****
***/
+struct tr_web
+{
+ bool curl_verbose;
+ int close_mode;
+ struct tr_web_task * tasks;
+ tr_lock * taskLock;
+ char * cookie_filename;
+};
+
+/***
+****
+***/
+
static size_t
writeFunc( void * ptr, size_t size, size_t nmemb, void * vtask )
{
task->freebuf = buffer ? NULL : task->response;
tr_lockLock( web->taskLock );
- tr_list_append( &web->tasks, task );
+ task->next = web->tasks;
+ web->tasks = task;
tr_lockUnlock( web->taskLock );
}
}
/* add tasks from the queue */
tr_lockLock( web->taskLock );
- while(( task = tr_list_pop_front( &web->tasks )))
+ while( web->tasks != NULL )
{
+ /* pop the task */
+ task = web->tasks;
+ web->tasks = task->next;
+ task->next = NULL;
+
dbgmsg( "adding task to curl: [%s]", task->url );
curl_multi_add_handle( multi, createEasy( session, web, task ));
/*fprintf( stderr, "adding a task.. taskCount is now %d\n", taskCount );*/
--taskCount;
}
}
-
-#if 0
-{
-tr_list * l;
-for( l=web->tasks; l!=NULL; l=l->next )
- fprintf( stderr, "still pending: %s\n", ((struct tr_web_task*)l->data)->url );
-}
-fprintf( stderr, "loop is ending... web is closing\n" );
-#endif
}
/* Discard any remaining tasks.
* This is rare, but can happen on shutdown with unresponsive trackers. */
- while(( task = tr_list_pop_front( &web->tasks ))) {
+ while( web->tasks != NULL ) {
+ task = web->tasks;
+ web->tasks = task->next;
dbgmsg( "Discarding task \"%s\"", task->url );
task_free( task );
}