├── CREDITS ├── config.w32 ├── libevent.php ├── config.m4 ├── php_libevent.h ├── package.xml └── libevent.c /CREDITS: -------------------------------------------------------------------------------- 1 | Antony Dovgal, Arnaud Le Blanc 2 | -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | ARG_WITH("libevent", "libevent support", "no"); 2 | 3 | if (PHP_LIBEVENT != "no") { 4 | if (CHECK_HEADER_ADD_INCLUDE("event2/event.h", "CFLAGS_LIBEVENT", PHP_PHP_BUILD + "\\include;" + PHP_LIBEVENT) 5 | && CHECK_LIB("libevent.lib", "libevent", PHP_PHP_BUILD + "\\lib;" + PHP_LIBEVENT)) 6 | { 7 | EXTENSION('libevent', 'libevent.c'); 8 | AC_DEFINE('HAVE_LIBEVENT', 1); 9 | } else { 10 | WARNING("libevent not enabled; libraries and headers not found"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /libevent.php: -------------------------------------------------------------------------------- 1 | 59 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl $Id$ 2 | 3 | PHP_ARG_WITH(libevent, for libevent support, 4 | [ --with-libevent Include libevent support]) 5 | 6 | if test "$PHP_LIBEVENT" != "no"; then 7 | SEARCH_PATH="/usr /usr/local" 8 | SEARCH_FOR="/include/event.h" 9 | 10 | if test "$PHP_LIBEVENT" = "yes"; then 11 | AC_MSG_CHECKING([for libevent headers in default path]) 12 | for i in $SEARCH_PATH ; do 13 | if test -r $i/$SEARCH_FOR; then 14 | LIBEVENT_DIR=$i 15 | AC_MSG_RESULT(found in $i) 16 | fi 17 | done 18 | else 19 | AC_MSG_CHECKING([for libevent headers in $PHP_LIBEVENT]) 20 | if test -r $PHP_LIBEVENT/$SEARCH_FOR; then 21 | LIBEVENT_DIR=$PHP_LIBEVENT 22 | AC_MSG_RESULT([found]) 23 | fi 24 | fi 25 | 26 | if test -z "$LIBEVENT_DIR"; then 27 | AC_MSG_RESULT([not found]) 28 | AC_MSG_ERROR([Cannot find libevent headers]) 29 | fi 30 | 31 | PHP_ADD_INCLUDE($LIBEVENT_DIR/include) 32 | 33 | LIBNAME=event 34 | LIBSYMBOL=event_base_new 35 | 36 | if test "x$PHP_LIBDIR" = "x"; then 37 | PHP_LIBDIR=lib 38 | fi 39 | 40 | PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, 41 | [ 42 | PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $LIBEVENT_DIR/$PHP_LIBDIR, LIBEVENT_SHARED_LIBADD) 43 | ],[ 44 | AC_MSG_ERROR([wrong libevent version {1.4.+ is required} or lib not found]) 45 | ],[ 46 | -L$LIBEVENT_DIR/$PHP_LIBDIR 47 | ]) 48 | 49 | PHP_ADD_EXTENSION_DEP(libevent, sockets, true) 50 | PHP_SUBST(LIBEVENT_SHARED_LIBADD) 51 | PHP_NEW_EXTENSION(libevent, libevent.c, $ext_shared) 52 | fi 53 | -------------------------------------------------------------------------------- /php_libevent.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2008 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: Antony Dovgal | 16 | | Arnaud Le Blanc | 17 | +----------------------------------------------------------------------+ 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef PHP_LIBEVENT_H 23 | #define PHP_LIBEVENT_H 24 | 25 | #define PHP_LIBEVENT_VERSION "0.2.0-dev" 26 | 27 | extern zend_module_entry libevent_module_entry; 28 | #define phpext_libevent_ptr &libevent_module_entry 29 | 30 | #ifdef ZTS 31 | #include "TSRM.h" 32 | #endif 33 | 34 | #ifndef zend_always_inline 35 | # if defined(__GNUC__) 36 | # define zend_always_inline inline __attribute__((always_inline)) 37 | # elif defined(_MSC_VER) 38 | # define zend_always_inline __forceinline 39 | # else 40 | # define zend_always_inline inline 41 | # endif 42 | #endif 43 | 44 | #ifndef Z_ADDREF_P 45 | #define Z_ADDREF_P(pz) zval_addref_p(pz) 46 | static zend_always_inline zend_uint zval_addref_p(zval* pz) { 47 | return ++pz->refcount; 48 | } 49 | #endif 50 | 51 | #ifndef Z_DELREF_P 52 | #define Z_DELREF_P(pz) zval_delref_p(pz) 53 | static zend_always_inline zend_uint zval_delref_p(zval* pz) { 54 | return --pz->refcount; 55 | } 56 | #endif 57 | 58 | #endif /* PHP_LIBEVENT_H */ 59 | 60 | 61 | /* 62 | * Local variables: 63 | * tab-width: 4 64 | * c-basic-offset: 4 65 | * End: 66 | * vim600: noet sw=4 ts=4 fdm=marker 67 | * vim<600: noet sw=4 ts=4 68 | */ 69 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | libevent 7 | pecl.php.net 8 | Libevent - event notification 9 | This extension is a wrapper for libevent - event notification library. 10 | 11 | 12 | Antony Dovgal 13 | tony2001 14 | tony2001@php.net 15 | yes 16 | 17 | 18 | Arnaud Le Blanc 19 | lbarnaud 20 | lbarnaud@php.net 21 | yes 22 | 23 | 2013-05-22 24 | 25 | 26 | 0.1.0 27 | 0.1.0 28 | 29 | 30 | beta 31 | beta 32 | 33 | PHP 34 | 35 | - Added event_base_reinit(). (Ivan Shalganov, Andy Skelton) 36 | - Added config.w32. (bruno at chalopin dot fr) 37 | - Fixed windows compilation with libevent 2.x. (Anatol Belski) 38 | - Fixed bug #61673 (callback function args are wrong for signal handler). 39 | - Fixed bug #61653 (Segfault on event_free()). 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 5.3.0 54 | 6.0.0 55 | 6.0.0 56 | 57 | 58 | 1.4.0b1 59 | 60 | 61 | 62 | libevent 63 | 64 | 65 | 66 | 67 | 68 | 2012-04-02 69 | 70 | 71 | 0.0.5 72 | 0.0.5 73 | 74 | 75 | beta 76 | beta 77 | 78 | PHP 79 | - Fixed build with museum PHP versions. 80 | - Fixed PECL bug #22705 (event_set() resets event base to NULL). 81 | - Changed event_set(), event_buffer_new() and event_buffer_set_fd() to 82 | accept numerical file descriptors. 83 | - Added event_priority_set() (patch by Ruslan Osmanov). 84 | - Fixed build with 5_4. 85 | 86 | 87 | 88 | 2010-06-23 89 | 90 | 91 | 0.0.4 92 | 0.0.4 93 | 94 | 95 | beta 96 | beta 97 | 98 | PHP 99 | - Added signal support to event_set(). 100 | - Added add event_buffer_set_callback(). 101 | - Fixed possible segfault in event_del(). 102 | 103 | 104 | 105 | betabeta 106 | 0.0.30.0.3 107 | 2009-08-29 108 | - Added support for sockets created with socket_create() (requires PHP 5.3.1+). 109 | 110 | 111 | 112 | betabeta 113 | 0.0.20.0.2 114 | 2009-08-29 115 | Initial release (after a long testing period). 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /libevent.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2008 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: Antony Dovgal | 16 | | Arnaud Le Blanc | 17 | +----------------------------------------------------------------------+ 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifdef HAVE_CONFIG_H 23 | #include "config.h" 24 | #endif 25 | 26 | #include "php.h" 27 | #include "php_ini.h" 28 | #include "ext/standard/info.h" 29 | #include "php_streams.h" 30 | #include "php_network.h" 31 | #include "php_libevent.h" 32 | 33 | #include 34 | 35 | #if PHP_VERSION_ID >= 50301 && (HAVE_SOCKETS || defined(COMPILE_DL_SOCKETS)) 36 | # include "ext/sockets/php_sockets.h" 37 | # define LIBEVENT_SOCKETS_SUPPORT 38 | #endif 39 | 40 | #ifndef ZEND_FETCH_RESOURCE_NO_RETURN 41 | # define ZEND_FETCH_RESOURCE_NO_RETURN(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type) \ 42 | (rsrc = (rsrc_type) zend_fetch_resource(passed_id TSRMLS_CC, default_id, resource_type_name, NULL, 1, resource_type)) 43 | #endif 44 | 45 | #ifdef PHP_WIN32 46 | /* XXX compiling with 2.x on Windows. Luckily the ext code works thanks to the 47 | compat exports from the libevent. However it might need to be adapted to the 48 | never version, so this ifdefs would go away. */ 49 | # include 50 | # include 51 | # include 52 | # include 53 | # include 54 | #else 55 | # include 56 | #endif 57 | 58 | #if PHP_MAJOR_VERSION < 5 59 | # ifdef PHP_WIN32 60 | typedef SOCKET php_socket_t; 61 | # else 62 | typedef int php_socket_t; 63 | # endif 64 | 65 | # ifdef ZTS 66 | # define TSRMLS_FETCH_FROM_CTX(ctx) void ***tsrm_ls = (void ***) ctx 67 | # define TSRMLS_SET_CTX(ctx) ctx = (void ***) tsrm_ls 68 | # else 69 | # define TSRMLS_FETCH_FROM_CTX(ctx) 70 | # define TSRMLS_SET_CTX(ctx) 71 | # endif 72 | 73 | # ifndef Z_ADDREF_P 74 | # define Z_ADDREF_P(x) (x)->refcount++ 75 | # endif 76 | #endif 77 | 78 | static int le_event_base; 79 | static int le_event; 80 | static int le_bufferevent; 81 | 82 | #ifdef COMPILE_DL_LIBEVENT 83 | ZEND_GET_MODULE(libevent) 84 | #endif 85 | 86 | typedef struct _php_event_base_t { /* {{{ */ 87 | struct event_base *base; 88 | int rsrc_id; 89 | zend_uint events; 90 | } php_event_base_t; 91 | /* }}} */ 92 | 93 | typedef struct _php_event_callback_t { /* {{{ */ 94 | zval *func; 95 | zval *arg; 96 | } php_event_callback_t; 97 | /* }}} */ 98 | 99 | typedef struct _php_event_t { /* {{{ */ 100 | struct event *event; 101 | int rsrc_id; 102 | int stream_id; 103 | php_event_base_t *base; 104 | php_event_callback_t *callback; 105 | #ifdef ZTS 106 | void ***thread_ctx; 107 | #endif 108 | int in_free; 109 | } php_event_t; 110 | /* }}} */ 111 | 112 | typedef struct _php_bufferevent_t { /* {{{ */ 113 | struct bufferevent *bevent; 114 | int rsrc_id; 115 | php_event_base_t *base; 116 | zval *readcb; 117 | zval *writecb; 118 | zval *errorcb; 119 | zval *arg; 120 | #ifdef ZTS 121 | void ***thread_ctx; 122 | #endif 123 | } php_bufferevent_t; 124 | /* }}} */ 125 | 126 | #define ZVAL_TO_BASE(zval, base) \ 127 | ZEND_FETCH_RESOURCE(base, php_event_base_t *, &zval, -1, "event base", le_event_base) 128 | 129 | #define ZVAL_TO_EVENT(zval, event) \ 130 | ZEND_FETCH_RESOURCE(event, php_event_t *, &zval, -1, "event", le_event) 131 | 132 | #define ZVAL_TO_BEVENT(zval, bevent) \ 133 | ZEND_FETCH_RESOURCE(bevent, php_bufferevent_t *, &zval, -1, "buffer event", le_bufferevent) 134 | 135 | /* {{{ internal funcs */ 136 | 137 | static inline void _php_event_callback_free(php_event_callback_t *callback) /* {{{ */ 138 | { 139 | if (!callback) { 140 | return; 141 | } 142 | 143 | zval_ptr_dtor(&callback->func); 144 | if (callback->arg) { 145 | zval_ptr_dtor(&callback->arg); 146 | } 147 | efree(callback); 148 | } 149 | /* }}} */ 150 | 151 | static void _php_event_base_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */ 152 | { 153 | php_event_base_t *base = (php_event_base_t*)rsrc->ptr; 154 | 155 | event_base_free(base->base); 156 | efree(base); 157 | } 158 | /* }}} */ 159 | 160 | static void _php_event_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */ 161 | { 162 | php_event_t *event = (php_event_t*)rsrc->ptr; 163 | int base_id = -1; 164 | 165 | if (event->in_free) { 166 | return; 167 | } 168 | 169 | event->in_free = 1; 170 | 171 | if (event->base) { 172 | base_id = event->base->rsrc_id; 173 | --event->base->events; 174 | } 175 | if (event->stream_id >= 0) { 176 | zend_list_delete(event->stream_id); 177 | } 178 | event_del(event->event); 179 | 180 | _php_event_callback_free(event->callback); 181 | efree(event->event); 182 | efree(event); 183 | 184 | if (base_id >= 0) { 185 | zend_list_delete(base_id); 186 | } 187 | } 188 | /* }}} */ 189 | 190 | static void _php_bufferevent_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */ 191 | { 192 | php_bufferevent_t *bevent = (php_bufferevent_t*)rsrc->ptr; 193 | int base_id = -1; 194 | 195 | if (bevent->base) { 196 | base_id = bevent->base->rsrc_id; 197 | --bevent->base->events; 198 | } 199 | if (bevent->readcb) { 200 | zval_ptr_dtor(&(bevent->readcb)); 201 | } 202 | if (bevent->writecb) { 203 | zval_ptr_dtor(&(bevent->writecb)); 204 | } 205 | if (bevent->errorcb) { 206 | zval_ptr_dtor(&(bevent->errorcb)); 207 | } 208 | if (bevent->arg) { 209 | zval_ptr_dtor(&(bevent->arg)); 210 | } 211 | 212 | bufferevent_free(bevent->bevent); 213 | efree(bevent); 214 | 215 | if (base_id >= 0) { 216 | zend_list_delete(base_id); 217 | } 218 | } 219 | /* }}} */ 220 | 221 | static void _php_event_callback(int fd, short events, void *arg) /* {{{ */ 222 | { 223 | zval *args[3]; 224 | php_event_t *event = (php_event_t *)arg; 225 | php_event_callback_t *callback; 226 | zval retval; 227 | TSRMLS_FETCH_FROM_CTX(event ? event->thread_ctx : NULL); 228 | 229 | if (!event || !event->callback || !event->base) { 230 | return; 231 | } 232 | 233 | callback = event->callback; 234 | 235 | MAKE_STD_ZVAL(args[0]); 236 | if (event->stream_id >= 0) { 237 | ZVAL_RESOURCE(args[0], event->stream_id); 238 | zend_list_addref(event->stream_id); 239 | } else if (events & EV_SIGNAL) { 240 | ZVAL_LONG(args[0], fd); 241 | } else { 242 | ZVAL_NULL(args[0]); 243 | } 244 | 245 | MAKE_STD_ZVAL(args[1]); 246 | ZVAL_LONG(args[1], events); 247 | 248 | args[2] = callback->arg; 249 | Z_ADDREF_P(callback->arg); 250 | 251 | if (call_user_function(EG(function_table), NULL, callback->func, &retval, 3, args TSRMLS_CC) == SUCCESS) { 252 | zval_dtor(&retval); 253 | } 254 | 255 | zval_ptr_dtor(&(args[0])); 256 | zval_ptr_dtor(&(args[1])); 257 | zval_ptr_dtor(&(args[2])); 258 | 259 | } 260 | /* }}} */ 261 | 262 | static void _php_bufferevent_readcb(struct bufferevent *be, void *arg) /* {{{ */ 263 | { 264 | zval *args[2]; 265 | zval retval; 266 | php_bufferevent_t *bevent = (php_bufferevent_t *)arg; 267 | TSRMLS_FETCH_FROM_CTX(bevent ? bevent->thread_ctx : NULL); 268 | 269 | if (!bevent || !bevent->base || !bevent->readcb) { 270 | return; 271 | } 272 | 273 | MAKE_STD_ZVAL(args[0]); 274 | ZVAL_RESOURCE(args[0], bevent->rsrc_id); 275 | zend_list_addref(bevent->rsrc_id); /* we do refcount-- later in zval_ptr_dtor */ 276 | 277 | args[1] = bevent->arg; 278 | Z_ADDREF_P(args[1]); 279 | 280 | if (call_user_function(EG(function_table), NULL, bevent->readcb, &retval, 2, args TSRMLS_CC) == SUCCESS) { 281 | zval_dtor(&retval); 282 | } 283 | 284 | zval_ptr_dtor(&(args[0])); 285 | zval_ptr_dtor(&(args[1])); 286 | 287 | } 288 | /* }}} */ 289 | 290 | static void _php_bufferevent_writecb(struct bufferevent *be, void *arg) /* {{{ */ 291 | { 292 | zval *args[2]; 293 | zval retval; 294 | php_bufferevent_t *bevent = (php_bufferevent_t *)arg; 295 | TSRMLS_FETCH_FROM_CTX(bevent ? bevent->thread_ctx : NULL); 296 | 297 | if (!bevent || !bevent->base || !bevent->writecb) { 298 | return; 299 | } 300 | 301 | MAKE_STD_ZVAL(args[0]); 302 | ZVAL_RESOURCE(args[0], bevent->rsrc_id); 303 | zend_list_addref(bevent->rsrc_id); /* we do refcount-- later in zval_ptr_dtor */ 304 | 305 | args[1] = bevent->arg; 306 | Z_ADDREF_P(args[1]); 307 | 308 | if (call_user_function(EG(function_table), NULL, bevent->writecb, &retval, 2, args TSRMLS_CC) == SUCCESS) { 309 | zval_dtor(&retval); 310 | } 311 | 312 | zval_ptr_dtor(&(args[0])); 313 | zval_ptr_dtor(&(args[1])); 314 | 315 | } 316 | /* }}} */ 317 | 318 | static void _php_bufferevent_errorcb(struct bufferevent *be, short what, void *arg) /* {{{ */ 319 | { 320 | zval *args[3]; 321 | zval retval; 322 | php_bufferevent_t *bevent = (php_bufferevent_t *)arg; 323 | TSRMLS_FETCH_FROM_CTX(bevent ? bevent->thread_ctx : NULL); 324 | 325 | if (!bevent || !bevent->base || !bevent->errorcb) { 326 | return; 327 | } 328 | 329 | MAKE_STD_ZVAL(args[0]); 330 | ZVAL_RESOURCE(args[0], bevent->rsrc_id); 331 | zend_list_addref(bevent->rsrc_id); /* we do refcount-- later in zval_ptr_dtor */ 332 | 333 | MAKE_STD_ZVAL(args[1]); 334 | ZVAL_LONG(args[1], what); 335 | 336 | args[2] = bevent->arg; 337 | Z_ADDREF_P(args[2]); 338 | 339 | if (call_user_function(EG(function_table), NULL, bevent->errorcb, &retval, 3, args TSRMLS_CC) == SUCCESS) { 340 | zval_dtor(&retval); 341 | } 342 | 343 | zval_ptr_dtor(&(args[0])); 344 | zval_ptr_dtor(&(args[1])); 345 | zval_ptr_dtor(&(args[2])); 346 | 347 | } 348 | /* }}} */ 349 | 350 | /* }}} */ 351 | 352 | 353 | /* {{{ proto resource event_base_new() 354 | */ 355 | static PHP_FUNCTION(event_base_new) 356 | { 357 | php_event_base_t *base; 358 | 359 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") != SUCCESS) { 360 | return; 361 | } 362 | 363 | base = emalloc(sizeof(php_event_base_t)); 364 | base->base = event_base_new(); 365 | if (!base->base) { 366 | efree(base); 367 | RETURN_FALSE; 368 | } 369 | 370 | base->events = 0; 371 | 372 | #if PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 4 373 | base->rsrc_id = zend_list_insert(base, le_event_base TSRMLS_CC); 374 | #else 375 | base->rsrc_id = zend_list_insert(base, le_event_base); 376 | #endif 377 | RETURN_RESOURCE(base->rsrc_id); 378 | } 379 | /* }}} */ 380 | 381 | /* {{{ proto bool event_base_reinit() 382 | */ 383 | static PHP_FUNCTION(event_base_reinit) { 384 | zval *zbase; 385 | php_event_base_t *base; 386 | int r = 0; 387 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zbase) != SUCCESS) { 388 | return; 389 | } 390 | 391 | ZVAL_TO_BASE(zbase, base); 392 | r = event_reinit(base->base); 393 | if (r == -1) { 394 | RETURN_FALSE 395 | } else { 396 | RETURN_TRUE; 397 | } 398 | } 399 | /* }}} */ 400 | 401 | /* {{{ proto void event_base_free(resource base) 402 | */ 403 | static PHP_FUNCTION(event_base_free) 404 | { 405 | zval *zbase; 406 | php_event_base_t *base; 407 | 408 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zbase) != SUCCESS) { 409 | return; 410 | } 411 | 412 | ZVAL_TO_BASE(zbase, base); 413 | 414 | if (base->events > 0) { 415 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "base has events attached to it and cannot be freed"); 416 | RETURN_FALSE; 417 | } 418 | 419 | zend_list_delete(base->rsrc_id); 420 | } 421 | /* }}} */ 422 | 423 | /* {{{ proto int event_base_loop(resource base[, int flags]) 424 | */ 425 | static PHP_FUNCTION(event_base_loop) 426 | { 427 | zval *zbase; 428 | php_event_base_t *base; 429 | long flags = 0; 430 | int ret; 431 | 432 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zbase, &flags) != SUCCESS) { 433 | return; 434 | } 435 | 436 | ZVAL_TO_BASE(zbase, base); 437 | zend_list_addref(base->rsrc_id); /* make sure the base cannot be destroyed during the loop */ 438 | ret = event_base_loop(base->base, flags); 439 | zend_list_delete(base->rsrc_id); 440 | 441 | RETURN_LONG(ret); 442 | } 443 | /* }}} */ 444 | 445 | /* {{{ proto bool event_base_loopbreak(resource base) 446 | */ 447 | static PHP_FUNCTION(event_base_loopbreak) 448 | { 449 | zval *zbase; 450 | php_event_base_t *base; 451 | int ret; 452 | 453 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zbase) != SUCCESS) { 454 | return; 455 | } 456 | 457 | ZVAL_TO_BASE(zbase, base); 458 | ret = event_base_loopbreak(base->base); 459 | if (ret == 0) { 460 | RETURN_TRUE; 461 | } 462 | RETURN_FALSE; 463 | } 464 | /* }}} */ 465 | 466 | /* {{{ proto bool event_base_loopexit(resource base[, int timeout]) 467 | */ 468 | static PHP_FUNCTION(event_base_loopexit) 469 | { 470 | zval *zbase; 471 | php_event_base_t *base; 472 | int ret; 473 | long timeout = -1; 474 | 475 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zbase, &timeout) != SUCCESS) { 476 | return; 477 | } 478 | 479 | ZVAL_TO_BASE(zbase, base); 480 | 481 | if (timeout < 0) { 482 | ret = event_base_loopexit(base->base, NULL); 483 | } else { 484 | struct timeval time; 485 | 486 | time.tv_usec = timeout % 1000000; 487 | time.tv_sec = timeout / 1000000; 488 | ret = event_base_loopexit(base->base, &time); 489 | } 490 | 491 | if (ret == 0) { 492 | RETURN_TRUE; 493 | } 494 | RETURN_FALSE; 495 | } 496 | /* }}} */ 497 | 498 | /* {{{ proto bool event_base_set(resource event, resource base) 499 | */ 500 | static PHP_FUNCTION(event_base_set) 501 | { 502 | zval *zbase, *zevent; 503 | php_event_base_t *base, *old_base; 504 | php_event_t *event; 505 | int ret; 506 | 507 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &zevent, &zbase) != SUCCESS) { 508 | return; 509 | } 510 | 511 | ZVAL_TO_BASE(zbase, base); 512 | ZVAL_TO_EVENT(zevent, event); 513 | 514 | old_base = event->base; 515 | ret = event_base_set(base->base, event->event); 516 | 517 | if (ret == 0) { 518 | if (base != old_base) { 519 | /* make sure the base is destroyed after the event */ 520 | zend_list_addref(base->rsrc_id); 521 | ++base->events; 522 | } 523 | 524 | if (old_base && base != old_base) { 525 | --old_base->events; 526 | zend_list_delete(old_base->rsrc_id); 527 | } 528 | 529 | event->base = base; 530 | RETURN_TRUE; 531 | } 532 | RETURN_FALSE; 533 | } 534 | /* }}} */ 535 | 536 | /* {{{ proto bool event_base_priority_init(resource base, int npriorities) 537 | */ 538 | static PHP_FUNCTION(event_base_priority_init) 539 | { 540 | zval *zbase; 541 | php_event_base_t *base; 542 | long npriorities; 543 | int ret; 544 | 545 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zbase, &npriorities) != SUCCESS) { 546 | return; 547 | } 548 | 549 | ZVAL_TO_BASE(zbase, base); 550 | 551 | if (npriorities < 0) { 552 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "npriorities cannot be less than zero"); 553 | RETURN_FALSE; 554 | } 555 | 556 | ret = event_base_priority_init(base->base, npriorities); 557 | if (ret == 0) { 558 | RETURN_TRUE; 559 | } 560 | RETURN_FALSE; 561 | } 562 | /* }}} */ 563 | 564 | 565 | /* {{{ proto resource event_new() 566 | */ 567 | static PHP_FUNCTION(event_new) 568 | { 569 | php_event_t *event; 570 | 571 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") != SUCCESS) { 572 | return; 573 | } 574 | 575 | event = emalloc(sizeof(php_event_t)); 576 | event->event = ecalloc(1, sizeof(struct event)); 577 | 578 | event->stream_id = -1; 579 | event->callback = NULL; 580 | event->base = NULL; 581 | event->in_free = 0; 582 | TSRMLS_SET_CTX(event->thread_ctx); 583 | 584 | #if PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 4 585 | event->rsrc_id = zend_list_insert(event, le_event TSRMLS_CC); 586 | #else 587 | event->rsrc_id = zend_list_insert(event, le_event); 588 | #endif 589 | RETURN_RESOURCE(event->rsrc_id); 590 | } 591 | /* }}} */ 592 | 593 | /* {{{ proto void event_free(resource event) 594 | */ 595 | static PHP_FUNCTION(event_free) 596 | { 597 | zval *zevent; 598 | php_event_t *event; 599 | 600 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zevent) != SUCCESS) { 601 | return; 602 | } 603 | 604 | ZVAL_TO_EVENT(zevent, event); 605 | zend_list_delete(event->rsrc_id); 606 | } 607 | /* }}} */ 608 | 609 | /* {{{ proto bool event_add(resource event[, int timeout]) 610 | */ 611 | static PHP_FUNCTION(event_add) 612 | { 613 | zval *zevent; 614 | php_event_t *event; 615 | int ret; 616 | long timeout = -1; 617 | 618 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zevent, &timeout) != SUCCESS) { 619 | return; 620 | } 621 | 622 | ZVAL_TO_EVENT(zevent, event); 623 | 624 | if (!event->base) { 625 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to add event without an event base"); 626 | RETURN_FALSE; 627 | } 628 | 629 | if (timeout < 0) { 630 | ret = event_add(event->event, NULL); 631 | } else { 632 | struct timeval time; 633 | 634 | time.tv_usec = timeout % 1000000; 635 | time.tv_sec = timeout / 1000000; 636 | ret = event_add(event->event, &time); 637 | } 638 | 639 | if (ret != 0) { 640 | RETURN_FALSE; 641 | } 642 | 643 | RETURN_TRUE; 644 | } 645 | /* }}} */ 646 | 647 | /* {{{ proto bool event_set(resource event, mixed fd, int events, mixed callback[, mixed arg]) 648 | */ 649 | static PHP_FUNCTION(event_set) 650 | { 651 | zval *zevent, **fd, *zcallback, *zarg = NULL; 652 | php_event_t *event; 653 | long events; 654 | php_event_callback_t *callback, *old_callback; 655 | char *func_name; 656 | php_stream *stream; 657 | php_socket_t file_desc; 658 | #ifdef LIBEVENT_SOCKETS_SUPPORT 659 | php_socket *php_sock; 660 | #endif 661 | int ret; 662 | 663 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZlz|z", &zevent, &fd, &events, &zcallback, &zarg) != SUCCESS) { 664 | return; 665 | } 666 | 667 | ZVAL_TO_EVENT(zevent, event); 668 | 669 | if (events & EV_SIGNAL) { 670 | /* signal support */ 671 | convert_to_long_ex(fd); 672 | file_desc = Z_LVAL_PP(fd); 673 | if (file_desc < 0 || file_desc >= NSIG) { 674 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid signal passed"); 675 | RETURN_FALSE; 676 | } 677 | } else { 678 | if (Z_TYPE_PP(fd) == IS_RESOURCE) { 679 | if (ZEND_FETCH_RESOURCE2_NO_RETURN(stream, php_stream *, fd, -1, NULL, php_file_le_stream(), php_file_le_pstream())) { 680 | if (php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&file_desc, 1) != SUCCESS || file_desc < 0) { 681 | RETURN_FALSE; 682 | } 683 | } else { 684 | #ifdef LIBEVENT_SOCKETS_SUPPORT 685 | if (ZEND_FETCH_RESOURCE_NO_RETURN(php_sock, php_socket *, fd, -1, NULL, php_sockets_le_socket())) { 686 | file_desc = php_sock->bsd_socket; 687 | } else { 688 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "fd argument must be either valid PHP stream or valid PHP socket resource"); 689 | RETURN_FALSE; 690 | } 691 | #else 692 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "fd argument must be valid PHP stream resource"); 693 | RETURN_FALSE; 694 | #endif 695 | } 696 | } else if (Z_TYPE_PP(fd) == IS_LONG) { 697 | file_desc = Z_LVAL_PP(fd); 698 | if (file_desc < 0) { 699 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid file descriptor passed"); 700 | RETURN_FALSE; 701 | } 702 | } else { 703 | #ifdef LIBEVENT_SOCKETS_SUPPORT 704 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "fd argument must be valid PHP stream or socket resource or a file descriptor of type long"); 705 | #else 706 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "fd argument must be valid PHP stream resource or a file descriptor of type long"); 707 | #endif 708 | RETURN_FALSE; 709 | } 710 | } 711 | 712 | if (!zend_is_callable(zcallback, 0, &func_name TSRMLS_CC)) { 713 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid callback", func_name); 714 | efree(func_name); 715 | RETURN_FALSE; 716 | } 717 | efree(func_name); 718 | 719 | zval_add_ref(&zcallback); 720 | if (zarg) { 721 | zval_add_ref(&zarg); 722 | } else { 723 | ALLOC_INIT_ZVAL(zarg); 724 | } 725 | 726 | callback = emalloc(sizeof(php_event_callback_t)); 727 | callback->func = zcallback; 728 | callback->arg = zarg; 729 | 730 | old_callback = event->callback; 731 | event->callback = callback; 732 | if (events & EV_SIGNAL) { 733 | event->stream_id = -1; 734 | } else { 735 | zend_list_addref(Z_LVAL_PP(fd)); 736 | event->stream_id = Z_LVAL_PP(fd); 737 | } 738 | 739 | event_set(event->event, (int)file_desc, (short)events, _php_event_callback, event); 740 | 741 | if (old_callback) { 742 | _php_event_callback_free(old_callback); 743 | } 744 | 745 | if (event->base) { 746 | ret = event_base_set(event->base->base, event->event); 747 | if (ret != 0) { 748 | RETURN_FALSE; 749 | } 750 | } 751 | RETURN_TRUE; 752 | } 753 | /* }}} */ 754 | 755 | /* {{{ proto bool event_del(resource event) 756 | */ 757 | static PHP_FUNCTION(event_del) 758 | { 759 | zval *zevent; 760 | php_event_t *event; 761 | 762 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zevent) != SUCCESS) { 763 | return; 764 | } 765 | 766 | ZVAL_TO_EVENT(zevent, event); 767 | 768 | if (!event->base) { 769 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to delete event without an event base"); 770 | RETURN_FALSE; 771 | } 772 | 773 | if (event_del(event->event) == 0) { 774 | RETURN_TRUE; 775 | } 776 | RETURN_FALSE; 777 | } 778 | /* }}} */ 779 | 780 | /* {{{ proto bool event_priority_set(resource event, int priority) 781 | */ 782 | static PHP_FUNCTION(event_priority_set) 783 | { 784 | zval *zevent; 785 | php_event_t *event; 786 | long priority; 787 | int ret; 788 | 789 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zevent, &priority) != SUCCESS) { 790 | return; 791 | } 792 | 793 | ZVAL_TO_EVENT(zevent, event); 794 | 795 | if (!event->base) { 796 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to set event priority without an event base"); 797 | RETURN_FALSE; 798 | } 799 | 800 | ret = event_priority_set(event->event, priority); 801 | 802 | if (ret == 0) { 803 | RETURN_TRUE; 804 | } 805 | RETURN_FALSE; 806 | } 807 | /* }}} */ 808 | 809 | /* {{{ proto bool event_timer_set(resource event, mixed callback[, mixed arg]) 810 | */ 811 | static PHP_FUNCTION(event_timer_set) 812 | { 813 | zval *zevent, *zcallback, *zarg = NULL; 814 | php_event_t *event; 815 | php_event_callback_t *callback, *old_callback; 816 | char *func_name; 817 | 818 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|z", &zevent, &zcallback, &zarg) != SUCCESS) { 819 | return; 820 | } 821 | 822 | ZVAL_TO_EVENT(zevent, event); 823 | 824 | if (!zend_is_callable(zcallback, 0, &func_name TSRMLS_CC)) { 825 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid callback", func_name); 826 | efree(func_name); 827 | RETURN_FALSE; 828 | } 829 | efree(func_name); 830 | 831 | zval_add_ref(&zcallback); 832 | if (zarg) { 833 | zval_add_ref(&zarg); 834 | } else { 835 | ALLOC_INIT_ZVAL(zarg); 836 | } 837 | 838 | callback = emalloc(sizeof(php_event_callback_t)); 839 | callback->func = zcallback; 840 | callback->arg = zarg; 841 | 842 | old_callback = event->callback; 843 | event->callback = callback; 844 | if (event->stream_id >= 0) { 845 | zend_list_delete(event->stream_id); 846 | } 847 | event->stream_id = -1; 848 | 849 | event_set(event->event, -1, 0, _php_event_callback, event); 850 | 851 | if (old_callback) { 852 | _php_event_callback_free(old_callback); 853 | } 854 | RETURN_TRUE; 855 | } 856 | /* }}} */ 857 | 858 | /* {{{ proto bool event_timer_pending(resource event[, int timeout]) 859 | */ 860 | static PHP_FUNCTION(event_timer_pending) 861 | { 862 | zval *zevent; 863 | php_event_t *event; 864 | int ret; 865 | long timeout = -1; 866 | 867 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zevent, &timeout) != SUCCESS) { 868 | return; 869 | } 870 | 871 | ZVAL_TO_EVENT(zevent, event); 872 | 873 | if (timeout < 0) { 874 | ret = event_pending(event->event, EV_TIMEOUT, NULL); 875 | } else { 876 | struct timeval time; 877 | 878 | time.tv_usec = timeout % 1000000; 879 | time.tv_sec = timeout / 1000000; 880 | ret = event_pending(event->event, EV_TIMEOUT, &time); 881 | } 882 | 883 | if (ret != 0) { 884 | RETURN_FALSE; 885 | } 886 | RETURN_TRUE; 887 | } 888 | /* }}} */ 889 | 890 | 891 | 892 | /* {{{ proto resource event_buffer_new(mixed fd, mixed readcb, mixed writecb, mixed errorcb[, mixed arg]) 893 | */ 894 | static PHP_FUNCTION(event_buffer_new) 895 | { 896 | php_bufferevent_t *bevent; 897 | php_stream *stream; 898 | zval *zfd, *zreadcb, *zwritecb, *zerrorcb, *zarg = NULL; 899 | php_socket_t fd; 900 | char *func_name; 901 | #ifdef LIBEVENT_SOCKETS_SUPPORT 902 | php_socket *php_sock; 903 | #endif 904 | 905 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzz|z", &zfd, &zreadcb, &zwritecb, &zerrorcb, &zarg) != SUCCESS) { 906 | return; 907 | } 908 | 909 | if (Z_TYPE_P(zfd) == IS_RESOURCE) { 910 | if (ZEND_FETCH_RESOURCE2_NO_RETURN(stream, php_stream *, &zfd, -1, NULL, php_file_le_stream(), php_file_le_pstream())) { 911 | if (php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&fd, 1) != SUCCESS || fd < 0) { 912 | RETURN_FALSE; 913 | } 914 | } else { 915 | #ifdef LIBEVENT_SOCKETS_SUPPORT 916 | if (ZEND_FETCH_RESOURCE_NO_RETURN(php_sock, php_socket *, &zfd, -1, NULL, php_sockets_le_socket())) { 917 | fd = php_sock->bsd_socket; 918 | } else { 919 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "fd argument must be valid PHP stream or socket resource or a file descriptor of type long"); 920 | RETURN_FALSE; 921 | } 922 | #else 923 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "fd argument must be valid PHP stream resource or a file descriptor of type long"); 924 | RETURN_FALSE; 925 | #endif 926 | } 927 | } else if (Z_TYPE_P(zfd) == IS_LONG) { 928 | fd = Z_LVAL_P(zfd); 929 | } else { 930 | #ifdef LIBEVENT_SOCKETS_SUPPORT 931 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "fd argument must be valid PHP stream or socket resource or a file descriptor of type long"); 932 | #else 933 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "fd argument must be valid PHP stream resource or a file descriptor of type long"); 934 | #endif 935 | RETURN_FALSE; 936 | } 937 | 938 | if (Z_TYPE_P(zreadcb) != IS_NULL) { 939 | if (!zend_is_callable(zreadcb, 0, &func_name TSRMLS_CC)) { 940 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid read callback", func_name); 941 | efree(func_name); 942 | RETURN_FALSE; 943 | } 944 | efree(func_name); 945 | } else { 946 | zreadcb = NULL; 947 | } 948 | 949 | if (Z_TYPE_P(zwritecb) != IS_NULL) { 950 | if (!zend_is_callable(zwritecb, 0, &func_name TSRMLS_CC)) { 951 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid write callback", func_name); 952 | efree(func_name); 953 | RETURN_FALSE; 954 | } 955 | efree(func_name); 956 | } else { 957 | zwritecb = NULL; 958 | } 959 | 960 | if (!zend_is_callable(zerrorcb, 0, &func_name TSRMLS_CC)) { 961 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid error callback", func_name); 962 | efree(func_name); 963 | RETURN_FALSE; 964 | } 965 | efree(func_name); 966 | 967 | bevent = emalloc(sizeof(php_bufferevent_t)); 968 | bevent->bevent = bufferevent_new(fd, _php_bufferevent_readcb, _php_bufferevent_writecb, _php_bufferevent_errorcb, bevent); 969 | 970 | bevent->base = NULL; 971 | 972 | if (zreadcb) { 973 | zval_add_ref(&zreadcb); 974 | } 975 | bevent->readcb = zreadcb; 976 | 977 | if (zwritecb) { 978 | zval_add_ref(&zwritecb); 979 | } 980 | bevent->writecb = zwritecb; 981 | 982 | zval_add_ref(&zerrorcb); 983 | bevent->errorcb = zerrorcb; 984 | 985 | if (zarg) { 986 | zval_add_ref(&zarg); 987 | bevent->arg = zarg; 988 | } else { 989 | ALLOC_INIT_ZVAL(bevent->arg); 990 | } 991 | 992 | TSRMLS_SET_CTX(bevent->thread_ctx); 993 | 994 | #if PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 4 995 | bevent->rsrc_id = zend_list_insert(bevent, le_bufferevent TSRMLS_CC); 996 | #else 997 | bevent->rsrc_id = zend_list_insert(bevent, le_bufferevent); 998 | #endif 999 | RETURN_RESOURCE(bevent->rsrc_id); 1000 | } 1001 | /* }}} */ 1002 | 1003 | /* {{{ proto void event_buffer_free(resource bevent) 1004 | */ 1005 | static PHP_FUNCTION(event_buffer_free) 1006 | { 1007 | zval *zbevent; 1008 | php_bufferevent_t *bevent; 1009 | 1010 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zbevent) != SUCCESS) { 1011 | return; 1012 | } 1013 | 1014 | ZVAL_TO_BEVENT(zbevent, bevent); 1015 | zend_list_delete(bevent->rsrc_id); 1016 | } 1017 | /* }}} */ 1018 | 1019 | /* {{{ proto bool event_buffer_base_set(resource bevent, resource base) 1020 | */ 1021 | static PHP_FUNCTION(event_buffer_base_set) 1022 | { 1023 | zval *zbase, *zbevent; 1024 | php_event_base_t *base, *old_base; 1025 | php_bufferevent_t *bevent; 1026 | int ret; 1027 | 1028 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &zbevent, &zbase) != SUCCESS) { 1029 | return; 1030 | } 1031 | 1032 | ZVAL_TO_BASE(zbase, base); 1033 | ZVAL_TO_BEVENT(zbevent, bevent); 1034 | 1035 | old_base = bevent->base; 1036 | ret = bufferevent_base_set(base->base, bevent->bevent); 1037 | 1038 | if (ret == 0) { 1039 | if (base != old_base) { 1040 | /* make sure the base is destroyed after the event */ 1041 | zend_list_addref(base->rsrc_id); 1042 | ++base->events; 1043 | } 1044 | 1045 | if (old_base) { 1046 | --old_base->events; 1047 | zend_list_delete(old_base->rsrc_id); 1048 | } 1049 | 1050 | bevent->base = base; 1051 | RETURN_TRUE; 1052 | } 1053 | RETURN_FALSE; 1054 | } 1055 | /* }}} */ 1056 | 1057 | /* {{{ proto bool event_buffer_priority_set(resource bevent, int priority) 1058 | */ 1059 | static PHP_FUNCTION(event_buffer_priority_set) 1060 | { 1061 | zval *zbevent; 1062 | php_bufferevent_t *bevent; 1063 | long priority; 1064 | int ret; 1065 | 1066 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zbevent, &priority) != SUCCESS) { 1067 | return; 1068 | } 1069 | 1070 | ZVAL_TO_BEVENT(zbevent, bevent); 1071 | 1072 | if (!bevent->base) { 1073 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to set event priority without an event base"); 1074 | RETURN_FALSE; 1075 | } 1076 | 1077 | ret = bufferevent_priority_set(bevent->bevent, priority); 1078 | 1079 | if (ret == 0) { 1080 | RETURN_TRUE; 1081 | } 1082 | RETURN_FALSE; 1083 | } 1084 | /* }}} */ 1085 | 1086 | /* {{{ proto bool event_buffer_write(resource bevent, string data[, int data_size]) 1087 | */ 1088 | static PHP_FUNCTION(event_buffer_write) 1089 | { 1090 | zval *zbevent; 1091 | php_bufferevent_t *bevent; 1092 | char *data; 1093 | int data_len; 1094 | long data_size = -1; 1095 | int ret; 1096 | 1097 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &zbevent, &data, &data_len, &data_size) != SUCCESS) { 1098 | return; 1099 | } 1100 | 1101 | ZVAL_TO_BEVENT(zbevent, bevent); 1102 | 1103 | if (ZEND_NUM_ARGS() < 3 || data_size < 0) { 1104 | data_size = data_len; 1105 | } else if (data_size > data_len) { 1106 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_size out of range"); 1107 | RETURN_FALSE; 1108 | } 1109 | 1110 | ret = bufferevent_write(bevent->bevent, (const void *)data, data_size); 1111 | 1112 | if (ret == 0) { 1113 | RETURN_TRUE; 1114 | } 1115 | RETURN_FALSE; 1116 | } 1117 | /* }}} */ 1118 | 1119 | /* {{{ proto string event_buffer_read(resource bevent, int data_size) 1120 | */ 1121 | static PHP_FUNCTION(event_buffer_read) 1122 | { 1123 | zval *zbevent; 1124 | php_bufferevent_t *bevent; 1125 | char *data; 1126 | long data_size; 1127 | int ret; 1128 | 1129 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zbevent, &data_size) != SUCCESS) { 1130 | return; 1131 | } 1132 | 1133 | ZVAL_TO_BEVENT(zbevent, bevent); 1134 | 1135 | if (data_size == 0) { 1136 | RETURN_EMPTY_STRING(); 1137 | } else if (data_size < 0) { 1138 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_size cannot be less than zero"); 1139 | RETURN_FALSE; 1140 | } 1141 | 1142 | data = safe_emalloc((int)data_size, sizeof(char), 1); 1143 | 1144 | ret = bufferevent_read(bevent->bevent, data, data_size); 1145 | if (ret > 0) { 1146 | if (ret > data_size) { /* paranoia */ 1147 | ret = data_size; 1148 | } 1149 | data[ret] = '\0'; 1150 | RETURN_STRINGL(data, ret, 0); 1151 | } 1152 | efree(data); 1153 | RETURN_EMPTY_STRING(); 1154 | } 1155 | /* }}} */ 1156 | 1157 | /* {{{ proto bool event_buffer_enable(resource bevent, int events) 1158 | */ 1159 | static PHP_FUNCTION(event_buffer_enable) 1160 | { 1161 | zval *zbevent; 1162 | php_bufferevent_t *bevent; 1163 | long events; 1164 | int ret; 1165 | 1166 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zbevent, &events) != SUCCESS) { 1167 | return; 1168 | } 1169 | 1170 | ZVAL_TO_BEVENT(zbevent, bevent); 1171 | 1172 | ret = bufferevent_enable(bevent->bevent, events); 1173 | 1174 | if (ret == 0) { 1175 | RETURN_TRUE; 1176 | } 1177 | RETURN_FALSE; 1178 | } 1179 | /* }}} */ 1180 | 1181 | /* {{{ proto bool event_buffer_disable(resource bevent, int events) 1182 | */ 1183 | static PHP_FUNCTION(event_buffer_disable) 1184 | { 1185 | zval *zbevent; 1186 | php_bufferevent_t *bevent; 1187 | long events; 1188 | int ret; 1189 | 1190 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zbevent, &events) != SUCCESS) { 1191 | return; 1192 | } 1193 | 1194 | ZVAL_TO_BEVENT(zbevent, bevent); 1195 | 1196 | ret = bufferevent_disable(bevent->bevent, events); 1197 | 1198 | if (ret == 0) { 1199 | RETURN_TRUE; 1200 | } 1201 | RETURN_FALSE; 1202 | } 1203 | /* }}} */ 1204 | 1205 | /* {{{ proto void event_buffer_timeout_set(resource bevent, int read_timeout, int write_timeout) 1206 | */ 1207 | static PHP_FUNCTION(event_buffer_timeout_set) 1208 | { 1209 | zval *zbevent; 1210 | php_bufferevent_t *bevent; 1211 | long read_timeout, write_timeout; 1212 | 1213 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &zbevent, &read_timeout, &write_timeout) != SUCCESS) { 1214 | return; 1215 | } 1216 | 1217 | ZVAL_TO_BEVENT(zbevent, bevent); 1218 | bufferevent_settimeout(bevent->bevent, read_timeout, write_timeout); 1219 | } 1220 | /* }}} */ 1221 | 1222 | /* {{{ proto void event_buffer_watermark_set(resource bevent, int events, int lowmark, int highmark) 1223 | */ 1224 | static PHP_FUNCTION(event_buffer_watermark_set) 1225 | { 1226 | zval *zbevent; 1227 | php_bufferevent_t *bevent; 1228 | long events, lowmark, highmark; 1229 | 1230 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &zbevent, &events, &lowmark, &highmark) != SUCCESS) { 1231 | return; 1232 | } 1233 | 1234 | ZVAL_TO_BEVENT(zbevent, bevent); 1235 | bufferevent_setwatermark(bevent->bevent, events, lowmark, highmark); 1236 | } 1237 | /* }}} */ 1238 | 1239 | /* {{{ proto void event_buffer_fd_set(resource bevent, resource fd) 1240 | */ 1241 | static PHP_FUNCTION(event_buffer_fd_set) 1242 | { 1243 | zval *zbevent, *zfd; 1244 | php_stream *stream; 1245 | php_bufferevent_t *bevent; 1246 | php_socket_t fd; 1247 | #ifdef LIBEVENT_SOCKETS_SUPPORT 1248 | php_socket *php_sock; 1249 | #endif 1250 | 1251 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz", &zbevent, &zfd) != SUCCESS) { 1252 | return; 1253 | } 1254 | 1255 | ZVAL_TO_BEVENT(zbevent, bevent); 1256 | 1257 | if (Z_TYPE_P(zfd) == IS_RESOURCE) { 1258 | if (ZEND_FETCH_RESOURCE2_NO_RETURN(stream, php_stream *, &zfd, -1, NULL, php_file_le_stream(), php_file_le_pstream())) { 1259 | if (php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&fd, 1) != SUCCESS || fd < 0) { 1260 | RETURN_FALSE; 1261 | } 1262 | } else { 1263 | #ifdef LIBEVENT_SOCKETS_SUPPORT 1264 | if (ZEND_FETCH_RESOURCE_NO_RETURN(php_sock, php_socket *, &zfd, -1, NULL, php_sockets_le_socket())) { 1265 | fd = php_sock->bsd_socket; 1266 | } else { 1267 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "fd argument must be valid PHP stream or socket resource or a file descriptor of type long"); 1268 | RETURN_FALSE; 1269 | } 1270 | #else 1271 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "fd argument must be valid PHP stream resource or a file descriptor of type long"); 1272 | RETURN_FALSE; 1273 | #endif 1274 | } 1275 | } else if (Z_TYPE_P(zfd) == IS_LONG) { 1276 | fd = Z_LVAL_P(zfd); 1277 | } else { 1278 | #ifdef LIBEVENT_SOCKETS_SUPPORT 1279 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "fd argument must be valid PHP stream or socket resource or a file descriptor of type long"); 1280 | #else 1281 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "fd argument must be valid PHP stream resource or a file descriptor of type long"); 1282 | #endif 1283 | RETURN_FALSE; 1284 | } 1285 | 1286 | bufferevent_setfd(bevent->bevent, fd); 1287 | } 1288 | /* }}} */ 1289 | 1290 | /* {{{ proto resource event_buffer_set_callback(resource bevent, mixed readcb, mixed writecb, mixed errorcb[, mixed arg]) 1291 | */ 1292 | static PHP_FUNCTION(event_buffer_set_callback) 1293 | { 1294 | php_bufferevent_t *bevent; 1295 | zval *zbevent, *zreadcb, *zwritecb, *zerrorcb, *zarg = NULL; 1296 | char *func_name; 1297 | 1298 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rzzz|z", &zbevent, &zreadcb, &zwritecb, &zerrorcb, &zarg) != SUCCESS) { 1299 | return; 1300 | } 1301 | 1302 | ZVAL_TO_BEVENT(zbevent, bevent); 1303 | 1304 | if (Z_TYPE_P(zreadcb) != IS_NULL) { 1305 | if (!zend_is_callable(zreadcb, 0, &func_name TSRMLS_CC)) { 1306 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid read callback", func_name); 1307 | efree(func_name); 1308 | RETURN_FALSE; 1309 | } 1310 | efree(func_name); 1311 | } else { 1312 | zreadcb = NULL; 1313 | } 1314 | 1315 | if (Z_TYPE_P(zwritecb) != IS_NULL) { 1316 | if (!zend_is_callable(zwritecb, 0, &func_name TSRMLS_CC)) { 1317 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid write callback", func_name); 1318 | efree(func_name); 1319 | RETURN_FALSE; 1320 | } 1321 | efree(func_name); 1322 | } else { 1323 | zwritecb = NULL; 1324 | } 1325 | 1326 | if (Z_TYPE_P(zerrorcb) != IS_NULL) { 1327 | if (!zend_is_callable(zerrorcb, 0, &func_name TSRMLS_CC)) { 1328 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid error callback", func_name); 1329 | efree(func_name); 1330 | RETURN_FALSE; 1331 | } 1332 | efree(func_name); 1333 | } else { 1334 | zerrorcb = NULL; 1335 | } 1336 | 1337 | if (zreadcb) { 1338 | zval_add_ref(&zreadcb); 1339 | 1340 | if (bevent->readcb) { 1341 | zval_ptr_dtor(&bevent->readcb); 1342 | } 1343 | bevent->readcb = zreadcb; 1344 | } else { 1345 | if (bevent->readcb) { 1346 | zval_ptr_dtor(&bevent->readcb); 1347 | } 1348 | bevent->readcb = NULL; 1349 | } 1350 | 1351 | if (zwritecb) { 1352 | zval_add_ref(&zwritecb); 1353 | 1354 | if (bevent->writecb) { 1355 | zval_ptr_dtor(&bevent->writecb); 1356 | } 1357 | bevent->writecb = zwritecb; 1358 | } else { 1359 | if (bevent->writecb) { 1360 | zval_ptr_dtor(&bevent->writecb); 1361 | } 1362 | bevent->writecb = NULL; 1363 | } 1364 | 1365 | if (zerrorcb) { 1366 | zval_add_ref(&zerrorcb); 1367 | 1368 | if (bevent->errorcb) { 1369 | zval_ptr_dtor(&bevent->errorcb); 1370 | } 1371 | bevent->errorcb = zerrorcb; 1372 | } 1373 | 1374 | if (zarg) { 1375 | zval_add_ref(&zarg); 1376 | if (bevent->arg) { 1377 | zval_ptr_dtor(&bevent->arg); 1378 | } 1379 | bevent->arg = zarg; 1380 | } 1381 | 1382 | RETURN_TRUE; 1383 | } 1384 | /* }}} */ 1385 | 1386 | 1387 | /* {{{ PHP_MINIT_FUNCTION 1388 | */ 1389 | static PHP_MINIT_FUNCTION(libevent) 1390 | { 1391 | le_event_base = zend_register_list_destructors_ex(_php_event_base_dtor, NULL, "event base", module_number); 1392 | le_event = zend_register_list_destructors_ex(_php_event_dtor, NULL, "event", module_number); 1393 | le_bufferevent = zend_register_list_destructors_ex(_php_bufferevent_dtor, NULL, "buffer event", module_number); 1394 | 1395 | REGISTER_LONG_CONSTANT("EV_TIMEOUT", EV_TIMEOUT, CONST_CS | CONST_PERSISTENT); 1396 | REGISTER_LONG_CONSTANT("EV_READ", EV_READ, CONST_CS | CONST_PERSISTENT); 1397 | REGISTER_LONG_CONSTANT("EV_WRITE", EV_WRITE, CONST_CS | CONST_PERSISTENT); 1398 | REGISTER_LONG_CONSTANT("EV_SIGNAL", EV_SIGNAL, CONST_CS | CONST_PERSISTENT); 1399 | REGISTER_LONG_CONSTANT("EV_PERSIST", EV_PERSIST, CONST_CS | CONST_PERSISTENT); 1400 | REGISTER_LONG_CONSTANT("EVLOOP_NONBLOCK", EVLOOP_NONBLOCK, CONST_CS | CONST_PERSISTENT); 1401 | REGISTER_LONG_CONSTANT("EVLOOP_ONCE", EVLOOP_ONCE, CONST_CS | CONST_PERSISTENT); 1402 | 1403 | REGISTER_LONG_CONSTANT("EVBUFFER_READ", EVBUFFER_READ, CONST_CS | CONST_PERSISTENT); 1404 | REGISTER_LONG_CONSTANT("EVBUFFER_WRITE", EVBUFFER_WRITE, CONST_CS | CONST_PERSISTENT); 1405 | REGISTER_LONG_CONSTANT("EVBUFFER_EOF", EVBUFFER_EOF, CONST_CS | CONST_PERSISTENT); 1406 | REGISTER_LONG_CONSTANT("EVBUFFER_ERROR", EVBUFFER_ERROR, CONST_CS | CONST_PERSISTENT); 1407 | REGISTER_LONG_CONSTANT("EVBUFFER_TIMEOUT", EVBUFFER_TIMEOUT, CONST_CS | CONST_PERSISTENT); 1408 | 1409 | return SUCCESS; 1410 | } 1411 | /* }}} */ 1412 | 1413 | /* {{{ PHP_MINFO_FUNCTION 1414 | */ 1415 | static PHP_MINFO_FUNCTION(libevent) 1416 | { 1417 | char buf[64]; 1418 | 1419 | 1420 | php_info_print_table_start(); 1421 | php_info_print_table_header(2, "libevent support", "enabled"); 1422 | php_info_print_table_row(2, "extension version", PHP_LIBEVENT_VERSION); 1423 | php_info_print_table_row(2, "Revision", "$Revision$"); 1424 | 1425 | snprintf(buf, sizeof(buf) - 1, "%s", event_get_version()); 1426 | php_info_print_table_row(2, "libevent version", buf); 1427 | 1428 | php_info_print_table_end(); 1429 | } 1430 | /* }}} */ 1431 | 1432 | #if PHP_MAJOR_VERSION >= 5 1433 | /* {{{ arginfo */ 1434 | #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3) || PHP_MAJOR_VERSION > 5 1435 | # define EVENT_ARGINFO 1436 | #else 1437 | # define EVENT_ARGINFO static 1438 | #endif 1439 | 1440 | EVENT_ARGINFO 1441 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_base_loop, 0, 0, 1) 1442 | ZEND_ARG_INFO(0, base) 1443 | ZEND_ARG_INFO(0, flags) 1444 | ZEND_END_ARG_INFO() 1445 | 1446 | EVENT_ARGINFO 1447 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_base_loopbreak, 0, 0, 1) 1448 | ZEND_ARG_INFO(0, base) 1449 | ZEND_END_ARG_INFO() 1450 | 1451 | EVENT_ARGINFO 1452 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_base_loopexit, 0, 0, 1) 1453 | ZEND_ARG_INFO(0, base) 1454 | ZEND_ARG_INFO(0, timeout) 1455 | ZEND_END_ARG_INFO() 1456 | 1457 | EVENT_ARGINFO 1458 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_base_set, 0, 0, 2) 1459 | ZEND_ARG_INFO(0, event) 1460 | ZEND_ARG_INFO(0, base) 1461 | ZEND_END_ARG_INFO() 1462 | 1463 | EVENT_ARGINFO 1464 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_base_priority_init, 0, 0, 2) 1465 | ZEND_ARG_INFO(0, base) 1466 | ZEND_ARG_INFO(0, npriorities) 1467 | ZEND_END_ARG_INFO() 1468 | 1469 | EVENT_ARGINFO 1470 | ZEND_BEGIN_ARG_INFO(arginfo_event_new, 0) 1471 | ZEND_END_ARG_INFO() 1472 | 1473 | EVENT_ARGINFO 1474 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_add, 0, 0, 1) 1475 | ZEND_ARG_INFO(0, event) 1476 | ZEND_ARG_INFO(0, timeout) 1477 | ZEND_END_ARG_INFO() 1478 | 1479 | EVENT_ARGINFO 1480 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_set, 0, 0, 4) 1481 | ZEND_ARG_INFO(0, event) 1482 | ZEND_ARG_INFO(0, fd) 1483 | ZEND_ARG_INFO(0, events) 1484 | ZEND_ARG_INFO(0, callback) 1485 | ZEND_ARG_INFO(0, arg) 1486 | ZEND_END_ARG_INFO() 1487 | 1488 | EVENT_ARGINFO 1489 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_del, 0, 0, 1) 1490 | ZEND_ARG_INFO(0, event) 1491 | ZEND_END_ARG_INFO() 1492 | 1493 | EVENT_ARGINFO 1494 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_priority_set, 0, 0, 2) 1495 | ZEND_ARG_INFO(0, event) 1496 | ZEND_ARG_INFO(0, priority) 1497 | ZEND_END_ARG_INFO() 1498 | 1499 | EVENT_ARGINFO 1500 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_new, 0, 0, 4) 1501 | ZEND_ARG_INFO(0, stream) 1502 | ZEND_ARG_INFO(0, readcb) 1503 | ZEND_ARG_INFO(0, writecb) 1504 | ZEND_ARG_INFO(0, errorcb) 1505 | ZEND_ARG_INFO(0, arg) 1506 | ZEND_END_ARG_INFO() 1507 | 1508 | EVENT_ARGINFO 1509 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_free, 0, 0, 1) 1510 | ZEND_ARG_INFO(0, bevent) 1511 | ZEND_END_ARG_INFO() 1512 | 1513 | EVENT_ARGINFO 1514 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_base_set, 0, 0, 2) 1515 | ZEND_ARG_INFO(0, bevent) 1516 | ZEND_ARG_INFO(0, base) 1517 | ZEND_END_ARG_INFO() 1518 | 1519 | EVENT_ARGINFO 1520 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_priority_set, 0, 0, 2) 1521 | ZEND_ARG_INFO(0, bevent) 1522 | ZEND_ARG_INFO(0, priority) 1523 | ZEND_END_ARG_INFO() 1524 | 1525 | EVENT_ARGINFO 1526 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_write, 0, 0, 2) 1527 | ZEND_ARG_INFO(0, bevent) 1528 | ZEND_ARG_INFO(0, data) 1529 | ZEND_ARG_INFO(0, data_size) 1530 | ZEND_END_ARG_INFO() 1531 | 1532 | EVENT_ARGINFO 1533 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_read, 0, 0, 2) 1534 | ZEND_ARG_INFO(0, bevent) 1535 | ZEND_ARG_INFO(0, data_size) 1536 | ZEND_END_ARG_INFO() 1537 | 1538 | EVENT_ARGINFO 1539 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_disable, 0, 0, 2) 1540 | ZEND_ARG_INFO(0, bevent) 1541 | ZEND_ARG_INFO(0, events) 1542 | ZEND_END_ARG_INFO() 1543 | 1544 | EVENT_ARGINFO 1545 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_timeout_set, 0, 0, 3) 1546 | ZEND_ARG_INFO(0, bevent) 1547 | ZEND_ARG_INFO(0, read_timeout) 1548 | ZEND_ARG_INFO(0, write_timeout) 1549 | ZEND_END_ARG_INFO() 1550 | 1551 | EVENT_ARGINFO 1552 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_watermark_set, 0, 0, 4) 1553 | ZEND_ARG_INFO(0, bevent) 1554 | ZEND_ARG_INFO(0, events) 1555 | ZEND_ARG_INFO(0, lowmark) 1556 | ZEND_ARG_INFO(0, highmark) 1557 | ZEND_END_ARG_INFO() 1558 | 1559 | EVENT_ARGINFO 1560 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_fd_set, 0, 0, 2) 1561 | ZEND_ARG_INFO(0, bevent) 1562 | ZEND_ARG_INFO(0, fd) 1563 | ZEND_END_ARG_INFO() 1564 | 1565 | EVENT_ARGINFO 1566 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_buffer_set_callback, 0, 0, 4) 1567 | ZEND_ARG_INFO(0, bevent) 1568 | ZEND_ARG_INFO(0, readcb) 1569 | ZEND_ARG_INFO(0, writecb) 1570 | ZEND_ARG_INFO(0, errorcb) 1571 | ZEND_ARG_INFO(0, arg) 1572 | ZEND_END_ARG_INFO() 1573 | 1574 | EVENT_ARGINFO 1575 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_timer_set, 0, 0, 2) 1576 | ZEND_ARG_INFO(0, event) 1577 | ZEND_ARG_INFO(0, callback) 1578 | ZEND_ARG_INFO(0, arg) 1579 | ZEND_END_ARG_INFO() 1580 | 1581 | EVENT_ARGINFO 1582 | ZEND_BEGIN_ARG_INFO_EX(arginfo_event_timer_pending, 0, 0, 1) 1583 | ZEND_ARG_INFO(0, event) 1584 | ZEND_ARG_INFO(0, timeout) 1585 | ZEND_END_ARG_INFO() 1586 | /* }}} */ 1587 | 1588 | /* {{{ libevent_functions[] 1589 | */ 1590 | #if ZEND_MODULE_API_NO >= 20071006 1591 | const 1592 | #endif 1593 | zend_function_entry libevent_functions[] = { 1594 | PHP_FE(event_base_new, arginfo_event_new) 1595 | PHP_FE(event_base_reinit, arginfo_event_base_loopbreak) 1596 | PHP_FE(event_base_free, arginfo_event_base_loopbreak) 1597 | PHP_FE(event_base_loop, arginfo_event_base_loop) 1598 | PHP_FE(event_base_loopbreak, arginfo_event_base_loopbreak) 1599 | PHP_FE(event_base_loopexit, arginfo_event_base_loopexit) 1600 | PHP_FE(event_base_set, arginfo_event_base_set) 1601 | PHP_FE(event_base_priority_init, arginfo_event_base_priority_init) 1602 | PHP_FE(event_new, arginfo_event_new) 1603 | PHP_FE(event_free, arginfo_event_del) 1604 | PHP_FE(event_add, arginfo_event_add) 1605 | PHP_FE(event_set, arginfo_event_set) 1606 | PHP_FE(event_del, arginfo_event_del) 1607 | PHP_FE(event_priority_set, arginfo_event_priority_set) 1608 | PHP_FE(event_buffer_new, arginfo_event_buffer_new) 1609 | PHP_FE(event_buffer_free, arginfo_event_buffer_free) 1610 | PHP_FE(event_buffer_base_set, arginfo_event_buffer_base_set) 1611 | PHP_FE(event_buffer_priority_set, arginfo_event_buffer_priority_set) 1612 | PHP_FE(event_buffer_write, arginfo_event_buffer_write) 1613 | PHP_FE(event_buffer_read, arginfo_event_buffer_read) 1614 | PHP_FE(event_buffer_enable, arginfo_event_buffer_disable) 1615 | PHP_FE(event_buffer_disable, arginfo_event_buffer_disable) 1616 | PHP_FE(event_buffer_timeout_set, arginfo_event_buffer_timeout_set) 1617 | PHP_FE(event_buffer_watermark_set, arginfo_event_buffer_watermark_set) 1618 | PHP_FE(event_buffer_fd_set, arginfo_event_buffer_fd_set) 1619 | PHP_FE(event_buffer_set_callback, arginfo_event_buffer_set_callback) 1620 | PHP_FALIAS(event_timer_new, event_new, arginfo_event_new) 1621 | PHP_FE(event_timer_set, arginfo_event_timer_set) 1622 | PHP_FE(event_timer_pending, arginfo_event_timer_pending) 1623 | PHP_FALIAS(event_timer_add, event_add, arginfo_event_add) 1624 | PHP_FALIAS(event_timer_del, event_del, arginfo_event_del) 1625 | {NULL, NULL, NULL} 1626 | }; 1627 | /* }}} */ 1628 | #else 1629 | /* {{{ libevent_functions[] 1630 | */ 1631 | zend_function_entry libevent_functions[] = { 1632 | PHP_FE(event_base_new, NULL) 1633 | PHP_FE(event_base_reinit, NULL) 1634 | PHP_FE(event_base_free, NULL) 1635 | PHP_FE(event_base_loop, NULL) 1636 | PHP_FE(event_base_loopbreak, NULL) 1637 | PHP_FE(event_base_loopexit, NULL) 1638 | PHP_FE(event_base_set, NULL) 1639 | PHP_FE(event_base_priority_init, NULL) 1640 | PHP_FE(event_new, NULL) 1641 | PHP_FE(event_free, NULL) 1642 | PHP_FE(event_add, NULL) 1643 | PHP_FE(event_set, NULL) 1644 | PHP_FE(event_del, NULL) 1645 | PHP_FE(event_priority_set, NULL) 1646 | PHP_FE(event_buffer_new, NULL) 1647 | PHP_FE(event_buffer_free, NULL) 1648 | PHP_FE(event_buffer_base_set, NULL) 1649 | PHP_FE(event_buffer_priority_set, NULL) 1650 | PHP_FE(event_buffer_write, NULL) 1651 | PHP_FE(event_buffer_read, NULL) 1652 | PHP_FE(event_buffer_enable, NULL) 1653 | PHP_FE(event_buffer_disable, NULL) 1654 | PHP_FE(event_buffer_timeout_set, NULL) 1655 | PHP_FE(event_buffer_watermark_set, NULL) 1656 | PHP_FE(event_buffer_fd_set, NULL) 1657 | PHP_FALIAS(event_timer_new, event_new, NULL) 1658 | PHP_FE(event_timer_set, NULL) 1659 | PHP_FE(event_timer_pending, NULL) 1660 | PHP_FALIAS(event_timer_add, event_add, NULL) 1661 | PHP_FALIAS(event_timer_del, event_del, NULL) 1662 | {NULL, NULL, NULL} 1663 | }; 1664 | /* }}} */ 1665 | #endif 1666 | 1667 | static const zend_module_dep libevent_deps[] = { /* {{{ */ 1668 | ZEND_MOD_OPTIONAL("sockets") 1669 | {NULL, NULL, NULL} 1670 | }; 1671 | /* }}} */ 1672 | 1673 | /* {{{ libevent_module_entry 1674 | */ 1675 | zend_module_entry libevent_module_entry = { 1676 | STANDARD_MODULE_HEADER_EX, 1677 | NULL, 1678 | libevent_deps, 1679 | "libevent", 1680 | libevent_functions, 1681 | PHP_MINIT(libevent), 1682 | NULL, 1683 | NULL, 1684 | NULL, 1685 | PHP_MINFO(libevent), 1686 | PHP_LIBEVENT_VERSION, 1687 | STANDARD_MODULE_PROPERTIES 1688 | }; 1689 | /* }}} */ 1690 | 1691 | /* 1692 | * Local variables: 1693 | * tab-width: 4 1694 | * c-basic-offset: 4 1695 | * End: 1696 | * vim600: noet sw=4 ts=4 fdm=marker 1697 | * vim<600: noet sw=4 ts=4 1698 | */ 1699 | --------------------------------------------------------------------------------