mirror of
https://github.com/transmission/transmission
synced 2024-12-23 16:24:02 +00:00
push event_del() through the libevent pipe too.
This commit is contained in:
parent
9cb2dcb63d
commit
3a45686c3f
3 changed files with 46 additions and 21 deletions
|
@ -27,7 +27,8 @@ typedef void tr_data_free_func( void * user_data );
|
|||
|
||||
struct timer_node
|
||||
{
|
||||
struct event event;
|
||||
tr_handle_t * handle;
|
||||
struct event * event;
|
||||
tr_timer_func * func;
|
||||
void * user_data;
|
||||
tr_data_free_func * free_func;
|
||||
|
@ -47,7 +48,7 @@ unref( struct timer_node * node, int count )
|
|||
|
||||
if( node->free_func != NULL )
|
||||
(node->free_func)( node->user_data );
|
||||
event_del( &node->event );
|
||||
tr_event_del( node->handle, node->event );
|
||||
tr_free( node );
|
||||
}
|
||||
|
||||
|
@ -74,7 +75,7 @@ timerCB( int fd UNUSED, short event UNUSED, void * arg )
|
|||
if( !val )
|
||||
unref( node, 2 );
|
||||
else {
|
||||
timeout_add( &node->event, &node->tv );
|
||||
timeout_add( node->event, &node->tv );
|
||||
unref( node, 1 );
|
||||
}
|
||||
}
|
||||
|
@ -94,13 +95,15 @@ tr_timerNew( tr_handle_t * handle,
|
|||
assert( timeout_milliseconds >= 0 );
|
||||
|
||||
node = tr_new( struct timer_node, 1 );
|
||||
node->handle = handle;
|
||||
node->event = tr_new0( struct event, 1 );
|
||||
node->func = func;
|
||||
node->user_data = user_data;
|
||||
node->free_func = free_func;
|
||||
node->refcount = 1;
|
||||
node->tv.tv_sec = microseconds / 1000000;
|
||||
node->tv.tv_usec = microseconds % 1000000;
|
||||
timeout_set( &node->event, timerCB, node );
|
||||
tr_event_add( handle, &node->event, &node->tv );
|
||||
timeout_set( node->event, timerCB, node );
|
||||
tr_event_add( handle, node->event, &node->tv );
|
||||
return node;
|
||||
}
|
||||
|
|
|
@ -68,15 +68,11 @@ readFromPipe( int fd, short eventType UNUSED, void * unused UNUSED )
|
|||
struct evhttp_request * req;
|
||||
enum evhttp_cmd_type type;
|
||||
const char * uri;
|
||||
static char * buf = NULL;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf( stderr, "reading...reads: [%d] writes: [%d]\n", ++reads, writes );
|
||||
#endif
|
||||
|
||||
if( !buf )
|
||||
buf = tr_new0( char, sizeof(void*) );
|
||||
|
||||
ch = '\0';
|
||||
do {
|
||||
ret = read( fd, &ch, 1 );
|
||||
|
@ -88,9 +84,14 @@ readFromPipe( int fd, short eventType UNUSED, void * unused UNUSED )
|
|||
}
|
||||
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 */
|
||||
event = tr_new0( struct event, 1 );
|
||||
read( fd, event, sizeof(struct event) );
|
||||
read( fd, &event, sizeof(struct event*) );
|
||||
read( fd, &interval, sizeof(struct timeval) );
|
||||
tr_dbg( "read event from pipe: event.ev_arg is %p", event->ev_arg );
|
||||
event_add( event, &interval );
|
||||
|
@ -150,7 +151,7 @@ tr_eventClose( tr_handle_t * handle UNUSED )
|
|||
}
|
||||
|
||||
void
|
||||
tr_event_add (tr_handle_t * handle,
|
||||
tr_event_add( tr_handle_t * handle,
|
||||
struct event * event,
|
||||
struct timeval * interval )
|
||||
{
|
||||
|
@ -164,11 +165,29 @@ tr_event_add (tr_handle_t * handle,
|
|||
fprintf( stderr, "reads: [%d] writes: [%d]\n", reads, ++writes );
|
||||
#endif
|
||||
write( fd, &ch, 1 );
|
||||
write( fd, event, sizeof(struct event) );
|
||||
write( fd, &event, sizeof(struct event*) );
|
||||
write( fd, interval, sizeof(struct timeval) );
|
||||
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
|
||||
tr_evhttp_make_request (tr_handle_t * handle,
|
||||
struct evhttp_connection * evcon,
|
||||
|
|
|
@ -25,14 +25,17 @@ enum evhttp_cmd_type;
|
|||
struct evhttp_request;
|
||||
struct evhttp_connection;
|
||||
|
||||
extern void tr_event_add( struct tr_handle_s * tr_handle,
|
||||
struct event * event,
|
||||
struct timeval * interval );
|
||||
void tr_event_add( struct tr_handle_s * tr_handle,
|
||||
struct event * event,
|
||||
struct timeval * interval );
|
||||
|
||||
extern void tr_evhttp_make_request (struct tr_handle_s * tr_handle,
|
||||
struct evhttp_connection * evcon,
|
||||
struct evhttp_request * req,
|
||||
enum evhttp_cmd_type type,
|
||||
const char * uri);
|
||||
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_request * req,
|
||||
enum evhttp_cmd_type type,
|
||||
const char * uri);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue