/** * Normal constructor for EventLoop instance. */ PHP_METHOD(EventLoop, __construct) { int backend = EVFLAG_AUTO; event_loop_object *obj = (event_loop_object *)zend_object_store_get_object(getThis() TSRMLS_CC); assert( ! obj->loop); if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &backend) != SUCCESS) { return; } /* Check parameter */ if(EVFLAG_AUTO != backend && EVBACKEND_SELECT != backend && EVBACKEND_POLL != backend && EVBACKEND_EPOLL != backend && EVBACKEND_KQUEUE != backend && EVBACKEND_DEVPOLL != backend && EVBACKEND_PORT != backend && EVBACKEND_ALL != backend) { /* TODO: libev-specific exception class here */ zend_throw_exception(NULL, "libev\\EventLoop: backend parameter must be " "one of the EventLoop::BACKEND_* constants.", 1 TSRMLS_DC); return; } obj->loop = ev_loop_new(backend); IF_DEBUG(ev_verify(obj->loop)); }
/** * Returns the default event loop object, this object is a global singleton * and it is not recommended to use it unless you require ChildEvent watchers * as they can only be attached to the default loop. * * @return EventLoop */ PHP_METHOD(EventLoop, getDefaultLoop) { /* Singleton */ if( ! default_event_loop_object) { ALLOC_INIT_ZVAL(default_event_loop_object); /* Create object without calling constructor, we now have an EventLoop missing the ev_loop */ if(object_init_ex(default_event_loop_object, event_loop_ce) != SUCCESS) { /* TODO: Error handling */ RETURN_BOOL(0); return; } event_loop_object *obj = (event_loop_object *)zend_object_store_get_object(default_event_loop_object TSRMLS_CC); assert( ! obj->loop); /* TODO: allow other EVFLAGs */ obj->loop = ev_default_loop(EVFLAG_AUTO); IF_DEBUG(ev_verify(obj->loop)); IF_DEBUG(libev_printf("Created default_event_loop_object\n")); } /* Return copy, no destruct on our local zval */ RETURN_ZVAL(default_event_loop_object, 1, 0); }
static PyObject * Loop_verify(Loop *self) { ev_verify(self->loop); Py_RETURN_NONE; }