Ruslan Osmanov avatar Ruslan Osmanov committed 18975bc

Renamed EventBuffer::remove to EventBuffer::read, EventBuffer::read now takes only max_bytes argument and returns string.
Renamed EventBuffer::removeBuffer to EventBuffer::appendFrom
EventBuffer::read now takes single argument 'size' and returns the string read

Comments (0)

Files changed (9)

 }
 /* }}} */
 
-/* {{{ proto int EventBuffer::remove(string &data, long max_bytes);
+/* {{{ proto string EventBuffer::read(long max_bytes);
  *
  * Read data from an evbuffer and drain the bytes read.  If more bytes are
  * requested than are available in the evbuffer, we only extract as many bytes
  * as were available.
- *
- * Returns the number of bytes read, or -1 if we can't drain the buffer.
  */
-PHP_METHOD(EventBuffer, remove)
+PHP_METHOD(EventBuffer, read)
 {
 	php_event_buffer_t *b;
 	zval               *zbuf      = getThis();
-	zval               *zdata;
 	long                max_bytes;
 	long                ret;
 	char               *data;
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl",
-				&zdata, &max_bytes) == FAILURE) {
-		return;
-	}
-
-	if (!Z_ISREF_P(zdata)) {
-		/* Was not passed by reference */
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
+				&max_bytes) == FAILURE) {
 		return;
 	}
 
 	data = emalloc(sizeof(char) * max_bytes + 1);
 
 	ret = evbuffer_remove(b->buf, data, max_bytes);
-
 	if (ret > 0) {
-		convert_to_string(zdata);
-		zval_dtor(zdata);
-		Z_STRVAL_P(zdata) = estrndup(data, ret);
-		Z_STRLEN_P(zdata) = ret;
+		RETVAL_STRINGL(data, ret, 1);
+	} else {
+		RETVAL_NULL();
 	}
 
 	efree(data);
-
-	RETVAL_LONG(ret);
 }
 /* }}} */
 
 }
 /* }}} */
 
-/* {{{ proto int EventBuffer::removeBuffer(EventBuffer buf, int len); 
+/* {{{ proto int EventBuffer::appendFrom(EventBuffer buf, int len); 
  * Moves exactly len bytes from buf to the end of current instance of EventBuffer
  */
-PHP_METHOD(EventBuffer, removeBuffer)
+PHP_METHOD(EventBuffer, appendFrom)
 {
 	php_event_buffer_t *b_dst;
 	php_event_buffer_t *b_src;
 	PHP_EVENT_FETCH_BUFFER(b_src, zbuf_src);
 
 	RETVAL_LONG(evbuffer_remove_buffer(b_src->buf, b_dst->buf, (size_t) len));
-
 }
 /* }}} */
 

classes/buffer_event.c

 }
 /* }}} */
 
-/* {{{ proto int EventBufferEvent::read(string &data, int size);
+/* {{{ proto string EventBufferEvent::read(int size);
  * Removes up to size bytes from the input buffer, storing them into the memory at data.
- *
- * Returns the number of bytes actually removed.  */
+ */
 PHP_METHOD(EventBufferEvent, read)
 {
 	zval               *zbevent = getThis();
 	php_event_bevent_t *bev;
-	zval               *zdata;
 	long                size;
 	char               *data;
 	long                ret;
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl",
-				&zdata, &size) == FAILURE) {
-		return;
-	}
-
-	if (!Z_ISREF_P(zdata)) {
-		/* Was not passed by reference */
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
+				&size) == FAILURE) {
 		return;
 	}
 
 	ret = bufferevent_read(bev->bevent, data, size);
 
 	if (ret > 0) {
-		convert_to_string(zdata);
-		zval_dtor(zdata);
-		Z_STRVAL_P(zdata) = estrndup(data, ret);
-		Z_STRLEN_P(zdata) = ret;
+		RETVAL_STRINGL(data, ret, 1);
+	} else {
+		RETVAL_NULL();
 	}
 
 	efree(data);
-
-	RETVAL_LONG(ret);
 }
 /* }}} */
 

examples/httpv0client.php

 	//$pos = $input->search("TTP");
 	$pos = $bev->input->search("TTP");
 
-	while (($n = $bev->input->remove($buf, 1024)) > 0) {
+	while (!empty($buf = $bev->input->read(1024)) > 0) {
 		echo $buf;
 	}
 }

examples/httpv0client2.php

 function readcb($bev, $base) {
 	$input = $bev->getInput();
 
-	while (($n = $input->remove($buf, 1024)) > 0) {
+	while (!empty($buf = $input->read(1024))) {
 		echo $buf;
 	}
 }

examples/uppercase_proxy.php

 	$tmp = NULL;
 
 	while (1) {
-		$n = bufferevent_read($bev, $tmp, 128);
-		($n > 0) or break;
-		bufferevent_write($bev, strtoupper($tmp), $n);
+		$tmp = $bev->read(128);
+		(!empty($tmp)) or break;
+		$bev->write(strtoupper($tmp), $n);
 	}
 }
 ?>
   Fix: build error with libevent_extra disabled
   Add: EventListener fd readonly property for numeric file descriptor of the socket associated with the listener
   Add: EventBuffer::substr method
+
+  INCOMPATIBLE CHANGES!
+  Renamed EventBuffer::remove to EventBuffer::read, EventBuffer::read now takes only max_bytes argument and returns string.
+  Renamed EventBuffer::removeBuffer to EventBuffer::appendFrom
+  EventBuffer::read now takes single argument 'size' and returns the string read
   ]]></notes>
   <!--}}}-->
   <!--{{{ Contents -->
   Fix: build error with libevent_extra disabled
   Add: EventListener fd readonly property for numeric file descriptor of the socket associated with the listener
   Add: EventBuffer::substr method
+
+  INCOMPATIBLE CHANGES!
+  Renamed EventBuffer::remove to EventBuffer::read, EventBuffer::read now takes only max_bytes argument and returns string.
+  Renamed EventBuffer::removeBuffer to EventBuffer::appendFrom
+  EventBuffer::read now takes single argument 'size' and returns the string read
   ]]></notes>
     </release>
     <!--}}}-->
 	ZEND_ARG_INFO(0, buf)
 ZEND_END_ARG_INFO();
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_bufferevent_read, 0, 0, 2)
-	ZEND_ARG_INFO(1, data)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_bufferevent_read, 0, 0, 1)
 	ZEND_ARG_INFO(0, size)
 ZEND_END_ARG_INFO();
 
 	ZEND_ARG_INFO(0, len)
 ZEND_END_ARG_INFO();
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_evbuffer_remove, 0, 0, 2)
-	ZEND_ARG_INFO(1, data)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_evbuffer_remove, 0, 0, 1)
 	ZEND_ARG_INFO(0, max_bytes)
 ZEND_END_ARG_INFO();
 
 	PHP_ME(EventBuffer, enableLocking, arginfo_event__void,            ZEND_ACC_PUBLIC)
 	PHP_ME(EventBuffer, add,           arginfo_evbuffer_add,           ZEND_ACC_PUBLIC)
 	PHP_ME(EventBuffer, addBuffer,     arginfo_evbuffer_add_buffer,    ZEND_ACC_PUBLIC)
-	PHP_ME(EventBuffer, removeBuffer,  arginfo_evbuffer_remove_buffer, ZEND_ACC_PUBLIC)
-	PHP_ME(EventBuffer, remove,        arginfo_evbuffer_remove,        ZEND_ACC_PUBLIC)
+	PHP_ME(EventBuffer, appendFrom,    arginfo_evbuffer_remove_buffer, ZEND_ACC_PUBLIC)
+	PHP_ME(EventBuffer, read,          arginfo_evbuffer_remove,        ZEND_ACC_PUBLIC)
 	PHP_ME(EventBuffer, expand,        arginfo_evbuffer_len,           ZEND_ACC_PUBLIC)
 	PHP_ME(EventBuffer, prepend,       arginfo_evbuffer_add,           ZEND_ACC_PUBLIC)
 	PHP_ME(EventBuffer, prependBuffer, arginfo_evbuffer_add_buffer,    ZEND_ACC_PUBLIC)
 PHP_METHOD(EventBuffer, unlock);
 PHP_METHOD(EventBuffer, enableLocking);
 PHP_METHOD(EventBuffer, add);
-PHP_METHOD(EventBuffer, remove);
+PHP_METHOD(EventBuffer, read);
 PHP_METHOD(EventBuffer, addBuffer);
-PHP_METHOD(EventBuffer, removeBuffer);
+PHP_METHOD(EventBuffer, appendFrom);
 PHP_METHOD(EventBuffer, expand);
 PHP_METHOD(EventBuffer, prepend);
 PHP_METHOD(EventBuffer, prependBuffer);

tests/08-buffer.phpt

 
 $tmp = "";
 for ($i = 0, $j = 1; $i < $s_len; $i += 4, ++$j) {
-	if ($b2->removeBuffer($b1, 4)) {
-		$b2->remove($tmp, 32);
+	if ($b2->appendFrom($b1, 4)) {
+		$tmp = $b2->read(32);
 		echo $j, ' ', $tmp == substr($s, $i, 4) ? "ok" : "failed", PHP_EOL;
 	}
 }
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.