/** * If the event is associated with any EventLoop (add()ed or feed_event()ed), it * will be stopped and reset. * * @return boolean */ PHP_METHOD(Event, stop) { event_object *obj = (event_object *)zend_object_store_get_object(getThis() TSRMLS_CC); EVENT_STOP(obj); EVENT_LOOP_REF_DEL(obj); }
/** * If the Event is pending, this function clears its pending status and * returns its revents bitset (as if its callback was invoked). If the watcher * isn't pending it returns 0. * * @return int revents bitset if pending, 0 if not (or not associated with EventLoop) */ PHP_METHOD(Event, clearPending) { int revents = 0; event_object *event = (event_object *)zend_object_store_get_object(getThis() TSRMLS_CC); if(event->loop_obj) { revents = event_clear_pending(event->loop_obj, event); /* Inactive event, meaning it is no longer part of the event loop and must be dtor:ed (most probably a fed event which has never become active because ev_TYPE_start has not been called) */ if( ! event_is_active(event)) { EVENT_LOOP_REF_DEL(event); } RETURN_LONG(revents); } RETURN_LONG(0); }
PHP_METHOD(PeriodicEvent, again) { /* TODO: Optional EventLoop parameter? */ event_object *event_obj = (event_object *)zend_object_store_get_object(getThis() TSRMLS_CC); if(event_has_loop(event_obj)) { event_periodic_again(event_obj); if( ! event_is_active(event_obj) && ! event_is_pending(event_obj)) { /* No longer referenced by libev, so remove GC protection */ IF_DEBUG(libev_printf("ev_periodic_again() stopped non-repeating timer\n")); EVENT_LOOP_REF_DEL(event_obj); } RETURN_BOOL(1); } /* TODO: Throw exception */ RETURN_BOOL(0); }
/** * Removes the event from the event loop, will skip all pending events on it too. * * @param Event * @return boolean False if the Event is not associated with this EventLoop, * can also be false if there is an error */ PHP_METHOD(EventLoop, remove) { zval *event_obj; event_object *event; event_loop_object *loop_obj = (event_loop_object *)zend_object_store_get_object(getThis() TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &event_obj, event_ce) != SUCCESS) { return; } event = (event_object *)zend_object_store_get_object(event_obj TSRMLS_CC); assert(loop_obj->loop); if(loop_obj->loop && event_is_active(event)) { assert(event->loop_obj); /* Check that the event is associated with us */ if( ! event_in_loop(loop_obj, event)) { IF_DEBUG(libev_printf("Event is not in this EventLoop\n")); RETURN_BOOL(0); } EVENT_STOP(event); /* Remove GC protection, no longer active or pending */ EVENT_LOOP_REF_DEL(event); RETURN_BOOL(1); } RETURN_BOOL(0); }