1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 08:43:27 +00:00

push event_del() through the libevent pipe too.

This commit is contained in:
Charles Kerr 2007-08-18 06:59:20 +00:00
parent 9cb2dcb63d
commit 3a45686c3f
3 changed files with 46 additions and 21 deletions

View file

@ -27,7 +27,8 @@ typedef void tr_data_free_func( void * user_data );
struct timer_node struct timer_node
{ {
struct event event; tr_handle_t * handle;
struct event * event;
tr_timer_func * func; tr_timer_func * func;
void * user_data; void * user_data;
tr_data_free_func * free_func; tr_data_free_func * free_func;
@ -47,7 +48,7 @@ unref( struct timer_node * node, int count )
if( node->free_func != NULL ) if( node->free_func != NULL )
(node->free_func)( node->user_data ); (node->free_func)( node->user_data );
event_del( &node->event ); tr_event_del( node->handle, node->event );
tr_free( node ); tr_free( node );
} }
@ -74,7 +75,7 @@ timerCB( int fd UNUSED, short event UNUSED, void * arg )
if( !val ) if( !val )
unref( node, 2 ); unref( node, 2 );
else { else {
timeout_add( &node->event, &node->tv ); timeout_add( node->event, &node->tv );
unref( node, 1 ); unref( node, 1 );
} }
} }
@ -94,13 +95,15 @@ tr_timerNew( tr_handle_t * handle,
assert( timeout_milliseconds >= 0 ); assert( timeout_milliseconds >= 0 );
node = tr_new( struct timer_node, 1 ); node = tr_new( struct timer_node, 1 );
node->handle = handle;
node->event = tr_new0( struct event, 1 );
node->func = func; node->func = func;
node->user_data = user_data; node->user_data = user_data;
node->free_func = free_func; node->free_func = free_func;
node->refcount = 1; node->refcount = 1;
node->tv.tv_sec = microseconds / 1000000; node->tv.tv_sec = microseconds / 1000000;
node->tv.tv_usec = microseconds % 1000000; node->tv.tv_usec = microseconds % 1000000;
timeout_set( &node->event, timerCB, node ); timeout_set( node->event, timerCB, node );
tr_event_add( handle, &node->event, &node->tv ); tr_event_add( handle, node->event, &node->tv );
return node; return node;
} }

View file

@ -68,15 +68,11 @@ readFromPipe( int fd, short eventType UNUSED, void * unused UNUSED )
struct evhttp_request * req; struct evhttp_request * req;
enum evhttp_cmd_type type; enum evhttp_cmd_type type;
const char * uri; const char * uri;
static char * buf = NULL;
#ifdef DEBUG #ifdef DEBUG
fprintf( stderr, "reading...reads: [%d] writes: [%d]\n", ++reads, writes ); fprintf( stderr, "reading...reads: [%d] writes: [%d]\n", ++reads, writes );
#endif #endif
if( !buf )
buf = tr_new0( char, sizeof(void*) );
ch = '\0'; ch = '\0';
do { do {
ret = read( fd, &ch, 1 ); ret = read( fd, &ch, 1 );
@ -88,9 +84,14 @@ readFromPipe( int fd, short eventType UNUSED, void * unused UNUSED )
} }
else switch( ch ) else switch( ch )
{ {
case 'd': /* event_del */
read( fd, &event, sizeof(struct event*) );
tr_dbg( "read del event from pipe: event is %p", event );
event_del( event );
break;
case 'e': /* event_add */ case 'e': /* event_add */
event = tr_new0( struct event, 1 ); read( fd, &event, sizeof(struct event*) );
read( fd, event, sizeof(struct event) );
read( fd, &interval, sizeof(struct timeval) ); read( fd, &interval, sizeof(struct timeval) );
tr_dbg( "read event from pipe: event.ev_arg is %p", event->ev_arg ); tr_dbg( "read event from pipe: event.ev_arg is %p", event->ev_arg );
event_add( event, &interval ); event_add( event, &interval );
@ -164,11 +165,29 @@ tr_event_add (tr_handle_t * handle,
fprintf( stderr, "reads: [%d] writes: [%d]\n", reads, ++writes ); fprintf( stderr, "reads: [%d] writes: [%d]\n", reads, ++writes );
#endif #endif
write( fd, &ch, 1 ); write( fd, &ch, 1 );
write( fd, event, sizeof(struct event) ); write( fd, &event, sizeof(struct event*) );
write( fd, interval, sizeof(struct timeval) ); write( fd, interval, sizeof(struct timeval) );
tr_lockUnlock( lock ); tr_lockUnlock( lock );
} }
void
tr_event_del( tr_handle_t * handle,
struct event * event )
{
const char ch = 'd';
int fd = handle->events->fds[1];
tr_lock_t * lock = handle->events->lock;
tr_lockLock( lock );
tr_dbg( "writing event to pipe: del event %p", event );
#ifdef DEBUG
fprintf( stderr, "reads: [%d] writes: [%d]\n", reads, ++writes );
#endif
write( fd, &ch, 1 );
write( fd, &event, sizeof(struct event*) );
tr_lockUnlock( lock );
}
void void
tr_evhttp_make_request (tr_handle_t * handle, tr_evhttp_make_request (tr_handle_t * handle,
struct evhttp_connection * evcon, struct evhttp_connection * evcon,

View file

@ -25,11 +25,14 @@ enum evhttp_cmd_type;
struct evhttp_request; struct evhttp_request;
struct evhttp_connection; struct evhttp_connection;
extern void tr_event_add( struct tr_handle_s * tr_handle, void tr_event_add( struct tr_handle_s * tr_handle,
struct event * event, struct event * event,
struct timeval * interval ); struct timeval * interval );
extern void tr_evhttp_make_request (struct tr_handle_s * tr_handle, void tr_event_del( struct tr_handle_s * tr_handle,
struct event * event );
void tr_evhttp_make_request (struct tr_handle_s * tr_handle,
struct evhttp_connection * evcon, struct evhttp_connection * evcon,
struct evhttp_request * req, struct evhttp_request * req,
enum evhttp_cmd_type type, enum evhttp_cmd_type type,