1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 18:18:10 +00:00

(libT) maybe fix the evhttp issues that softwareelves reported

This commit is contained in:
Charles Kerr 2008-10-01 04:26:38 +00:00
parent 830bb2f57b
commit 859af09f37
2 changed files with 42 additions and 20 deletions

View file

@ -398,8 +398,10 @@ handle_request( struct evhttp_request * req,
} }
static void 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 ); fprintf( stderr, "%s:%d in startServer; current context is %p\n", __FILE__, __LINE__, server->httpd );
if( !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 void
tr_rpcSetEnabled( tr_rpc_server * server, tr_rpcSetEnabled( tr_rpc_server * server,
int isEnabled ) int isEnabled )
{ {
server->isEnabled = isEnabled != 0; server->isEnabled = isEnabled != 0;
if( !isEnabled ) tr_runInEventThread( server->session, onEnabledChanged, server );
stopServer( server );
else
startServer( server );
} }
int int
@ -441,6 +452,18 @@ tr_rpcIsEnabled( const tr_rpc_server * server )
return server->isEnabled; return server->isEnabled;
} }
static void
restartServer( void * vserver )
{
tr_rpc_server * server = vserver;
if( server->isEnabled )
{
stopServer( server );
startServer( server );
}
}
void void
tr_rpcSetPort( tr_rpc_server * server, tr_rpcSetPort( tr_rpc_server * server,
uint16_t port ) uint16_t port )
@ -450,10 +473,7 @@ tr_rpcSetPort( tr_rpc_server * server,
server->port = port; server->port = port;
if( server->isEnabled ) if( server->isEnabled )
{ tr_runInEventThread( server->session, restartServer, server );
stopServer( server );
startServer( server );
}
} }
} }
@ -529,13 +549,10 @@ tr_rpcIsPasswordEnabled( const tr_rpc_server * server )
***** LIFE CYCLE ***** LIFE CYCLE
****/ ****/
void static void
tr_rpcClose( tr_rpc_server ** ps ) closeServer( void * vserver )
{ {
tr_rpc_server * s = *ps; tr_rpc_server * s = vserver;
*ps = NULL;
stopServer( s ); stopServer( s );
tr_free( s->acl ); tr_free( s->acl );
tr_free( s->username ); tr_free( s->username );
@ -543,6 +560,13 @@ tr_rpcClose( tr_rpc_server ** ps )
tr_free( s ); tr_free( s );
} }
void
tr_rpcClose( tr_rpc_server ** ps )
{
tr_runInEventThread( (*ps)->session, closeServer, *ps );
*ps = NULL;
}
tr_rpc_server * tr_rpc_server *
tr_rpcInit( tr_handle * session, tr_rpcInit( tr_handle * session,
int isEnabled, int isEnabled,
@ -562,9 +586,8 @@ tr_rpcInit( tr_handle * session,
s->password = tr_strdup( password ); s->password = tr_strdup( password );
s->isPasswordEnabled = isPasswordEnabled != 0; s->isPasswordEnabled = isPasswordEnabled != 0;
s->isEnabled = isEnabled != 0; s->isEnabled = isEnabled != 0;
if( isEnabled ) if( isEnabled )
startServer( s ); tr_runInEventThread( session, startServer, s );
return s; return s;
} }

View file

@ -145,7 +145,7 @@ logFunc( int severity,
static void static void
libeventThreadFunc( void * veh ) libeventThreadFunc( void * veh )
{ {
tr_event_handle * eh = (tr_event_handle *) veh; tr_event_handle * eh = veh;
tr_dbg( "Starting libevent thread" ); tr_dbg( "Starting libevent thread" );
@ -154,9 +154,7 @@ libeventThreadFunc( void * veh )
signal( SIGPIPE, SIG_IGN ); signal( SIGPIPE, SIG_IGN );
#endif #endif
eh->base = event_init( );
eh->h->events = eh; eh->h->events = eh;
event_set_log_callback( logFunc );
/* listen to the pipe's read fd */ /* listen to the pipe's read fd */
event_set( &eh->pipeEvent, eh->fds[0], EV_READ | EV_PERSIST, event_set( &eh->pipeEvent, eh->fds[0], EV_READ | EV_PERSIST,
@ -182,6 +180,7 @@ tr_eventInit( tr_handle * handle )
eh->lock = tr_lockNew( ); eh->lock = tr_lockNew( );
pipe( eh->fds ); pipe( eh->fds );
eh->h = handle; eh->h = handle;
eh->base = event_init( );
eh->thread = tr_threadNew( libeventThreadFunc, eh ); eh->thread = tr_threadNew( libeventThreadFunc, eh );
} }