Commits

Ruslan Osmanov committed f318b97

Add: EvFork
Change: renamed test files

Comments (0)

Files changed (13)

 #if EV_EMBED_ENABLE
 zend_class_entry *ev_embed_class_entry_ptr;
 #endif
+#if EV_FORK_ENABLE
+zend_class_entry *ev_fork_class_entry_ptr;
+#endif
 
 static HashTable classes;
 static HashTable php_ev_properties;
 /* }}} */
 #endif
 
+#if EV_FORK_ENABLE
+/* {{{ php_ev_fork_free_storage() */
+static void php_ev_fork_free_storage(void *object TSRMLS_DC)
+{
+	php_ev_object *obj_ptr = (php_ev_object *) object;
+
+	PHP_EV_ASSERT(obj_ptr->ptr);
+	ev_fork *ptr = (ev_fork *) obj_ptr->ptr;
+
+	/* Free base class members */
+	php_ev_watcher_free_storage((ev_watcher *) ptr TSRMLS_CC);
+
+	/* Free common Ev object members and the object itself */
+	php_ev_object_free_storage(object TSRMLS_CC);
+}
+/* }}} */
+#endif
+
 /* {{{ php_ev_register_object 
  * Is called AFTER php_ev_object_new() */
 zend_object_value php_ev_register_object(zend_class_entry *ce, php_ev_object *intern TSRMLS_DC)
 		/* EvEmbed */
 	 	func_free_storage = php_ev_embed_free_storage;
 #endif
+#if EV_FORK_ENABLE
+	} else if (instanceof_function(ce, ev_fork_class_entry_ptr TSRMLS_CC)) {
+		/* EvCheck */
+	 	func_free_storage = php_ev_fork_free_storage;
+#endif
 	} else {
 	 	func_free_storage = php_ev_object_free_storage;
 	}
 	zend_hash_add(&classes, ce->name, ce->name_length + 1, &php_ev_embed_properties, sizeof(php_ev_embed_properties), NULL);
 	/* }}} */
 #endif
+
+#if EV_CHECK_ENABLE
+	/* {{{ EvFork */
+	PHP_EV_REGISTER_CLASS_ENTRY_EX("EvFork", ev_fork_class_entry_ptr, ev_fork_class_entry_functions, ev_watcher_class_entry_ptr);
+	ce = ev_fork_class_entry_ptr;
+	zend_hash_add(&classes, ce->name, ce->name_length + 1, &php_ev_watcher_properties, sizeof(php_ev_watcher_properties), NULL);
+	/* }}} */
+#endif
 }
 /* }}} */
 
 #if EV_EMBED_ENABLE
 # include "embed.c";
 #endif
+#if EV_FORK_ENABLE
+# include "fork.c";
+#endif
 
 #endif /* HAVE_EV */
 
 /* }}} */
 #endif
 
+#if EV_FORK_ENABLE
+/* {{{ EvFork */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_fork, 0, 0, 2)
+	ZEND_ARG_INFO(0, loop)
+	ZEND_ARG_INFO(0, callback)
+	ZEND_ARG_INFO(0, data)
+	ZEND_ARG_INFO(0, priority)
+ZEND_END_ARG_INFO();
+/* }}} */
+#endif
+
 /* ARGINFO }}} */
 
 
 };
 /* }}} */
 #endif
+
+#if EV_FORK_ENABLE
+/* {{{ ev_fork_class_entry_functions */
+const zend_function_entry ev_fork_class_entry_functions[] = {
+	PHP_ME(EvFork, __construct, arginfo_ev_fork, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
+	{ NULL, NULL, NULL }
+};
+/* }}} */
+#endif
 /*
  * Local variables:
  * tab-width: 4
 /* }}} */
 #endif
 
+#if EV_FORK_ENABLE
+/* {{{ EvFork*/
+PHP_METHOD(EvFork, __construct);
+/* }}} */
+#endif
+
 #endif /* PHP_EV_FE_H */
 
 /* 
+/*
+   +----------------------------------------------------------------------+
+   | PHP Version 5                                                        |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997-2012 The PHP Group                                |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 3.01 of the PHP license,      |
+   | that is bundled with this package in the file LICENSE, and is        |
+   | available through the world-wide-web at the following url:           |
+   | http://www.php.net/license/3_01.txt                                  |
+   | If you did not receive a copy of the PHP license and are unable to   |
+   | obtain it through the world-wide-web, please send a note to          |
+   | license@php.net so we can mail you a copy immediately.               |
+   +----------------------------------------------------------------------+
+   | Author: Ruslan Osmanov <osmanov@php.net>                             |
+   +----------------------------------------------------------------------+
+*/
+#include "watcher.h"
+
+/* {{{ proto EvFork::__construct(EvLoop loop, callable callback[, mixed data = NULL[, int priority = 0]]) */
+PHP_METHOD(EvFork, __construct)
+{
+	zval          *self;
+	php_ev_object *o_self;
+	php_ev_object *o_loop;
+	ev_fork      *fork_watcher;
+
+	zval                  *loop;
+	zval                  *data       = NULL;
+	zend_fcall_info        fci        = empty_fcall_info;
+	zend_fcall_info_cache  fcc        = empty_fcall_info_cache;
+	long                   priority   = 0;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Of|z!l",
+				&loop, ev_loop_class_entry_ptr, &fci, &fcc,
+				&data, &priority) == FAILURE) {
+		return;
+	}
+
+	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);
+	fork_watcher = (ev_fork *) php_ev_new_watcher(sizeof(ev_fork), self,
+			PHP_EV_LOOP_OBJECT_FETCH_FROM_OBJECT(o_loop),
+			&fci, &fcc, data, priority TSRMLS_CC);
+
+	fork_watcher->type = EV_CHECK;
+
+	o_self->ptr = (void *) fork_watcher;
+}
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 sts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4 sts=4
+ */
 extern const zend_function_entry ev_check_class_entry_functions[];
 extern const zend_function_entry ev_prepare_class_entry_functions[];
 extern const zend_function_entry ev_embed_class_entry_functions[];
+extern const zend_function_entry ev_fork_class_entry_functions[];
 
 extern const php_ev_property_entry ev_test_property_entries[];
 extern const php_ev_property_entry ev_loop_property_entries[];

tests/01_load.phpt

+--TEST--
+Check for ev presence
+--SKIPIF--
+<?php if (!extension_loaded("ev")) print "skip"; ?>
+--FILE--
+<?php 
+echo "ev extension is available";
+?>
+--EXPECT--
+ev extension is available

tests/02_ev_construct_variation.phpt

+--TEST--
+Check for constructor and factory methods' behaviour
+--FILE--
+<?php
+function cb() {
+	return FALSE;
+}
+
+$prev_data = "prev_data";
+$third_data = "new_data";
+
+// Passing data var to constructor
+$loop = new EvLoop(0, "cb", $prev_data);
+var_dump($loop->data);
+
+// data property read/write
+$loop->data = "new data";
+var_dump($loop->data);
+
+// rewrite data property with string literal
+$loop->data = "new new data";
+var_dump($loop->data);
+
+// rewrite data property with a variable
+$loop->data = $third_data;
+var_dump($loop->data);
+
+// Multiple attempts to create the default loop
+$loop2 = EvLoop::default_loop();
+$loop2 = EvLoop::default_loop();
+$loop2 = EvLoop::default_loop();
+
+// Overwriting previously created loop with the default loop
+$loop = EvLoop::default_loop();
+
+// Overwriting previously created default loop with new loop
+$loop = new EvLoop(EVFLAG_AUTO);
+// Should be NULL
+var_dump($loop->data);
+?>
+--CLEAN--
+--EXPECTF--
+string(9) "prev_data"
+string(8) "new data"
+string(12) "new new data"
+string(8) "new_data"
+
+Warning: EvLoop::default_loop(): Returning previously created default loop in %s on line %d
+
+Warning: EvLoop::default_loop(): Returning previously created default loop in %s on line %d
+
+Warning: EvLoop::default_loop(): Returning previously created default loop in %s on line %d
+NULL

tests/03_ev_loop_props.phpt

+--TEST--
+Check for EvLoop class properties
+--FILE--
+<?php 
+function cb($watcher, $revents) {
+	echo __FUNCTION__, "() called", PHP_EOL;
+	$watcher->stop();
+	return FALSE;
+}
+//$fd = fopen('listen_to_me', 'r');
+
+$loop       = EvLoop::default_loop();
+$loop->data = "ld";
+$io_watcher = new EvIo(STDIN, EV_READ, $loop, "cb", "data", 2);
+var_dump($io_watcher->get_loop());
+var_dump($io_watcher->priority);
+var_dump($io_watcher->data);
+
+//$io_watcher->start();
+//$loop->run();
+//echo "closing fd\n";
+//fclose($fd);
+
+?>
+--EXPECT--

tests/04_ev_watcher_construct_variation.phpt

+--TEST--
+Check for constructors of the classes derived from EvWatcher
+--FILE--
+<?php
+function cb() {
+	return FALSE;
+}
+
+$loop = new EvLoop();
+$io_watcher = new EvIo(STDIN, EV_READ, $loop, "cb");
+var_dump($io_watcher);
+
+
+?>
+--EXPECTF--

tests/ev001.phpt

---TEST--
-Check for ev presence
---SKIPIF--
-<?php if (!extension_loaded("ev")) print "skip"; ?>
---FILE--
-<?php 
-echo "ev extension is available";
-?>
---EXPECT--
-ev extension is available

tests/ev_construct_variation.phpt

---TEST--
-Check for constructor and factory methods' behaviour
---FILE--
-<?php
-function cb() {
-	return FALSE;
-}
-
-$prev_data = "prev_data";
-$third_data = "new_data";
-
-// Passing data var to constructor
-$loop = new EvLoop(0, "cb", $prev_data);
-var_dump($loop->data);
-
-// data property read/write
-$loop->data = "new data";
-var_dump($loop->data);
-
-// rewrite data property with string literal
-$loop->data = "new new data";
-var_dump($loop->data);
-
-// rewrite data property with a variable
-$loop->data = $third_data;
-var_dump($loop->data);
-
-// Multiple attempts to create the default loop
-$loop2 = EvLoop::default_loop();
-$loop2 = EvLoop::default_loop();
-$loop2 = EvLoop::default_loop();
-
-// Overwriting previously created loop with the default loop
-$loop = EvLoop::default_loop();
-
-// Overwriting previously created default loop with new loop
-$loop = new EvLoop(EVFLAG_AUTO);
-// Should be NULL
-var_dump($loop->data);
-?>
---CLEAN--
---EXPECTF--
-string(9) "prev_data"
-string(8) "new data"
-string(12) "new new data"
-string(8) "new_data"
-
-Warning: EvLoop::default_loop(): Returning previously created default loop in %s on line %d
-
-Warning: EvLoop::default_loop(): Returning previously created default loop in %s on line %d
-
-Warning: EvLoop::default_loop(): Returning previously created default loop in %s on line %d
-NULL

tests/ev_loop_props.phpt

---TEST--
-Check for EvLoop class properties
---FILE--
-<?php 
-function cb($watcher, $revents) {
-	echo __FUNCTION__, "() called", PHP_EOL;
-	$watcher->stop();
-	return FALSE;
-}
-//$fd = fopen('listen_to_me', 'r');
-
-$loop       = EvLoop::default_loop();
-$loop->data = "ld";
-$io_watcher = new EvIo(STDIN, EV_READ, $loop, "cb", "data", 2);
-var_dump($io_watcher->get_loop());
-var_dump($io_watcher->priority);
-var_dump($io_watcher->data);
-
-//$io_watcher->start();
-//$loop->run();
-//echo "closing fd\n";
-//fclose($fd);
-
-?>
---EXPECT--

tests/ev_watcher_construct_variation.phpt

---TEST--
-Check for constructors of the classes derived from EvWatcher
---FILE--
-<?php
-function cb() {
-	return FALSE;
-}
-
-$loop = new EvLoop();
-$io_watcher = new EvIo(STDIN, EV_READ, $loop, "cb");
-var_dump($io_watcher);
-
-
-?>
---EXPECTF--