Source

pecl-ev / io.c

Diff from to
 #include "watcher.h"
 
 /* {{{ php_ev_io_object_ctor */
-void php_ev_io_object_ctor(INTERNAL_FUNCTION_PARAMETERS, zval *loop)
+void php_ev_io_object_ctor(INTERNAL_FUNCTION_PARAMETERS, zval *loop, zend_bool ctor, zend_bool start)
 {
-	zval                  *self       = NULL;
+	zval                  *self;
 	zval                  *z_fd;
 	php_ev_object         *o_self;
 	php_ev_object         *o_loop;
-	ev_io                 *io_watcher;
+	ev_io                 *w;
 	php_socket_t           fd;
 
-	zval                  *data       = NULL;
-	zend_fcall_info        fci        = empty_fcall_info;
-	zend_fcall_info_cache  fcc        = empty_fcall_info_cache;
-	long                   priority   = 0;
+	zval                  *data     = NULL;
+	zend_fcall_info        fci      = empty_fcall_info;
+	zend_fcall_info_cache  fcc      = empty_fcall_info_cache;
+	long                   priority = 0;
 	long                   events;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlf|z!l",
 		return;
 	}
 
-	/* If loop is NULL, then we're in __construct() */
-	if (loop) {
+	if (ctor) {
+		self = getThis();
+	} else {
 		PHP_EV_INIT_CLASS_OBJECT(return_value, ev_io_class_entry_ptr);
-
-		PHP_EV_ASSERT((self == NULL));
 		self = return_value; 
-	} else {
+	}
+
+	if (!loop) {
 		loop = php_ev_default_loop(TSRMLS_C);
-		self = getThis();
 	}
 
-	o_self     = (php_ev_object *) zend_object_store_get_object(self TSRMLS_CC);
-	o_loop     = (php_ev_object *) zend_object_store_get_object(loop TSRMLS_CC);
-	io_watcher = (ev_io *) php_ev_new_watcher(sizeof(ev_io), self,
+	o_self = (php_ev_object *) zend_object_store_get_object(self TSRMLS_CC);
+	o_loop = (php_ev_object *) zend_object_store_get_object(loop TSRMLS_CC);
+	w      = (ev_io *) php_ev_new_watcher(sizeof(ev_io), self,
 			PHP_EV_LOOP_OBJECT_FETCH_FROM_OBJECT(o_loop),
 			&fci, &fcc, data, priority TSRMLS_CC);
 
-	io_watcher->type = EV_IO;
+	w->type = EV_IO;
 	
-	ev_io_set(io_watcher, fd, events);
+	ev_io_set(w, fd, events);
 
-	o_self->ptr = (void *) io_watcher;
+	o_self->ptr = (void *) w;
+
+	if (start) {
+		PHP_EV_WATCHER_START(ev_io, w);
+	}
 }
 /* }}} */
 
 /* {{{ proto EvIo::__construct(mixed fd, int events, callable callback[, mixed data = NULL[, int priority = 0]]) */
 PHP_METHOD(EvIo, __construct)
 {
-	php_ev_io_object_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL);
+	PHP_EV_WATCHER_CTOR(io, NULL);
+}
+/* }}} */
+
+/* {{{ proto EvIo::createStopped(mixed fd, int events, callable callback[, mixed data = NULL[, int priority = 0]]) */
+PHP_METHOD(EvIo, createStopped)
+{
+	PHP_EV_WATCHER_FACTORY_NS(io, NULL);
 }
 /* }}} */
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.