Commits

Ruslan Osmanov committed 8440fb8

Change: replace varargs with single arg for evbuffer_add

Comments (0)

Files changed (3)

 }
 /* }}} */
 
-/* {{{ proto bool evbuffer_add(resource buf, ...);
+/* {{{ proto bool evbuffer_add(resource buf, string data); 
  *
- * Append data to the end of an event buffer. The function accepts variable set
- * of arguments. Each argument is converted to string.
+ * Append data to the end of an event buffer.
  */
 PHP_FUNCTION(evbuffer_add)
 {
 	php_event_buffer_t   *b;
 	zval                 *zbuf;
-	int                   i;
-	int                   num_varargs;
-	zval               ***varargs     = NULL;
-	zval                **ppz;
+	zval                **ppzdata;
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r+",
-				&zbuf, &varargs, &num_varargs) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ",
+				&zbuf, &ppzdata) == FAILURE) {
 		return;
 	}
 
 	PHP_EVENT_FETCH_BUFFER(b, zbuf);
 
-	for (i = 0; i < num_varargs; i++) {
-		ppz = varargs[i];
-		convert_to_string_ex(ppz);
+	convert_to_string_ex(ppzdata);
 
-		if (evbuffer_add(b->buf, (void *) Z_STRVAL_PP(ppz), Z_STRLEN_PP(ppz))) {
-			RETVAL_FALSE;
-			break;
-		}
-	}
-
-	if (varargs) {
-		efree(varargs);
+	if (evbuffer_add(b->buf, (void *) Z_STRVAL_PP(ppzdata), Z_STRLEN_PP(ppzdata))) {
+		RETURN_FALSE;
 	}
-
 	RETVAL_TRUE;
 }
 /* }}} */

examples/httpv0client.php

 <?php
+/* Read callback */
 function readcb($bev, $base) {
 	$input = bufferevent_get_input($bev);
 
 	}
 }
 
+/* Event callback */
 function eventcb($bev, $events, $base) {
 	if ($events & EVENT_BEV_EVENT_CONNECTED) {
 		echo "Connected.\n";
 		echo "Closing\n";
 		bufferevent_free($bev);
 		event_base_loopexit($base);
-		exit("exit\n");
+		exit("Done\n");
 	}
 }
 
 }
 
 $base = event_base_new();
-$dns_base = evdns_base_new($base, TRUE);
-echo "rsrc type of \$dns_base= ", get_resource_type($dns_base), PHP_EOL;
+
+$dns_base = evdns_base_new($base, TRUE); // We'll use async DNS resolving
 if (!$dns_base) {
 	exit("Failed to init DNS Base\n");
 }
 
-$bev = bufferevent_socket_new($base, NULL, EVENT_BEV_OPT_CLOSE_ON_FREE /*| EVENT_BEV_OPT_DEFER_CALLBACKS*/);
+$bev = bufferevent_socket_new($base, /* use internal socket */ NULL,
+	EVENT_BEV_OPT_CLOSE_ON_FREE | EVENT_BEV_OPT_DEFER_CALLBACKS);
+if (!$bev) {
+	exit("Failed creating bufferevent socket\n");
+}
 
-bufferevent_setcb($bev, "readcb", NULL, "eventcb", $base);
+bufferevent_setcb($bev, "readcb", /* writecb */ NULL, "eventcb", $base);
 bufferevent_enable($bev, EVENT_READ | EVENT_WRITE);
 
 $output = bufferevent_get_output($bev);
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_evbuffer_add, 0, 0, 2)
 	ZEND_ARG_INFO(0, buf)
-	ZEND_ARG_INFO(0, ...)
+	ZEND_ARG_INFO(0, data) 
 ZEND_END_ARG_INFO();
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_evbuffer_remove, 0, 0, 3)