Commits

Ruslan Osmanov committed 8ac18c6 Merge

Merge branch 'bevent_buf_props'

Comments (0)

Files changed (6)

 		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 */
+	bev->input = bev->output = NULL;
+	/* 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");
+	$pos = $bev->input->search("TTP");
 
-	$pos = $input->search("TTP");
-	var_dump($pos);
-
-	while (($n = $input->remove($buf, 1024)) > 0) {
+	while (($n = $bev->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".
 			b->self = NULL;
 		}
 #endif
+		if (b->input) {
+			zval_ptr_dtor(&b->input);
+			b->input = NULL;
+		}
+
+		if (b->output) {
+			zval_ptr_dtor(&b->output);
+			b->output= NULL;
+		}
 
 		if (b->bevent) {
 			bufferevent_free(b->bevent);
 }
 /* }}} */
 
+/* {{{ 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;
+
+	MAKE_STD_ZVAL(*retval);
+
+	if (bev->input) {
+		ZVAL_ZVAL(*retval, bev->input, 1, 0);
+		return SUCCESS;
+	}
+
+	php_event_buffer_t *b;
+
+	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;
+
+	MAKE_STD_ZVAL(bev->input);
+	ZVAL_ZVAL(bev->input, *retval, 1, 0);
+	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;
+
+	MAKE_STD_ZVAL(*retval);
+	if (bev->output) {
+		ZVAL_ZVAL(*retval, bev->output, 1, 0);
+		Z_ADDREF_P(bev->output);
+		return SUCCESS;
+	}
+
+	php_event_buffer_t *b;
+
+	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;
+
+	MAKE_STD_ZVAL(bev->output);
+	ZVAL_ZVAL(bev->output, *retval, 1, 0);
+	Z_ADDREF_P(bev->output);
+
+	return SUCCESS;
+}
+/* }}} */
+
+
+/* {{{ event_bevent_input_prop_ptr_ptr */
+static zval **event_bevent_input_prop_ptr_ptr(php_event_abstract_object_t *obj TSRMLS_DC)
+{
+	php_event_bevent_t *bev = (php_event_bevent_t *) obj;
+
+	return bev->input ? &bev->input : NULL;
+}
+/* }}} */
+
+/* {{{ event_bevent_output_prop_ptr_ptr */
+static zval **event_bevent_output_prop_ptr_ptr(php_event_abstract_object_t *obj TSRMLS_DC)
+{
+	php_event_bevent_t *bev = (php_event_bevent_t *) obj;
+
+	return bev->output ? &bev->output : NULL;
+}
+/* }}} */
+
 
 #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,                             event_bevent_input_prop_ptr_ptr},
+	{"output",   sizeof("output")   - 1, event_bevent_output_prop_read,   NULL,                             event_bevent_output_prop_ptr_ptr},
 
 #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;
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.