Anatol Belski avatar Anatol Belski committed fd7e66a

very basic windows support

Comments (0)

Files changed (12)

classes/buffer_event.c

 #include "src/util.h"
 #include "src/priv.h"
 
+extern const zend_function_entry php_event_dns_base_ce_functions[];
+extern zend_class_entry *php_event_dns_base_ce;
+
 /* {{{ Private */
 
 #define _ret_if_invalid_bevent_ptr(bev)             \
  * Is called from the bufferevent read and write callbacks */
 static zend_always_inline void bevent_rw_cb(struct bufferevent *bevent, php_event_bevent_t *bev, zend_fcall_info *pfci, zend_fcall_info_cache *pfcc)
 {
+
+	zval  *arg_data;
+	zval  *arg_self;
+	zval **args[2];
+	zval  *retval_ptr;
+	PHP_EVENT_TSRM_DECL
+
 	PHP_EVENT_ASSERT(bev);
 	PHP_EVENT_ASSERT(bevent);
 	PHP_EVENT_ASSERT(bevent == bev->bevent);
 	PHP_EVENT_ASSERT(pfci && pfcc);
 	PHP_EVENT_ASSERT(bev->self);
 
-	zval  *arg_data = bev->data;
-	zval  *arg_self;
-	zval **args[2];
-	zval  *retval_ptr;
+	arg_data = bev->data;
 
-	TSRMLS_FETCH_FROM_CTX(bev->thread_ctx);
+	PHP_EVENT_TSRMLS_FETCH_FROM_CTX(bev->thread_ctx);
 
 	if (ZEND_FCI_INITIALIZED(*pfci)) {
 #ifdef HAVE_EVENT_PTHREADS_LIB
 	php_event_bevent_t    *bev  = (php_event_bevent_t *) ptr;
 	zend_fcall_info       *pfci = bev->fci_event;
 	zend_fcall_info_cache *pfcc = bev->fcc_event;
+	zval  *arg_data;
+	zval  *arg_events;
+	zval  *arg_self;
+	zval **args[3];
+	zval  *retval_ptr;
+	PHP_EVENT_TSRM_DECL
 
 	PHP_EVENT_ASSERT(pfci && pfcc);
 	PHP_EVENT_ASSERT(bevent);
 	PHP_EVENT_ASSERT(bev->self);
 
 
-	zval  *arg_data   = bev->data;
-	zval  *arg_events;
-	zval  *arg_self;
-	zval **args[3];
-	zval  *retval_ptr;
+	arg_data = bev->data;
 
-	TSRMLS_FETCH_FROM_CTX(bev->thread_ctx);
+	PHP_EVENT_TSRMLS_FETCH_FROM_CTX(bev->thread_ctx);
 
 	if (ZEND_FCI_INITIALIZED(*pfci)) {
 #ifdef HAVE_EVENT_PTHREADS_LIB
 	int                 hostname_len;
 	long                port;
 	long                family       = AF_UNSPEC;
+#ifdef HAVE_EVENT_EXTRA_LIB
+	php_event_dns_base_t *dnsb;
+#endif
 
 #ifdef HAVE_EVENT_EXTRA_LIB
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O!sl|l",
 	 * bufferevent_socket_new() */
 
 #ifdef HAVE_EVENT_EXTRA_LIB
-	php_event_dns_base_t *dnsb;
-
 	if (zdns_base) {
 		PHP_EVENT_FETCH_DNS_BASE(dnsb, zdns_base);
 	}
 static void timer_cb(evutil_socket_t fd, short what, void *arg)
 {
 	php_event_t *e = (php_event_t *) arg;
+	zend_fcall_info     *pfci;
+	zval                *arg_data;
+	zval               **args[1];
+	zval                *retval_ptr;
+	PHP_EVENT_TSRM_DECL
 
 	PHP_EVENT_ASSERT(e);
 	PHP_EVENT_ASSERT(what & EV_TIMEOUT);
 	PHP_EVENT_ASSERT(e->fci && e->fcc);
 
-	zend_fcall_info     *pfci       = e->fci;
-	zval                *arg_data   = e->data;
-	zval               **args[1];
-	zval                *retval_ptr;
+	pfci     = e->fci;
+	arg_data = e->data;
 
-	TSRMLS_FETCH_FROM_CTX(e->thread_ctx);
+	PHP_EVENT_TSRMLS_FETCH_FROM_CTX(e->thread_ctx);
 
 	if (ZEND_FCI_INITIALIZED(*pfci)) {
 		/* Setup callback arg */
 static void event_cb(evutil_socket_t fd, short what, void *arg)
 {
 	php_event_t *e = (php_event_t *) arg;
-
-	PHP_EVENT_ASSERT(e);
-	PHP_EVENT_ASSERT(e->fci && e->fcc);
-
-	zend_fcall_info     *pfci       = e->fci;
-	zval                *arg_data   = e->data;
+	zend_fcall_info     *pfci;
+	zval                *arg_data;
 	zval                *arg_fd;
 	zval                *arg_what;
 	zval               **args[3];
 	zval                *retval_ptr;
+	PHP_EVENT_TSRM_DECL
+
+	PHP_EVENT_ASSERT(e);
+	PHP_EVENT_ASSERT(e->fci && e->fcc);
+
+	pfci       = e->fci;
+	arg_data   = e->data;
 
-	TSRMLS_FETCH_FROM_CTX(e->thread_ctx);
+	PHP_EVENT_TSRMLS_FETCH_FROM_CTX(e->thread_ctx);
 
 	if (ZEND_FCI_INITIALIZED(*pfci)) {
 		/* Setup callback arguments */
 static void signal_cb(evutil_socket_t signum, short what, void *arg)
 {
 	php_event_t *e = (php_event_t *) arg;
+	zend_fcall_info     *pfci;
+	zval                *arg_data;
+	zval                *arg_signum;
+	zval               **args[2];
+	zval                *retval_ptr;
+	PHP_EVENT_TSRM_DECL
 
 	PHP_EVENT_ASSERT(e);
 	PHP_EVENT_ASSERT(what & EV_SIGNAL);
 	PHP_EVENT_ASSERT(e->fci && e->fcc);
 
-	zend_fcall_info     *pfci       = e->fci;
-	zval                *arg_data   = e->data;
-	zval                *arg_signum;
-	zval               **args[2];
-	zval                *retval_ptr;
+	pfci     = e->fci;
+	arg_data = e->data;
 
-	TSRMLS_FETCH_FROM_CTX(e->thread_ctx);
+	PHP_EVENT_TSRMLS_FETCH_FROM_CTX(e->thread_ctx);
 
 	if (ZEND_FCI_INITIALIZED(*pfci)) {
 		/* Setup callback args */
 static void _http_callback(struct evhttp_request *req, void *arg)
 {
 	php_event_http_cb_t *cb = (php_event_http_cb_t *) arg;
-	PHP_EVENT_ASSERT(cb);
-
 	php_event_http_req_t *http_req;
+	zend_fcall_info       *pfci;
+	zend_fcall_info_cache *pfcc;
+	zval  *arg_data;
+	zval  *arg_req;
+	zval **args[2];
+	zval  *retval_ptr;
+	PHP_EVENT_TSRM_DECL
 
-	zend_fcall_info       *pfci = cb->fci;
-	zend_fcall_info_cache *pfcc = cb->fcc;
+	PHP_EVENT_ASSERT(cb);
+
+	pfci = cb->fci;
+	pfcc = cb->fcc;
 	PHP_EVENT_ASSERT(pfci && pfcc);
 
-	TSRMLS_FETCH_FROM_CTX(cb->thread_ctx);
+	PHP_EVENT_TSRMLS_FETCH_FROM_CTX(cb->thread_ctx);
 
 	/* Call userspace function according to
 	 * proto void callback(EventHttpRequest req, mixed data);*/
 
-	zval  *arg_data = cb->data;
-	zval  *arg_req;
-	zval **args[2];
-	zval  *retval_ptr;
+	arg_data = cb->data;
 
 	MAKE_STD_ZVAL(arg_req);
 	PHP_EVENT_INIT_CLASS_OBJECT(arg_req, php_event_http_req_ce);
 static void _http_default_callback(struct evhttp_request *req, void *arg)
 {
 	php_event_http_t *http = (php_event_http_t *) arg;
-	PHP_EVENT_ASSERT(http);
-
 	php_event_http_req_t *http_req;
+	zend_fcall_info       *pfci;
+	zend_fcall_info_cache *pfcc;
+	zval  *arg_data;
+	zval  *arg_req;
+	zval **args[2];
+	zval  *retval_ptr;
+	PHP_EVENT_TSRM_DECL
 
-	zend_fcall_info       *pfci = http->fci;
-	zend_fcall_info_cache *pfcc = http->fcc;
+	PHP_EVENT_ASSERT(http);
+
+	pfci = http->fci;
+	pfcc = http->fcc;
 	PHP_EVENT_ASSERT(pfci && pfcc);
 
-	TSRMLS_FETCH_FROM_CTX(http->thread_ctx);
+	PHP_EVENT_TSRMLS_FETCH_FROM_CTX(http->thread_ctx);
 
 	/* Call userspace function according to
 	 * proto void callback(EventHttpRequest req, mixed data);*/
 
-	zval  *arg_data = http->data;
-	zval  *arg_req;
-	zval **args[2];
-	zval  *retval_ptr;
+	arg_data = http->data;
 
 	MAKE_STD_ZVAL(arg_req);
 	PHP_EVENT_INIT_CLASS_OBJECT(arg_req, php_event_http_req_ce);

classes/http_connection.c

 static void _conn_close_cb(struct evhttp_connection *conn, void *arg)/* {{{ */
 {
 	php_event_http_conn_t *evcon = (php_event_http_conn_t *) arg;
+	zend_fcall_info       *pfci;
+	zend_fcall_info_cache *pfcc;
+	zval  *arg_data;
+	zval  *arg_conn;
+	zval **args[2];
+	zval  *retval_ptr;
+	PHP_EVENT_TSRM_DECL
+
 	PHP_EVENT_ASSERT(evcon && conn);
 
-	zend_fcall_info       *pfci = evcon->fci_closecb;
-	zend_fcall_info_cache *pfcc = evcon->fcc_closecb;
+	pfci = evcon->fci_closecb;
+	pfcc = evcon->fcc_closecb;
 	PHP_EVENT_ASSERT(pfci && pfcc);
 
-	TSRMLS_FETCH_FROM_CTX(evcon->thread_ctx);
+	PHP_EVENT_TSRMLS_FETCH_FROM_CTX(evcon->thread_ctx);
 
 	/* Call userspace function according to
 	 * proto void callback(EventHttpConnection conn, mixed data); */
 
-	zval  *arg_data = evcon->data_closecb;
-	zval  *arg_conn;
-	zval **args[2];
-	zval  *retval_ptr;
+	arg_data = evcon->data_closecb;
 
 	arg_conn = evcon->self;
 	if (conn == NULL || !arg_conn) {

classes/http_request.c

 static void _req_handler(struct evhttp_request *req, void *arg)
 {
 	php_event_http_req_t *http_req = (php_event_http_req_t *) arg;
+	zend_fcall_info       *pfci;
+	zend_fcall_info_cache *pfcc;
+	zval  *arg_data;
+	zval  *arg_req;
+	zval **args[2];
+	zval  *retval_ptr;
+	PHP_EVENT_TSRM_DECL
 
 	PHP_EVENT_ASSERT(http_req && http_req->ptr);
 	PHP_EVENT_ASSERT(http_req->fci && http_req->fcc);
 	PHP_EVENT_ASSERT(http_req->self);
 
-	zend_fcall_info       *pfci = http_req->fci;
-	zend_fcall_info_cache *pfcc = http_req->fcc;
+	pfci = http_req->fci;
+	pfcc = http_req->fcc;
 	PHP_EVENT_ASSERT(pfci && pfcc);
 
-	TSRMLS_FETCH_FROM_CTX(http_req->thread_ctx);
+	PHP_EVENT_TSRMLS_FETCH_FROM_CTX(http_req->thread_ctx);
 
 	/* Call userspace function according to
 	 * proto void callback(EventHttpRequest req, mixed data); */
 
-	zval  *arg_data = http_req->data;
-	zval  *arg_req;
-	zval **args[2];
-	zval  *retval_ptr;
+	arg_data = http_req->data;
 
 	arg_req = http_req->self;
 	/* req == NULL means timeout */
 	int                   key_len;
 	struct evkeyvalq     *headers;
 	long                  type;
+	const char *val;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl",
 				&key, &key_len, &type) == FAILURE) {
 	headers = _get_http_req_headers(http_req, type);
 	PHP_EVENT_ASSERT(headers);
 
-	const char *val = evhttp_find_header(headers, key);
+	val = evhttp_find_header(headers, key);
 	if (val == NULL) {
 		RETURN_NULL();
 	}

classes/listener.c

 /* {{{ _php_event_listener_cb */
 static void _php_event_listener_cb(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *address, int socklen, void *ctx) {
 	php_event_listener_t *l = (php_event_listener_t *) ctx;
+	zend_fcall_info       *pfci;
+	zend_fcall_info_cache *pfcc;
+	zval  **args[4];
+	zval   *arg_fd;
+	zval   *arg_address;
+	zval   *arg_data;
+	zval   *retval_ptr;
+	PHP_EVENT_TSRM_DECL
 
 	PHP_EVENT_ASSERT(l);
 
-	zend_fcall_info       *pfci = l->fci;
-	zend_fcall_info_cache *pfcc = l->fcc;
+	pfci = l->fci;
+	pfcc = l->fcc;
 
 	PHP_EVENT_ASSERT(pfci && pfcc);
 
-	zval  **args[4];
-	zval   *arg_fd;
-	zval   *arg_address;
-	zval   *arg_data     = l->data;
-	zval   *retval_ptr;
+	arg_data = l->data;
 
-	TSRMLS_FETCH_FROM_CTX(l->thread_ctx);
+	PHP_EVENT_TSRMLS_FETCH_FROM_CTX(l->thread_ctx);
 
 	/* Call user function having proto:
 	 * void cb (EventListener $listener, resource $fd, array $address, mixed $data);
 /* {{{ listener_error_cb */
 static void listener_error_cb(struct evconnlistener *listener, void *ctx) {
 	php_event_listener_t  *l = (php_event_listener_t *) ctx;
+	zend_fcall_info       *pfci;
+	zend_fcall_info_cache *pfcc;
+	zval  **args[2];
+	zval   *arg_data;
+	zval   *retval_ptr;
+	PHP_EVENT_TSRM_DECL
 
 	PHP_EVENT_ASSERT(l);
 
-	zend_fcall_info       *pfci = l->fci_err;
-	zend_fcall_info_cache *pfcc = l->fcc_err;
+	pfci = l->fci_err;
+	pfcc = l->fcc_err;
 
 	PHP_EVENT_ASSERT(pfci && pfcc);
 
-	zval  **args[2];
-	zval   *arg_data     = l->data;
-	zval   *retval_ptr;
+	arg_data = l->data;
 
-	TSRMLS_FETCH_FROM_CTX(l->thread_ctx);
+	PHP_EVENT_TSRMLS_FETCH_FROM_CTX(l->thread_ctx);
 
 	/* Call user function having proto:
 	 * void cb (EventListener $listener, mixed $data); */

classes/ssl_context.c

 		}
 
 		switch (idx) {
-			case PHP_EVENT_OPT_LOCAL_CERT:
-				convert_to_string_ex(ppzval);
+			case PHP_EVENT_OPT_LOCAL_CERT: {
 				zval **ppz_private_key;
+				convert_to_string_ex(ppzval);
 
 				if (zend_hash_index_find(ht, PHP_EVENT_OPT_LOCAL_PK,
 						(void **) &ppz_private_key) == SUCCESS) {
 					_php_event_ssl_ctx_set_local_cert(ctx, Z_STRVAL_PP(ppzval), NULL TSRMLS_CC);
 				}
 				break;
+			}
 			case PHP_EVENT_OPT_LOCAL_PK:
 				/* Skip. SSL_CTX_use_PrivateKey_file is applied in "local_cert". */
 				break;
 
 if (PHP_EVENT != "no") {
 
+	/* XXX separate for options */
 	if (CHECK_HEADER_ADD_INCLUDE("event2/event.h", "CFLAGS_EVENT", PHP_PHP_BUILD + "\\include;" + PHP_EVENT) &&
 		CHECK_LIB("libevent.lib", "event", PHP_PHP_BUILD + "\\lib;" + PHP_EVENT) &&
 		CHECK_LIB("libevent_core.lib", "event", PHP_PHP_BUILD + "\\lib;" + PHP_EVENT) &&
 		CHECK_HEADER_ADD_INCLUDE("pthread.h", "CFLAGS_EVENT", PHP_EVENT + ";" + configure_module_dirname) &&
 		CHECK_HEADER_ADD_INCLUDE("sched.h", "CFLAGS_EVENT", PHP_EVENT + ";" + configure_module_dirname) &&
 		CHECK_LIB("pthreadVC2.lib", "event", PHP_EVENT) &&
-		CHECK_HEADER_ADD_INCLUDE("openssl/ssl.h", "CFLAGS_OPENSSL") &&
-		CHECK_LIB("ssleay32.lib", "openssl", PHP_OPENSSL) &&
-		CHECK_LIB("libeay32.lib", "openssl", PHP_OPENSSL) &&
+		/*CHECK_HEADER_ADD_INCLUDE("openssl/ssl.h", "CFLAGS_EVENT") &&
+		CHECK_LIB("ssleay32.lib", "event", PHP_EVENT) &&
+		CHECK_LIB("libeay32.lib", "event", PHP_EVENT) &&*/
 		CHECK_HEADER_ADD_INCLUDE("common.h", "CFLAGS_EVENT", configure_module_dirname + "\\src") &&
-		CHECK_HEADER_ADD_INCLUDE("http.h", "CFLAGS_EVENT", configure_module_dirname + "\\classes.h")) {
+		CHECK_HEADER_ADD_INCLUDE("http.h", "CFLAGS_EVENT", configure_module_dirname + "\\classes.h") &&
+		CHECK_HEADER_ADD_INCLUDE("php_event.h", "CFLAGS_EVENT", configure_module_dirname)) {
 
 		ADD_EXTENSION_DEP("event", "sockets");
-		AC_DEFINE("PHP_EVENT_SOCKETS", 1);
+		ADD_FLAG("CFLAGS_EVENT", "/D PHP_EVENT_SOCKETS=1");
+
+		ADD_FLAG("CFLAGS_EVENT", "/D HAVE_EVENT_PTHREADS_LIB=1");
+		/*ADD_FLAG("CFLAGS_EVENT", "/D HAVE_EVENT_OPENSSL_LIB=1");*/
+		ADD_FLAG("CFLAGS_EVENT", "/D HAVE_EVENT_EXTRA_LIB=1");
 
 		EXTENSION("event", "php_event.c", "true");
 
 			listener.c \
 			http.c \
 			http_request.c \
-			http_connection.c \
-			ssl_context.c", 
+			http_connection.c", 
 			"event");
+			//ssl_context.c
 	} else {
 		WARNING("event not enabled, libraries or headers not found");
 	}
 static PHP_GINIT_FUNCTION(event);
 #endif
 
+extern const zend_property_info event_listener_property_entry_info[];
+extern const php_event_property_entry_t event_listener_property_entries[];
+
 zend_class_entry *php_event_ce;
 zend_class_entry *php_event_base_ce;
 zend_class_entry *php_event_config_ce;
 /* {{{ event_generic_object_free_storage */
 static zend_always_inline void event_generic_object_free_storage(void *ptr TSRMLS_DC)
 {
+	php_event_abstract_object_t *obj;
+
 	PHP_EVENT_ASSERT(ptr);
 
-	php_event_abstract_object_t *obj = (php_event_abstract_object_t *) ptr;
+	obj = (php_event_abstract_object_t *) ptr;
 
 	zend_object_std_dtor(&obj->zo TSRMLS_CC);
 
  * EventUtil object ctor */
 static zend_object_value event_util_object_create(zend_class_entry *ce TSRMLS_DC)
 {
+	php_event_abstract_object_t *obj;
+
 	/* EventUtil is a singleton. This function must never be called */
 	PHP_EVENT_ASSERT(0);
 
-	php_event_abstract_object_t *obj = (php_event_abstract_object_t *) object_new(ce, sizeof(php_event_abstract_object_t) TSRMLS_CC);
+	obj = (php_event_abstract_object_t *) object_new(ce, sizeof(php_event_abstract_object_t) TSRMLS_CC);
 
 	return register_object(ce, (void *) obj, (zend_objects_store_dtor_t) zend_objects_destroy_object,
 			event_generic_object_free_storage TSRMLS_CC);
 
 #ifdef HAVE_EVENT_PTHREADS_LIB
 # ifdef WIN32
-# error "Windows is not supported right now"
 	evthread_use_windows_threads();
 # else
 	if (evthread_use_pthreads()) {
 #include <php_network.h>
 #include <php_streams.h>
 
-#ifdef AF_UNIX
+#if !defined(PHP_WIN32) && defined(AF_UNIX)
 # include <sys/un.h>
 #endif
 
 # include <event2/bufferevent_ssl.h>
 #endif
 
-#if !defined(_WIN32) && !defined(_MINIX)
+#if !defined(_MINIX)
 # include <pthread.h>
 #endif
 
 
 #include "src/common.h"
 #include "src/util.h"
-#include <fcntl.h>
+#ifndef PHP_WIN32
+# include <fcntl.h>
+#endif
 
 /* {{{ php_event_zval_to_fd
  * Get numeric file descriptor from PHP stream or Socket resource */
 	}
 
 	/* Validate file descriptor */
+#ifndef PHP_WIN32
 	if (file_desc >= 0 && fcntl(file_desc, F_GETFD) == -1) {
+#else
+	if (file_desc == INVALID_HANDLE_VALUE) {
+#endif
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "fcntl: invalid file descriptor passed");
 		return -1;
 	}
     PHP_EVENT_SOCKETS_REQUIRED_NORET;                                          \
     RETURN_FALSE
 
+#ifdef PHP_WIN32
+# define PHP_EVENT_TSRMLS_FETCH_FROM_CTX(ctx) tsrm_ls = (void ***)ctx
+# define PHP_EVENT_TSRM_DECL void ***tsrm_ls;
+#else
+# define PHP_EVENT_TSRMLS_FETCH_FROM_CTX(ctx) TSRMLS_FETCH_FROM_CTX(ctx)
+# define PHP_EVENT_TSRM_DECL
+#endif
 
 #endif /* PHP_EVENT_UTIL_H */
 
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.