Commits

Ruslan Osmanov committed 3ca05da

Fix: build error with libevent_extra disabled
Add: EventListener fd readonly property for numeric file descriptor of the socket associated with the listener

  • Participants
  • Parent commits 37ad7dc

Comments (0)

Files changed (6)

File classes/http.h

 
 #ifndef PHP_EVENT_HTTP_H
 #define PHP_EVENT_HTTP_H
+#ifdef HAVE_EVENT_EXTRA_LIB
 
 void _php_event_free_http_cb(php_event_http_cb_t *cb);
 
+#endif /* HAVE_EVENT_EXTRA_LIB */
 #endif /* PHP_EVENT_HTTP_H */
 /*
  * Local variables:
     <email>osmanov@php.net</email>
     <active>yes</active>
   </lead>
-  <date>2013-03-30</date>
+  <date>2013-04-01</date>
   <!--{{{ Current version -->
   <version>
     <release>1.6.0</release>
   Refact: automatically set the upper bound of EventBuffer::search to the buffer length, if it is greater then the length
   Fix: make the code compatible with PHP 5.6.0-dev
   Fix: build error with zts PHP setup
+  Fix: build error with libevent_extra disabled
+  Add: EventListener fd readonly property for numeric file descriptor of the socket associated with the listener
   ]]></notes>
   <!--}}}-->
   <!--{{{ Contents -->
   Refact: automatically set the upper bound of EventBuffer::search to the buffer length, if it is greater then the length
   Fix: make the code compatible with PHP 5.6.0-dev
   Fix: build error with zts PHP setup
+  Fix: build error with libevent_extra disabled
+  Add: EventListener fd readonly property for numeric file descriptor of the socket associated with the listener
   ]]></notes>
     </release>
     <!--}}}-->
 static HashTable event_properties;
 static HashTable event_bevent_properties;
 static HashTable event_buffer_properties;
+static HashTable event_listener_properties;
 #ifdef HAVE_EVENT_OPENSSL_LIB
 static HashTable event_ssl_context_properties;
 int php_event_ssl_data_index;
 	PHP_EVENT_REGISTER_CLASS("Event", event_object_create, php_event_ce, php_event_ce_functions);
 	ce = php_event_ce;
 	ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
-	zend_hash_init(&event_properties, 0, NULL, NULL, 1);
+	zend_hash_init(&event_properties, 2, NULL, NULL, 1);
 	PHP_EVENT_ADD_CLASS_PROPERTIES(&event_properties, event_property_entries);
 	PHP_EVENT_DECL_CLASS_PROPERTIES(ce, event_property_entry_info);
 	zend_hash_add(&classes, ce->name, ce->name_length + 1, &event_properties,
 			php_event_bevent_ce_functions);
 	ce = php_event_bevent_ce;
 	ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
-	zend_hash_init(&event_bevent_properties, 0, NULL, NULL, 1);
+	zend_hash_init(&event_bevent_properties, 4, NULL, NULL, 1);
 	PHP_EVENT_ADD_CLASS_PROPERTIES(&event_bevent_properties, event_bevent_property_entries);
 	PHP_EVENT_DECL_CLASS_PROPERTIES(ce, event_bevent_property_entry_info);
 	zend_hash_add(&classes, ce->name, ce->name_length + 1, &event_bevent_properties,
 			php_event_listener_ce_functions);
 	ce = php_event_listener_ce;
 	ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
+	zend_hash_init(&event_listener_properties, 1, NULL, NULL, 1);
+	PHP_EVENT_ADD_CLASS_PROPERTIES(&event_listener_properties, event_listener_property_entries);
+	PHP_EVENT_DECL_CLASS_PROPERTIES(ce, event_listener_property_entry_info);
+	zend_hash_add(&classes, ce->name, ce->name_length + 1, &event_listener_properties,
+			sizeof(event_listener_properties), NULL);
 
 	PHP_EVENT_REGISTER_CLASS("EventHttpConnection", event_http_conn_object_create,
 			php_event_http_conn_ce,
 	zend_hash_destroy(&event_properties);
 	zend_hash_destroy(&event_bevent_properties);
 	zend_hash_destroy(&event_buffer_properties);
+	zend_hash_destroy(&event_listener_properties);
 #ifdef HAVE_EVENT_OPENSSL_LIB
 	zend_hash_destroy(&event_ssl_context_properties);
 #endif
 		MAKE_STD_ZVAL(*ppz);
 	}
 
-    /* Make a copy of the zval, avoid direct binding to the address
-     * of value, since it breaks refcount in read_property()
-     * causing further leaks and memory access violations */
+	/* Make a copy of the zval, avoid direct binding to the address
+	 * of value, since it breaks refcount in read_property()
+	 * causing further leaks and memory access violations */
 	REPLACE_ZVAL_VALUE(ppz, value, 1);
 }
 
 		return;
 	}
 
-    MAKE_STD_ZVAL(*retval);
-    /*REPLACE_ZVAL_VALUE(retval, pz, 1);*/
-    ZVAL_ZVAL(*retval, pz, 1, 0);
+	MAKE_STD_ZVAL(*retval);
+	/*REPLACE_ZVAL_VALUE(retval, pz, 1);*/
+	ZVAL_ZVAL(*retval, pz, 1, 0);
 }
 
 
 /* {{{ get_ssl_option */
 static zval **get_ssl_option(const HashTable *ht, ulong idx)
 {
-    zval **val;
+	zval **val;
 
 	if (zend_hash_index_find(ht, idx, (void **) &val) == SUCCESS) {
 		return val;
-    }
+	}
 
-    return NULL;
+	return NULL;
 }
 /* }}} */
 
 }
 /* }}} */
 
+#ifdef HAVE_EVENT_EXTRA_LIB
+/* {{{ event_listener_fd_prop_read */
+static int event_listener_fd_prop_read(php_event_abstract_object_t *obj, zval **retval TSRMLS_DC)
+{
+	php_event_listener_t *l = (php_event_listener_t *) obj;
+	evutil_socket_t fd;
+
+	MAKE_STD_ZVAL(*retval);
+
+	if (!l->listener) {
+		/* Uninitialized listener */
+		ZVAL_NULL(*retval);
+		return SUCCESS;
+	}
+
+	fd = evconnlistener_get_fd(l->listener);
+	if (fd == -1) {
+		ZVAL_NULL(*retval);
+	} else {
+		ZVAL_LONG(*retval, fd);
+	}
+
+	return SUCCESS;
+}
+/* }}} */
+#endif
+
 /* {{{ event_bevent_priority_prop_write*/
 static int event_bevent_priority_prop_write(php_event_abstract_object_t *obj, zval *value TSRMLS_DC)
 {
 const php_event_property_entry_t event_property_entries[] = {
 	{"pending", sizeof("pending") - 1, event_pending_prop_read, NULL,                  NULL},
 	{"data",    sizeof("data")    - 1, event_data_prop_read,    event_data_prop_write, event_data_prop_get_ptr_ptr},
-    {NULL, 0, NULL, NULL, NULL}
+	{NULL, 0, NULL, NULL, NULL}
 };
 const php_event_property_entry_t event_bevent_property_entries[] = {
 	{"priority", sizeof("priority") - 1, event_bevent_priority_prop_read, event_bevent_priority_prop_write, NULL                               },
 		event_bevent_allow_ssl_dirty_shutdown_prop_read,
 		event_bevent_allow_ssl_dirty_shutdown_prop_write, NULL },
 #endif
-    {NULL, 0, NULL, NULL, NULL}
+	{NULL, 0, NULL, NULL, NULL}
 };
 const php_event_property_entry_t event_buffer_property_entries[] = {
 	{"length",           sizeof("length")           - 1, event_buffer_length_prop_read,           NULL, NULL},
 	{"contiguous_space", sizeof("contiguous_space") - 1, event_buffer_contiguous_space_prop_read, NULL, NULL},
-    {NULL, 0, NULL, NULL, NULL}
+	{NULL, 0, NULL, NULL, NULL}
+};
+#ifdef HAVE_EVENT_EXTRA_LIB
+const php_event_property_entry_t event_listener_property_entries[] = {
+	{"fd", sizeof("fd") - 1, event_listener_fd_prop_read, NULL, NULL},
+	{NULL, 0, NULL, NULL, NULL}
 };
+#endif
 #ifdef HAVE_EVENT_OPENSSL_LIB
 const php_event_property_entry_t event_ssl_context_property_entries[] = {
 	{"local_cert", sizeof("local_cert") - 1, event_ssl_context_local_cert_prop_read, event_ssl_context_local_cert_prop_write, NULL},
 	{"local_pk", sizeof("local_pk") - 1, event_ssl_context_local_pk_prop_read, event_ssl_context_local_pk_prop_write, NULL},
-    {NULL, 0, NULL, NULL, NULL}
+	{NULL, 0, NULL, NULL, NULL}
 };
 #endif
 
 	{ZEND_ACC_PUBLIC, "contiguous_space", sizeof("contiguous_space") - 1, -1, 0, NULL, 0, NULL},
 	{0, NULL, 0, -1, 0, NULL, 0, NULL}
 };
+#ifdef HAVE_EVENT_EXTRA_LIB
+const zend_property_info event_listener_property_entry_info[] = {
+	{ZEND_ACC_PUBLIC, "fd", sizeof("fd") - 1, -1, 0, NULL, 0, NULL},
+	{0, NULL, 0, -1, 0, NULL, 0, NULL}
+};
+#endif
 #ifdef HAVE_EVENT_OPENSSL_LIB
 const zend_property_info event_ssl_context_property_entry_info[] = {
 	{ZEND_ACC_PUBLIC, "local_cert", sizeof("local_cert") - 1, -1, 0, NULL, 0, NULL},
 extern const php_event_property_entry_t event_property_entries[];
 extern const php_event_property_entry_t event_bevent_property_entries[];
 extern const php_event_property_entry_t event_buffer_property_entries[];
+#ifdef HAVE_EVENT_EXTRA_LIB
+extern const php_event_property_entry_t event_listener_property_entries[];
+#endif
 #ifdef HAVE_EVENT_OPENSSL_LIB
 extern const php_event_property_entry_t event_ssl_context_property_entries[];
 #endif
 extern const zend_property_info event_property_entry_info[];
 extern const zend_property_info event_bevent_property_entry_info[];
 extern const zend_property_info event_buffer_property_entry_info[];
+#if HAVE_EVENT_EXTRA_LIB
+extern const zend_property_info event_listener_property_entry_info[];
+#endif
 #ifdef HAVE_EVENT_OPENSSL_LIB
 extern const zend_property_info event_ssl_context_property_entry_info[];
 #endif
 
-#if HAVE_EVENT_EXTRA_LIB
+#ifdef HAVE_EVENT_EXTRA_LIB
 extern const zend_function_entry php_event_dns_base_ce_functions[];
 extern const zend_function_entry php_event_http_conn_ce_functions[];
 extern const zend_function_entry php_event_http_ce_functions[];

File tests/07-listener-error.phpt

 --TEST--
 Check for EventListener error behaviour 
+--SKIPIF--
+<?php
+if (!class_exists("EventListener")) echo "skip Event extra functions are disabled"
+?>
 --FILE--
 <?php
 $base = new EventBase();