Commits

Ruslan Osmanov committed 5a79296

Change: for all functions set the same names as in libevent itself
Add: function aliases for compat. with libevent ext.

Comments (0)

Files changed (4)

 /* {{{ API functions */
 
 
-/* {{{ proto resource event_timer_new(resource base, callable cb[, zval arg = NULL]);
+/* {{{ proto resource evtimer_new(resource base, callable cb[, zval arg = NULL]);
  * Creates new event */
-PHP_FUNCTION(event_timer_new)
+PHP_FUNCTION(evtimer_new)
 {
 	zval                  *zbase;
 	php_event_base_t      *base;
 }
 /* }}} */
 
-/* {{{ proto bool event_timer_set(resource event, resource base, callable cb[, zval arg = NULL]);
+/* {{{ proto bool evtimer_set(resource event, resource base, callable cb[, zval arg = NULL]);
  * Re-configures timer event.
  * Note, this function doesn't invoke obsolete libevent's event_set. It calls event_assign instead. */
-PHP_FUNCTION(event_timer_set)
+PHP_FUNCTION(evtimer_set)
 {
 	zval                  *zbase;
 	php_event_base_t      *base;
 }
 /* }}} */
 
-/* {{{ proto bool event_timer_pending(resource event);
+/* {{{ proto bool evtimer_pending(resource event);
  * Detect whether timer event is pending or scheduled. */
-PHP_FUNCTION(event_timer_pending)
+PHP_FUNCTION(evtimer_pending)
 {
 	zval        *zevent;
 	php_event_t *e;
 
 
 
-/* {{{ proto resource event_buffer_socket_new(resource base[, resource socket = NULL[, int options = 0]]);
+/* {{{ proto resource bufferevent_socket_new(resource base[, resource socket = NULL[, int options = 0]]);
  *
  * Create a socket-based bufferevent.
  * options is one of EVENT_BEV_OPT_* constants, or 0.
  * e.g. by means of bufferevent_socket_connect().
  *
  * Returns bufferevent resource optionally associated with socket resource. */
-PHP_FUNCTION(event_buffer_socket_new)
+PHP_FUNCTION(bufferevent_socket_new)
 {
 	zval                *zbase;
 	php_event_base_t    *base;
 		evutil_make_socket_nonblocking(fd);
 	} else {
  		/* User decided to assign fd later,
- 		 * e.g. by means of event_buffer_socket_connect()
+ 		 * e.g. by means of bufferevent_socket_connect()
  		 * which allocates new socket stream in this case. */
 		fd = -1;
 	}
 		b->stream_id = Z_LVAL_PP(ppzfd);
 		zend_list_addref(Z_LVAL_PP(ppzfd));
 	} else {
-		/* Should be assigned in event_buffer_socket_connect() later
+		/* Should be assigned in bufferevent_socket_connect() later
 		 * (by means of bufferevent_getfd()) */
 		b->stream_id = -1;
 	}
 }
 /* }}} */
 
-/* {{{ proto void event_buffer_free(resource bevent);
+/* {{{ proto void bufferevent_free(resource bevent);
  * Free a buffer event resource. */
-PHP_FUNCTION(event_buffer_free)
+PHP_FUNCTION(bufferevent_free)
 {
 	php_event_bevent_t *bev;
 	zval               *zbevent;
 
 /* }}} */
 
-/* {{{ proto bool event_buffer_socket_connect(resource bevent, string addr[, bool sync_resolve = FALSE]);
+/* {{{ proto bool bufferevent_socket_connect(resource bevent, string addr[, bool sync_resolve = FALSE]);
  *
  * Connect bufferevent's socket to given address(optionally with port).  The
  * function available since libevent 2.0.2-alpha.
  *    IPv4Address
  * 
  * To resolve DNS names asyncronously, use
- * event_buffer_socket_connect_hostname() function.
+ * bufferevent_socket_connect_hostname() function.
  */
-PHP_FUNCTION(event_buffer_socket_connect)
+PHP_FUNCTION(bufferevent_socket_connect)
 {
 	php_event_bevent_t *bev;
 	zval               *zbevent;
 }
 /* }}} */
 
-/* {{{ proto bool event_buffer_socket_connect(resource bevent, resource dns_base, string hostname, int port[, int family = EVENT_AF_UNSPEC]);
+/* {{{ proto bool bufferevent_socket_connect(resource bevent, resource dns_base, string hostname, int port[, int family = EVENT_AF_UNSPEC]);
  *
  * Resolves the DNS name hostname, looking for addresses of type
  * family(EVENT_AF_* constants). If the name resolution fails, it invokes the
  * event callback with an error event. If it succeeds, it launches a connection
- * attempt just as event_buffer_socket_connect would.
+ * attempt just as bufferevent_socket_connect would.
  *
  * dns_base is optional. May be NULL, or a resource created with
  * event_dns_base_new()(requires --with-event-extra configure option).
  * For asyncronous hostname resolving pass a valid event dns base resource.
  * Otherwise the hostname resolving will block.
  */
-PHP_FUNCTION(event_buffer_socket_connect_hostname)
+PHP_FUNCTION(bufferevent_socket_connect_hostname)
 {
 #if LIBEVENT_VERSION_NUMBER < 0x02000300
-	PHP_EVENT_LIBEVENT_VERSION_REQUIRED(event_buffer_socket_connect_hostname, 2.0.3-alpha);
+	PHP_EVENT_LIBEVENT_VERSION_REQUIRED(bufferevent_socket_connect_hostname, 2.0.3-alpha);
 	RETVAL_FALSE;
 #else
 	php_event_bevent_t   *bev;
 }
 /* }}} */
 
-/* {{{ proto mixed event_buffer_socket_get_dns_error(resource bevent);
+/* {{{ proto mixed bufferevent_socket_get_dns_error(resource bevent);
  *
  * Finds out what the most recent error was.
  *
  * If there was a DNS error encountered on the buffer event, returns
  * descriptive string.  Otherwise returns NULL. */
-PHP_FUNCTION(event_buffer_socket_get_dns_error)
+PHP_FUNCTION(bufferevent_socket_get_dns_error)
 {
 	php_event_bevent_t *bev;
 	zval               *zbevent;
 }
 /* }}} */
 
-/* {{{ proto void event_buffer_set_callbacks(resource bevent, callable readcb, callable writecb, callable eventcb[, mixed arg = NULL]);
+/* {{{ proto void bufferevent_setcb(resource bevent, callable readcb, callable writecb, callable eventcb[, mixed arg = NULL]);
  * Changes one or more of the callbacks of a bufferevent.
  * A callback may be disabled by passing NULL instead of the callable.
  * arg is an argument passed to the callbacks.
  */
-PHP_FUNCTION(event_buffer_set_callbacks)
+PHP_FUNCTION(bufferevent_setcb)
 {
 #ifndef PHP_EVENT_SOCKETS_SUPPORT 
 	PHP_EVENT_RET_SOCKETS_REQUIRED_NORET;
 }
 /* }}} */
 
-/* {{{ proto void event_buffer_enable(resource bevent, int events);
+/* {{{ proto void bufferevent_enable(resource bevent, int events);
  * Enable events EVENT_READ, EVENT_WRITE, or EVENT_READ | EVENT_WRITE on a buffer event. */
-PHP_FUNCTION(event_buffer_enable)
+PHP_FUNCTION(bufferevent_enable)
 {
 	php_event_bevent_t *bev;
 	zval               *zbevent;
 }
 /* }}} */
 
-/* {{{ proto void event_buffer_disable(resource bevent, int events);
+/* {{{ proto void bufferevent_disable(resource bevent, int events);
  * Disable events EVENT_READ, EVENT_WRITE, or EVENT_READ | EVENT_WRITE on a buffer event. */
-PHP_FUNCTION(event_buffer_disable)
+PHP_FUNCTION(bufferevent_disable)
 {
 	php_event_bevent_t *bev;
 	zval               *zbevent;
 }
 /* }}} */
 
-/* {{{ proto int event_buffer_get_enabled(resource bevent);
+/* {{{ proto int bufferevent_get_enabled(resource bevent);
  * Returns bitmask of events currently enabled on the buffer event. */
-PHP_FUNCTION(event_buffer_get_enabled)
+PHP_FUNCTION(bufferevent_get_enabled)
 {
 	php_event_bevent_t *bev;
 	zval               *zbevent;
 }
 /* }}} */
 
-/* {{{ proto void event_buffer_set_watermark(resource bevent, int events, int lowmark, int highmark);
+/* {{{ proto void bufferevent_set_watermark(resource bevent, int events, int lowmark, int highmark);
  * Adjusts the read watermarks, the write watermarks, or both, of a single bufferevent. */
-PHP_FUNCTION(event_buffer_set_watermark)
+PHP_FUNCTION(bufferevent_set_watermark)
 {
 	php_event_bevent_t *bev;
 	zval               *zbevent;
 	ZEND_ARG_INFO(0, flags)
 ZEND_END_ARG_INFO();
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_event_timer_new, 0, 0, 2)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_evtimer_new, 0, 0, 2)
 	ZEND_ARG_INFO(0, base)
 	ZEND_ARG_INFO(0, cb)
 	ZEND_ARG_INFO(0, arg)
 ZEND_END_ARG_INFO();
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_event_timer_set, 0, 0, 3)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_evtimer_set, 0, 0, 3)
 	ZEND_ARG_INFO(0, event)
 	ZEND_ARG_INFO(0, base)
 	ZEND_ARG_INFO(0, cb)
 #endif
 
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_1, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_bufferevent_1, 0, 0, 1)
 	ZEND_ARG_INFO(0, bevent)
 ZEND_END_ARG_INFO();
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer__events, 0, 0, 2)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_bufferevent__events, 0, 0, 2)
 	ZEND_ARG_INFO(0, bevent)
 	ZEND_ARG_INFO(0, events)
 ZEND_END_ARG_INFO();
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_socket_new, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_bufferevent_socket_new, 0, 0, 1)
 	ZEND_ARG_INFO(0, base)
 	ZEND_ARG_INFO(0, fd)
 	ZEND_ARG_INFO(0, options)
 ZEND_END_ARG_INFO();
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_socket_connect, 0, 0, 2)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_bufferevent_socket_connect, 0, 0, 2)
 	ZEND_ARG_INFO(0, bevent)
 	ZEND_ARG_INFO(0, addr)
 ZEND_END_ARG_INFO();
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_set_callbacks, 0, 0, 4)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_bufferevent_set_callbacks, 0, 0, 4)
 	ZEND_ARG_INFO(0, bevent)
 	ZEND_ARG_INFO(0, readcb)
 	ZEND_ARG_INFO(0, writecb)
 	ZEND_ARG_INFO(0, arg)
 ZEND_END_ARG_INFO();
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_set_watermark, 0, 0, 4)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_bufferevent_set_watermark, 0, 0, 4)
 	ZEND_ARG_INFO(0, bevent)
 	ZEND_ARG_INFO(0, events)
 	ZEND_ARG_INFO(0, lowmark)
 	PHP_FE(event_remove_timer, arginfo_event_1)
 #endif
 
-	PHP_FE(event_timer_new,     arginfo_event_timer_new)
-	PHP_FE(event_timer_set,     arginfo_event_timer_set)
-	PHP_FE(event_timer_pending, arginfo_event_1)
+	PHP_FE(evtimer_new,     arginfo_evtimer_new)
+	PHP_FE(evtimer_set,     arginfo_evtimer_set)
+	PHP_FE(evtimer_pending, arginfo_event_1)
+
+	PHP_FALIAS(evtimer_add, event_add, arginfo_event_add)
+	PHP_FALIAS(evtimer_del, event_del, arginfo_event_1)
 
 	PHP_FE(event_base_new,                 arginfo_event__void)
 	PHP_FE(event_base_new_with_config,     arginfo_event_base_config_1)
 	PHP_FE(event_config_set_max_dispatch_interval, arginfo_event_config_set_max_dispatch_interval)
 #endif
 
-	PHP_FE(event_buffer_socket_new,           arginfo_event_buffer_socket_new)
-	PHP_FE(event_buffer_free,                 arginfo_event_buffer_1)
-	PHP_FE(event_buffer_socket_connect,       arginfo_event_buffer_socket_connect)
-	PHP_FE(event_buffer_socket_get_dns_error, arginfo_event_buffer_1)
-	PHP_FE(event_buffer_set_callbacks,        arginfo_event_buffer_set_callbacks)
-	PHP_FE(event_buffer_enable,               arginfo_event_buffer__events)
-	PHP_FE(event_buffer_disable,              arginfo_event_buffer__events)
-	PHP_FE(event_buffer_get_enabled,          arginfo_event_buffer_1)
-	PHP_FE(event_buffer_set_watermark,        arginfo_event_buffer_set_watermark)
+	PHP_FE(bufferevent_socket_new,           arginfo_bufferevent_socket_new)
+	PHP_FE(bufferevent_free,                 arginfo_bufferevent_1)
+	PHP_FE(bufferevent_socket_connect,       arginfo_bufferevent_socket_connect)
+	PHP_FE(bufferevent_socket_get_dns_error, arginfo_bufferevent_1)
+	PHP_FE(bufferevent_setcb,                arginfo_bufferevent_set_callbacks)
+	PHP_FE(bufferevent_enable,               arginfo_bufferevent__events)
+	PHP_FE(bufferevent_disable,              arginfo_bufferevent__events)
+	PHP_FE(bufferevent_get_enabled,          arginfo_bufferevent_1)
+	PHP_FE(bufferevent_set_watermark,        arginfo_bufferevent_set_watermark)
+	
+	/* These aliases are for compatibility with libevent extension */
+
+	PHP_FALIAS(event_timer_new,            evtimer_new,               arginfo_evtimer_new)
+	PHP_FALIAS(event_timer_set,            evtimer_set,               arginfo_evtimer_set)
+	PHP_FALIAS(event_timer_pending,        evtimer_pending,           arginfo_event_1)
+	PHP_FALIAS(event_timer_add,            event_add,                 arginfo_event_add)
+	PHP_FALIAS(event_timer_del,            event_del,                 arginfo_event_1)
+
+	PHP_FALIAS(event_buffer_free,          bufferevent_free,          arginfo_bufferevent_1)
+	PHP_FALIAS(event_buffer_set_callback,  bufferevent_setcb,         arginfo_bufferevent_set_callbacks)
+	PHP_FALIAS(event_buffer_enable,        bufferevent_enable,        arginfo_bufferevent__events)
+	PHP_FALIAS(event_buffer_disable,       bufferevent_disable,       arginfo_bufferevent__events)
+	PHP_FALIAS(event_buffer_watermark_set, bufferevent_set_watermark, arginfo_bufferevent_set_watermark)
+
 
 #if HAVE_EVENT_EXTRA_LIB
 /* {{{ Extra API */
 /* Extra API END}}} */
 #endif
 
+
 	PHP_FE_END
 };
 /* }}} */
 PHP_FUNCTION(event_pending);
 PHP_FUNCTION(event_free);
 
-PHP_FUNCTION(event_timer_new);
-PHP_FUNCTION(event_timer_set);
-PHP_FUNCTION(event_timer_pending);
+PHP_FUNCTION(evtimer_new);
+PHP_FUNCTION(evtimer_set);
+PHP_FUNCTION(evtimer_pending);
 
 PHP_FUNCTION(event_base_new);
 PHP_FUNCTION(event_base_new_with_config);
 PHP_FUNCTION(event_config_set_max_dispatch_interval);
 #endif
 
-PHP_FUNCTION(event_buffer_socket_new);
-PHP_FUNCTION(event_buffer_free);
-PHP_FUNCTION(event_buffer_socket_connect);
-PHP_FUNCTION(event_buffer_set_callbacks);
-PHP_FUNCTION(event_buffer_enable);
-PHP_FUNCTION(event_buffer_disable);
-PHP_FUNCTION(event_buffer_get_enabled);
-PHP_FUNCTION(event_buffer_set_watermark);
-PHP_FUNCTION(event_buffer_socket_get_dns_error);
+PHP_FUNCTION(bufferevent_socket_new);
+PHP_FUNCTION(bufferevent_free);
+PHP_FUNCTION(bufferevent_socket_connect);
+PHP_FUNCTION(bufferevent_setcb);
+PHP_FUNCTION(bufferevent_enable);
+PHP_FUNCTION(bufferevent_disable);
+PHP_FUNCTION(bufferevent_get_enabled);
+PHP_FUNCTION(bufferevent_set_watermark);
+PHP_FUNCTION(bufferevent_socket_get_dns_error);
+
 
 #if HAVE_EVENT_EXTRA_LIB
 /* {{{ Extra API */

tests/04-bevent-socket.phpt

 --FILE--
 <?php 
 $base = event_base_new();
-$bev = event_buffer_socket_new($base, NULL, EVENT_BEV_OPT_CLOSE_ON_FREE);
+$bev = bufferevent_socket_new($base, NULL, EVENT_BEV_OPT_CLOSE_ON_FREE);
 
-if (! event_buffer_socket_connect($bev, "www.php.net:80", TRUE)) {
+if (! bufferevent_socket_connect($bev, "www.php.net:80", TRUE)) {
 	exit("event_buffer_socket_connect failed\n");
 }
 
-event_buffer_set_callbacks($bev, NULL, NULL, function ($bev, $events, $data) {
+bufferevent_setcb($bev, NULL, NULL, function ($bev, $events, $data) {
 	if ($events & EVENT_BEV_EVENT_CONNECTED) {
 		/* We're connected to 127.0.0.1:8080.   Ordinarily we'd do
 		something here, like start reading or writing. */