mirror of
https://github.com/transmission/transmission
synced 2024-12-27 10:07:40 +00:00
(trunk libT) keep simplifying web.c... is there anything left to strip out?
This commit is contained in:
parent
11c119d960
commit
ee0de4b06c
1 changed files with 15 additions and 29 deletions
|
@ -26,8 +26,6 @@ enum
|
||||||
DEFAULT_TIMER_MSEC = 1500 /* arbitrary */
|
DEFAULT_TIMER_MSEC = 1500 /* arbitrary */
|
||||||
};
|
};
|
||||||
|
|
||||||
static tr_bool tr_multi_perform( tr_web * g, int fd );
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#define dbgmsg(...) \
|
#define dbgmsg(...) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -45,17 +43,17 @@ static tr_bool tr_multi_perform( tr_web * g, int fd );
|
||||||
struct tr_web
|
struct tr_web
|
||||||
{
|
{
|
||||||
tr_bool closing;
|
tr_bool closing;
|
||||||
|
tr_bool haveAddr;
|
||||||
int taskCount;
|
int taskCount;
|
||||||
long timer_msec;
|
long timer_msec;
|
||||||
CURLM * multi;
|
CURLM * multi;
|
||||||
tr_session * session;
|
tr_session * session;
|
||||||
tr_bool haveAddr;
|
|
||||||
tr_address addr;
|
tr_address addr;
|
||||||
struct event timer_event;
|
struct event timer_event;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
web_close( tr_web * g )
|
web_free( tr_web * g )
|
||||||
{
|
{
|
||||||
curl_multi_cleanup( g->multi );
|
curl_multi_cleanup( g->multi );
|
||||||
evtimer_del( &g->timer_event );
|
evtimer_del( &g->timer_event );
|
||||||
|
@ -193,7 +191,6 @@ addTask( void * vtask )
|
||||||
|
|
||||||
mcode = curl_multi_add_handle( web->multi, e );
|
mcode = curl_multi_add_handle( web->multi, e );
|
||||||
++web->taskCount;
|
++web->taskCount;
|
||||||
/*tr_multi_perform( web, CURL_SOCKET_TIMEOUT );*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,27 +240,24 @@ restart_timer( tr_web * g )
|
||||||
tr_timerAddMsec( &g->timer_event, g->timer_msec );
|
tr_timerAddMsec( &g->timer_event, g->timer_msec );
|
||||||
}
|
}
|
||||||
|
|
||||||
static tr_bool
|
static void
|
||||||
tr_multi_perform( tr_web * g, int fd )
|
tr_multi_perform( tr_web * g, int fd )
|
||||||
{
|
{
|
||||||
CURLMcode mcode;
|
CURLMcode mcode;
|
||||||
tr_bool closed = FALSE;
|
|
||||||
|
|
||||||
dbgmsg( "check_run_count: %d taskCount", g->taskCount );
|
dbgmsg( "check_run_count: %d taskCount", g->taskCount );
|
||||||
|
|
||||||
/* invoke libcurl's processing */
|
/* invoke libcurl's processing */
|
||||||
do {
|
do
|
||||||
mcode = curl_multi_socket_action( g->multi, fd, 0, &g->taskCount );
|
mcode = curl_multi_socket_action( g->multi, fd, 0, &g->taskCount );
|
||||||
} while( mcode == CURLM_CALL_MULTI_SOCKET );
|
while( mcode == CURLM_CALL_MULTI_SOCKET );
|
||||||
|
|
||||||
remove_finished_tasks( g );
|
remove_finished_tasks( g );
|
||||||
|
|
||||||
if(( closed = g->closing && !g->taskCount ))
|
if( g->closing && !g->taskCount )
|
||||||
web_close( g );
|
web_free( g );
|
||||||
else
|
else
|
||||||
restart_timer( g );
|
restart_timer( g );
|
||||||
|
|
||||||
return closed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* libevent says that sock is ready to be processed, so wake up libcurl */
|
/* libevent says that sock is ready to be processed, so wake up libcurl */
|
||||||
|
@ -275,14 +269,13 @@ event_cb( int fd, short kind UNUSED, void * g )
|
||||||
|
|
||||||
/* CURLMOPT_SOCKETFUNCTION */
|
/* CURLMOPT_SOCKETFUNCTION */
|
||||||
static int
|
static int
|
||||||
sock_cb( CURL * easy UNUSED, curl_socket_t fd, int action,
|
sock_cb( CURL * e UNUSED, curl_socket_t fd, int action,
|
||||||
void * vweb, void * vevent )
|
void * vweb, void * vevent )
|
||||||
{
|
{
|
||||||
/*static int num_events = 0;*/
|
/*static int num_events = 0;*/
|
||||||
struct tr_web * web = vweb;
|
struct tr_web * web = vweb;
|
||||||
struct event * io_event = vevent;
|
struct event * io_event = vevent;
|
||||||
dbgmsg( "sock_cb: action is %d, fd is %d, io_event is %p",
|
dbgmsg( "sock_cb: action %d, fd %d, io_event %p", action, (int)fd, io_event );
|
||||||
action, (int)fd, io_event );
|
|
||||||
|
|
||||||
if( action == CURL_POLL_REMOVE )
|
if( action == CURL_POLL_REMOVE )
|
||||||
{
|
{
|
||||||
|
@ -333,18 +326,11 @@ static void
|
||||||
multi_timer_cb( CURLM * multi UNUSED, long timer_msec, void * vg )
|
multi_timer_cb( CURLM * multi UNUSED, long timer_msec, void * vg )
|
||||||
{
|
{
|
||||||
tr_web * g = vg;
|
tr_web * g = vg;
|
||||||
tr_bool closed = FALSE;
|
|
||||||
|
|
||||||
if( timer_msec < 1 ) {
|
g->timer_msec = timer_msec > 0 ? timer_msec : DEFAULT_TIMER_MSEC;
|
||||||
if( timer_msec == 0 ) /* call it immediately */
|
|
||||||
closed = tr_multi_perform( g, CURL_SOCKET_TIMEOUT );
|
|
||||||
timer_msec = DEFAULT_TIMER_MSEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !closed ) {
|
if( timer_msec < 1 )
|
||||||
g->timer_msec = timer_msec;
|
tr_multi_perform( g, CURL_SOCKET_TIMEOUT );
|
||||||
restart_timer( g );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****
|
/****
|
||||||
|
@ -369,7 +355,6 @@ tr_webRun( tr_session * session,
|
||||||
task->done_func_user_data = done_func_user_data;
|
task->done_func_user_data = done_func_user_data;
|
||||||
task->tag = ++tag;
|
task->tag = ++tag;
|
||||||
task->response = evbuffer_new( );
|
task->response = evbuffer_new( );
|
||||||
|
|
||||||
tr_runInEventThread( session, addTask, task );
|
tr_runInEventThread( session, addTask, task );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,7 +396,7 @@ tr_webClose( tr_web ** web_in )
|
||||||
tr_web * web = *web_in;
|
tr_web * web = *web_in;
|
||||||
*web_in = NULL;
|
*web_in = NULL;
|
||||||
if( web->taskCount < 1 )
|
if( web->taskCount < 1 )
|
||||||
web_close( web );
|
web_free( web );
|
||||||
else
|
else
|
||||||
web->closing = 1;
|
web->closing = 1;
|
||||||
}
|
}
|
||||||
|
@ -472,7 +457,8 @@ tr_webGetResponseStr( long code )
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tr_http_escape( struct evbuffer * out, const char * str, int len, tr_bool escape_slashes )
|
tr_http_escape( struct evbuffer * out,
|
||||||
|
const char * str, int len, tr_bool escape_slashes )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue