Commits

Ruslan Osmanov  committed 38e7e99

Added some properties
Moved some methods to properties

  • Participants
  • Parent commits a6ec679

Comments (0)

Files changed (6)

File classes/buffer.c

 }
 /* }}} */
 
-/* {{{ proto long EventBuffer::getLength(void);
- * XXX Create property?
- * Returns the total number of bytes stored in the event buffer. */
-PHP_METHOD(EventBuffer, getLength)
-{
-	zval               *zbuf = getThis();
-	php_event_buffer_t *b;
-
-	if (zend_parse_parameters_none() == FAILURE) {
-		return;
-	}
-
-	PHP_EVENT_FETCH_BUFFER(b, zbuf);
-
-	RETVAL_LONG(evbuffer_get_length(b->buf));
-}
-/* }}} */
-
 /* {{{ proto void EventBuffer::lock(void);
  * Acquire the lock on an evbuffer. 
  * Has no effect if locking was not enabled with evbuffer_enable_locking.

File classes/event.c

 }
 /* }}} */
 
-/* {{{ timer_is_pending 
-Whether timer event is pending */
-static zend_always_inline zend_bool timer_is_pending(const struct event *e)
-{
-	return evtimer_pending(e, NULL);
-}
-/* }}} */
 
 /* {{{ timer_cb */
 static void timer_cb(evutil_socket_t fd, short what, void *arg)
 
 	PHP_EVENT_FETCH_EVENT(e, zevent);
 
-	if (timer_is_pending(e->event)) {
+	if (evtimer_pending(e->event, NULL)) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't modify pending timer");
 		RETURN_FALSE;
 		return;
 }
 /* }}} */
 
-/* {{{ proto bool Event::timerPending(void);
- * Detect whether timer event is pending or scheduled.
- * XXX move to properties */
-PHP_METHOD(Event, timerPending)
-{
-	zval        *zevent = getThis();
-	php_event_t *e;
-
-	if (zend_parse_parameters_none() == FAILURE) {
-		return;
-	}
-
-	PHP_EVENT_FETCH_EVENT(e, zevent);
-
-	if (timer_is_pending(e->event)) {
-		RETURN_TRUE;
-	}
-	RETVAL_FALSE;
-	
-}
-/* }}} */
-
-
 /* {{{ proto Event signal(EventBase base, int signum, callable cb[, zval arg = NULL]);
  * Factory method for signal event */
 PHP_METHOD(Event, signal)

File examples/httpv0client.php

 $bev->enable(Event::READ | Event::WRITE);
 
 $output = $bev->getOutput();
-
 if (!$output->add(
 	"GET {$argv[2]} HTTP/1.0\r\n".
 	"Host: {$argv[1]}\r\n".
 	PHP_ME(EventBuffer, __construct,   arginfo_event__void,         ZEND_ACC_PUBLIC  | ZEND_ACC_CTOR)
 	PHP_ME(EventBuffer, freeze,        arginfo_evbuffer_freeze,     ZEND_ACC_PUBLIC)
 	PHP_ME(EventBuffer, unfreeze,      arginfo_evbuffer_freeze,     ZEND_ACC_PUBLIC)
-	PHP_ME(EventBuffer, getLength,     arginfo_event__void,         ZEND_ACC_PUBLIC)
 	PHP_ME(EventBuffer, lock,          arginfo_event__void,         ZEND_ACC_PUBLIC)
 	PHP_ME(EventBuffer, unlock,        arginfo_event__void,         ZEND_ACC_PUBLIC)
 	PHP_ME(EventBuffer, enableLocking, arginfo_event__void,         ZEND_ACC_PUBLIC)
 PHP_METHOD(EventBuffer, __construct);
 PHP_METHOD(EventBuffer, freeze);
 PHP_METHOD(EventBuffer, unfreeze);
-PHP_METHOD(EventBuffer, getLength);
 PHP_METHOD(EventBuffer, lock);
 PHP_METHOD(EventBuffer, unlock);
 PHP_METHOD(EventBuffer, enableLocking);
 #include "priv.h"
 #include "util.h"
 
+/* {{{ event_timer_pending_prop_read */
+static int event_timer_pending_prop_read(php_event_abstract_object_t *obj, zval **retval TSRMLS_DC)
+{
+	php_event_t *e = (php_event_t *) obj;
+
+	PHP_EVENT_ASSERT(e->event);
+
+	MAKE_STD_ZVAL(*retval);
+	ZVAL_BOOL(*retval, (evtimer_pending(e->event, NULL) ? 1 : 0));
+
+	return SUCCESS;
+}
+/* }}} */
+
+
+
+/* {{{ event_buffer_length_prop_read */
+static int event_buffer_length_prop_read(php_event_abstract_object_t *obj, zval **retval TSRMLS_DC)
+{
+	php_event_buffer_t *b = (php_event_buffer_t *) obj;
+
+	PHP_EVENT_ASSERT(b->buf);
+
+	MAKE_STD_ZVAL(*retval);
+	ZVAL_LONG(*retval, evbuffer_get_length(b->buf));
+
+	return SUCCESS;
+}
+/* }}} */
+
+/* {{{ event_buffer_contiguous_space_prop_read */
+static int event_buffer_contiguous_space_prop_read(php_event_abstract_object_t *obj, zval **retval TSRMLS_DC)
+{
+	php_event_buffer_t *b = (php_event_buffer_t *) obj;
+
+	PHP_EVENT_ASSERT(b->buf);
+
+	MAKE_STD_ZVAL(*retval);
+	ZVAL_LONG(*retval, evbuffer_get_contiguous_space(b->buf));
+
+	return SUCCESS;
+}
+/* }}} */
+
+
 const php_event_property_entry_t event_property_entries[] = {
+	{"timer_pending",           sizeof("timer_pending") - 1, event_timer_pending_prop_read, NULL, NULL},
     {NULL, 0, NULL, NULL, NULL}
 };
 const php_event_property_entry_t event_base_property_entries[] = {
     {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}
 };
 const php_event_property_entry_t event_util_property_entries[] = {
 };
 
 const zend_property_info event_property_entry_info[] = {
+	{ZEND_ACC_PUBLIC, "timer_pending", sizeof("timer_pending") - 1, -1, 0, NULL, 0, NULL},
 	{0, NULL, 0, -1, 0, NULL, 0, NULL}
 };
 const zend_property_info event_base_property_entry_info[] = {
 	{0, NULL, 0, -1, 0, NULL, 0, NULL}
 };
 const zend_property_info event_buffer_property_entry_info[] = {
+	{ZEND_ACC_PUBLIC, "length",           sizeof("length")           - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "contiguous_space", sizeof("contiguous_space") - 1, -1, 0, NULL, 0, NULL},
 	{0, NULL, 0, -1, 0, NULL, 0, NULL}
 };
 const zend_property_info event_util_property_entry_info[] = {