Commits

Ruslan Osmanov committed c3be5fc

Add: EventBufferEvent input and output properties (cached)

Comments (0)

Files changed (5)

 		res_pos->p = evbuffer_search_range(b->buf, what, (size_t) what_len,
 				&start_pos->p, &end_pos->p);
 	} else {
-		res_pos->p = evbuffer_search(b->buf, what, (size_t) what_len, &start_pos->p);
+		res_pos->p = evbuffer_search(b->buf, what, (size_t) what_len, (start_pos ? &start_pos->p : NULL));
 	}
 
 	if (res_pos->p.pos == -1) {

classes/buffer_event.c

 	}
 
 	bev->self = zself;
-	/* Ensure the object won't be destroyed in case if we are in a callback */
+	/* Ensure the object won't be destroyed in case if we are in a callback
+	 * XXX Get rid of this! */
 	Z_ADDREF_P(zself);
 }
 /* }}} */

examples/httpv0client.php

 
 /* Read callback */
 function readcb($bev, $base) {
-	$input = $bev->getInput();
+	$input = $bev->input; //$bev->getInput();
 
 	$pos = $input->search("TTP");
-	var_dump($pos);
 
 	while (($n = $input->remove($buf, 1024)) > 0) {
 		echo $buf;
 $bev->setCallbacks("readcb", /* writecb */ NULL, "eventcb", $base);
 $bev->enable(Event::READ | Event::WRITE);
 
-$output = $bev->getOutput();
+$output = $bev->output; //$bev->getOutput();
 if (!$output->add(
 	"GET {$argv[2]} HTTP/1.0\r\n".
 	"Host: {$argv[1]}\r\n".
 }
 /* }}} */
 
+/* {{{ event_bevent_input_prop_read */
+static int event_bevent_input_prop_read(php_event_abstract_object_t *obj, zval **retval TSRMLS_DC)
+{
+	php_event_bevent_t *bev = (php_event_bevent_t *) obj;
+
+	if (bev->input) {
+		*retval = bev->input;
+		Z_ADDREF_P(bev->input);
+		return SUCCESS;
+	}
+
+	php_event_buffer_t *b;
+
+	MAKE_STD_ZVAL(*retval);
+
+	PHP_EVENT_INIT_CLASS_OBJECT(*retval, php_event_buffer_ce);
+	PHP_EVENT_FETCH_BUFFER(b, *retval);
+
+	b->buf      = bufferevent_get_input(bev->bevent);
+	b->internal = 1;
+
+	// Cache the pointer
+	bev->input = *retval;
+	Z_ADDREF_P(bev->input);
+
+	return SUCCESS;
+}
+/* }}} */
+
+/* {{{ event_bevent_output_prop_read */
+static int event_bevent_output_prop_read(php_event_abstract_object_t *obj, zval **retval TSRMLS_DC)
+{
+	php_event_bevent_t *bev = (php_event_bevent_t *) obj;
+
+	if (bev->output) {
+		*retval = bev->output;
+		Z_ADDREF_P(bev->output);
+		return SUCCESS;
+	}
+
+	php_event_buffer_t *b;
+
+	MAKE_STD_ZVAL(*retval);
+
+	PHP_EVENT_INIT_CLASS_OBJECT(*retval, php_event_buffer_ce);
+	PHP_EVENT_FETCH_BUFFER(b, *retval);
+
+	b->buf      = bufferevent_get_output(bev->bevent);
+	b->internal = 1;
+
+	// Cache the pointer
+	bev->output = *retval;
+	Z_ADDREF_P(bev->output);
+
+	return SUCCESS;
+}
+/* }}} */
+
 
 #if LIBEVENT_VERSION_NUMBER >= 0x02010100
 /* {{{ event_bevent_allow_ssl_dirty_shutdown_prop_write*/
 };
 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 },
+	{"input",    sizeof("input")    - 1, event_bevent_input_prop_read,    NULL,                             NULL },
+	{"output",   sizeof("output")   - 1, event_bevent_output_prop_read,   NULL,                             NULL },
 
 #if LIBEVENT_VERSION_NUMBER >= 0x02010100
 	{"allow_ssl_dirty_shutdown", sizeof("allow_ssl_dirty_shutdown") - 1,
 };
 const zend_property_info event_bevent_property_entry_info[] = {
 	{ZEND_ACC_PUBLIC, "priority", sizeof("priority") - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "input", sizeof("input") - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "output", sizeof("output") - 1, -1, 0, NULL, 0, NULL},
 #if LIBEVENT_VERSION_NUMBER >= 0x02010100
 	{ZEND_ACC_PUBLIC, "allow_ssl_dirty_shutdown", sizeof("allow_ssl_dirty_shutdown") - 1, -1, 0, NULL, 0, NULL},
 #endif
 	int                    stream_id;   /* Resource ID of the file descriptor. -1 if none */
 	zval                  *self;        /* Object itself. For callbacks                   */
 	zval                  *data;        /* User custom data                               */
+	zval                  *input;       /* Input buffer */
+	zval                  *output;      /* Output buffer */
 
     /* fci and fcc members represent userspace callbacks */
 	zend_fcall_info       *fci_read;