mirror of
https://github.com/transmission/transmission
synced 2024-12-26 09:37:56 +00:00
(libT) maybe fix the evhttp issues that softwareelves reported
This commit is contained in:
parent
830bb2f57b
commit
859af09f37
2 changed files with 42 additions and 20 deletions
|
@ -398,8 +398,10 @@ handle_request( struct evhttp_request * req,
|
|||
}
|
||||
|
||||
static void
|
||||
startServer( tr_rpc_server * server )
|
||||
startServer( void * vserver )
|
||||
{
|
||||
tr_rpc_server * server = vserver;
|
||||
|
||||
fprintf( stderr, "%s:%d in startServer; current context is %p\n", __FILE__, __LINE__, server->httpd );
|
||||
|
||||
if( !server->httpd )
|
||||
|
@ -423,16 +425,25 @@ stopServer( tr_rpc_server * server )
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
onEnabledChanged( void * vserver )
|
||||
{
|
||||
tr_rpc_server * server = vserver;
|
||||
|
||||
if( !server->isEnabled )
|
||||
stopServer( server );
|
||||
else
|
||||
startServer( server );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
tr_rpcSetEnabled( tr_rpc_server * server,
|
||||
int isEnabled )
|
||||
{
|
||||
server->isEnabled = isEnabled != 0;
|
||||
|
||||
if( !isEnabled )
|
||||
stopServer( server );
|
||||
else
|
||||
startServer( server );
|
||||
tr_runInEventThread( server->session, onEnabledChanged, server );
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -441,6 +452,18 @@ tr_rpcIsEnabled( const tr_rpc_server * server )
|
|||
return server->isEnabled;
|
||||
}
|
||||
|
||||
static void
|
||||
restartServer( void * vserver )
|
||||
{
|
||||
tr_rpc_server * server = vserver;
|
||||
|
||||
if( server->isEnabled )
|
||||
{
|
||||
stopServer( server );
|
||||
startServer( server );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tr_rpcSetPort( tr_rpc_server * server,
|
||||
uint16_t port )
|
||||
|
@ -450,10 +473,7 @@ tr_rpcSetPort( tr_rpc_server * server,
|
|||
server->port = port;
|
||||
|
||||
if( server->isEnabled )
|
||||
{
|
||||
stopServer( server );
|
||||
startServer( server );
|
||||
}
|
||||
tr_runInEventThread( server->session, restartServer, server );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -529,13 +549,10 @@ tr_rpcIsPasswordEnabled( const tr_rpc_server * server )
|
|||
***** LIFE CYCLE
|
||||
****/
|
||||
|
||||
void
|
||||
tr_rpcClose( tr_rpc_server ** ps )
|
||||
static void
|
||||
closeServer( void * vserver )
|
||||
{
|
||||
tr_rpc_server * s = *ps;
|
||||
|
||||
*ps = NULL;
|
||||
|
||||
tr_rpc_server * s = vserver;
|
||||
stopServer( s );
|
||||
tr_free( s->acl );
|
||||
tr_free( s->username );
|
||||
|
@ -543,6 +560,13 @@ tr_rpcClose( tr_rpc_server ** ps )
|
|||
tr_free( s );
|
||||
}
|
||||
|
||||
void
|
||||
tr_rpcClose( tr_rpc_server ** ps )
|
||||
{
|
||||
tr_runInEventThread( (*ps)->session, closeServer, *ps );
|
||||
*ps = NULL;
|
||||
}
|
||||
|
||||
tr_rpc_server *
|
||||
tr_rpcInit( tr_handle * session,
|
||||
int isEnabled,
|
||||
|
@ -562,9 +586,8 @@ tr_rpcInit( tr_handle * session,
|
|||
s->password = tr_strdup( password );
|
||||
s->isPasswordEnabled = isPasswordEnabled != 0;
|
||||
s->isEnabled = isEnabled != 0;
|
||||
|
||||
if( isEnabled )
|
||||
startServer( s );
|
||||
tr_runInEventThread( session, startServer, s );
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ logFunc( int severity,
|
|||
static void
|
||||
libeventThreadFunc( void * veh )
|
||||
{
|
||||
tr_event_handle * eh = (tr_event_handle *) veh;
|
||||
tr_event_handle * eh = veh;
|
||||
|
||||
tr_dbg( "Starting libevent thread" );
|
||||
|
||||
|
@ -154,9 +154,7 @@ libeventThreadFunc( void * veh )
|
|||
signal( SIGPIPE, SIG_IGN );
|
||||
#endif
|
||||
|
||||
eh->base = event_init( );
|
||||
eh->h->events = eh;
|
||||
event_set_log_callback( logFunc );
|
||||
|
||||
/* listen to the pipe's read fd */
|
||||
event_set( &eh->pipeEvent, eh->fds[0], EV_READ | EV_PERSIST,
|
||||
|
@ -182,6 +180,7 @@ tr_eventInit( tr_handle * handle )
|
|||
eh->lock = tr_lockNew( );
|
||||
pipe( eh->fds );
|
||||
eh->h = handle;
|
||||
eh->base = event_init( );
|
||||
eh->thread = tr_threadNew( libeventThreadFunc, eh );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue