(libT) make sure to init the rpc server with the correct event base.

This commit is contained in:
Charles Kerr 2008-09-29 04:26:52 +00:00
parent 713b99d64b
commit 86b6e00321
3 changed files with 16 additions and 6 deletions

View File

@ -28,6 +28,7 @@
#include "platform.h"
#include "rpcimpl.h"
#include "rpc-server.h"
#include "trevent.h"
#include "utils.h"
#include "web.h"
@ -327,7 +328,7 @@ handle_request( struct evhttp_request * req,
void * arg )
{
struct tr_rpc_server * server = arg;
tr_ndbg( MY_NAME, _( "Got request: \"%s\"" ), req->uri );
fprintf( stderr, "%s:%d Got request: \"%s\"\n", __FILE__, __LINE__, req->uri );
if( req && req->evcon )
{
@ -393,19 +394,21 @@ handle_request( struct evhttp_request * req,
tr_free( user );
}
fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ );
}
static void
startServer( tr_rpc_server * server )
{
dbgmsg( "in startServer; current context is %p", server->httpd );
fprintf( stderr, "%s:%d in startServer; current context is %p\n", __FILE__, __LINE__, server->httpd );
if( !server->httpd )
{
if( ( server->httpd = evhttp_start( "0.0.0.0", server->port ) ) )
evhttp_set_gencb( server->httpd, handle_request, server );
else
tr_nerr( MY_NAME, _( "Failed to start RPC server" ) );
int i;
server->httpd = evhttp_new( tr_eventGetBase( server->session ) );
fprintf( stderr, "%s:%d in startServer; new context is %p\n", __FILE__, __LINE__, server->httpd );
i = evhttp_bind_socket( server->httpd, "0.0.0.0", server->port );
fprintf( stderr, "evhttp_bind_socket returned %d\n", i );
}
}

View File

@ -302,3 +302,8 @@ tr_runInEventThread( struct tr_handle * handle,
}
}
struct event_base *
tr_eventGetBase( tr_session * session )
{
return session->events->base;
}

View File

@ -22,6 +22,8 @@ void tr_eventInit( struct tr_handle * tr_handle );
void tr_eventClose( struct tr_handle * tr_handle );
struct event_base * tr_eventGetBase( struct tr_handle * tr_handle );
typedef struct tr_timer tr_timer;