@ -141,23 +141,24 @@ bool poller_add_item(struct poller *p, struct poller_item *i) {
bool poller_del_item_callback ( struct poller * p , int fd , void ( * callback ) ( void * ) , void * arg ) {
bool poller_del_item_callback ( struct poller * p , int fd , void ( * callback ) ( void * ) , void * arg ) {
struct poller_item_int * it ;
struct poller_item_int * it ;
bool ret = false ;
if ( ! p | | fd < 0 )
if ( ! p | | fd < 0 )
return false ;
goto out ;
{
{
LOCK ( & p - > lock ) ;
LOCK ( & p - > lock ) ;
if ( ! p - > items ) / / can happen during shutdown / free only
if ( ! p - > items ) / / can happen during shutdown / free only
return false ;
goto out ;
if ( fd > = p - > items - > len )
if ( fd > = p - > items - > len )
return false ;
goto out ;
if ( ! ( it = p - > items - > pdata [ fd ] ) )
if ( ! ( it = p - > items - > pdata [ fd ] ) )
return false ;
goto out ;
if ( epoll_ctl ( p - > fd , EPOLL_CTL_DEL , fd , NULL ) )
if ( epoll_ctl ( p - > fd , EPOLL_CTL_DEL , fd , NULL ) )
return false ;
goto out ;
p - > items - > pdata [ fd ] = NULL ; /* stealing the ref */
p - > items - > pdata [ fd ] = NULL ; /* stealing the ref */
@ -165,12 +166,15 @@ bool poller_del_item_callback(struct poller *p, int fd, void (*callback)(void *)
obj_put ( it ) ;
obj_put ( it ) ;
ret = true ;
out :
if ( callback )
if ( callback )
callback ( arg ) ;
callback ( arg ) ;
else
else
close ( fd ) ;
close ( fd ) ;
return t ru e;
return ret ;
}
}
bool poller_del_item ( struct poller * p , int fd ) {
bool poller_del_item ( struct poller * p , int fd ) {
return poller_del_item_callback ( p , fd , NULL , NULL ) ;
return poller_del_item_callback ( p , fd , NULL , NULL ) ;