Commits

Ruslan Osmanov committed b200b2e Merge

Merged in weltling/pecl-event (pull request #5)

Windows compatibility

  • Participants
  • Parent commits 38ca9f2, ed20d7b

Comments (0)

Files changed (16)

File 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 = NULL;
+	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 = NULL;
+	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);
 	}

File classes/event.c

 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 = NULL;
+	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;
+	zend_fcall_info     *pfci;
+	zval                *arg_data;
+	zval                *arg_fd;
+	zval                *arg_what;
+	zval               **args[3];
+	zval                *retval_ptr = NULL;
+	PHP_EVENT_TSRM_DECL
 
 	PHP_EVENT_ASSERT(e);
 	PHP_EVENT_ASSERT(e->fci && e->fcc);
 
-	zend_fcall_info     *pfci       = e->fci;
-	zval                *arg_data   = e->data;
-	zval                *arg_fd;
-	zval                *arg_what;
-	zval               **args[3];
-	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 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 = NULL;
+	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 */
 	zval                   *zevent  = getThis();
 	php_event_t            *e;
 	zval                  **ppzfd   = NULL;
-	evutil_socket_t         fd;
+	evutil_socket_t         fd = -1;
 	long                    what    = -1;
 	zend_fcall_info         fci     = empty_fcall_info;
 	zend_fcall_info_cache   fcc     = empty_fcall_info_cache;

File classes/http.c

 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 = NULL;
+	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 = NULL;
+	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);

File 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 = NULL;
+	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) {

File 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 = NULL;
+	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();
 	}

File 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 = NULL;
+	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 = NULL;
+	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); */

File 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;
+// $Id$
+// vim:ft=javascript
+
+ARG_WITH("event", "for event support", "no");
+
+/* XXX fix libevent makefile.nmake to support openssl */
+/* XXX maybe it'd make sense to define the config options to split the features like m4 does */
+
+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_LIB("libevent_extras.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_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("php_event.h", "CFLAGS_EVENT", configure_module_dirname)) {
+
+		ADD_EXTENSION_DEP("event", "sockets");
+		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 _EVENT_HAVE_OPENSSL=1"); */
+		ADD_FLAG("CFLAGS_EVENT", "/D HAVE_EVENT_EXTRA_LIB=1");
+
+		EXTENSION("event", "php_event.c", "true");
+
+
+		ADD_SOURCES(configure_module_dirname + "\\src", "util.c fe.c pe.c", "event");
+		ADD_SOURCES(configure_module_dirname + "\\classes", " \
+			event.c \
+			base.c \
+			event_config.c \
+			buffer_event.c \
+			buffer.c \
+			event_util.c \
+			dns.c \
+			listener.c \
+			http.c \
+			http_request.c \
+			http_connection.c", 
+			"event");
+			//ssl_context.c
+	} else {
+		WARNING("event not enabled, libraries or headers not found");
+	}
+}
+
       <file role="doc" name="LICENSE"/>
       <file role="doc" name="README.md"/>
       <file role="src" name="config.m4"/>
+      <file role="src" name="config.w32"/>
       <file role="src" name="php_event.c"/>
       <file role="src" name="php_event.h"/>
       <dir name="classes">
         <name>libevent</name>
         <conflicts/>
       </extension>
-      <os>
-        <name>windows</name>
-        <conflicts/>
-      </os>
     </required>
   </dependencies>
   <providesextension>event</providesextension>
 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);
  * Overrides libevent's default error logging(it logs to stderr) */
 static void log_cb(int severity, const char *msg)
 {
+	int error_type;
+
 	/* TSRMLS_FETCH consumes a fair amount of resources.  But a ready-to-use
 	 * program shouldn't get any error logs. Nevertheless, we have no other way
 	 * to fetch TSRMLS. */
 	TSRMLS_FETCH();
 
-	int error_type;
-
 	switch (severity) {
 		case PHP_EVENT_LOG_CONST(EVENT_LOG_DEBUG):
 			error_type = E_STRICT;
 	REGISTER_EVENT_CLASS_CONST_LONG(php_event_ce, SIGNAL,  EV_SIGNAL);
 	REGISTER_EVENT_CLASS_CONST_LONG(php_event_ce, TIMEOUT, EV_TIMEOUT);
 
+	/* XXX define on the fly by calling event_base_get_features() first */
 	/* Features of event_base usually passed to event_config_require_features */
 	REGISTER_EVENT_CLASS_CONST_LONG(php_event_config_ce, FEATURE_ET,  EV_FEATURE_ET);
 	REGISTER_EVENT_CLASS_CONST_LONG(php_event_config_ce, FEATURE_O1,  EV_FEATURE_O1);
 
 #ifdef HAVE_EVENT_PTHREADS_LIB
 # ifdef WIN32
-# error "Windows is not supported right now"
 	evthread_use_windows_threads();
 # else
 	if (evthread_use_pthreads()) {

File src/common.h

 #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
 

File src/structs.h

 /* Thread context. With it we are getting rid of need
  * to call the heavy TSRMLS_FETCH() */
 #ifdef ZTS
-# define PHP_EVENT_COMMON_THREAD_CTX void ***thread_ctx
+# define PHP_EVENT_COMMON_THREAD_CTX void ***thread_ctx;
 #else
 # define PHP_EVENT_COMMON_THREAD_CTX
 #endif
 	zend_fcall_info       *fci;
 	zend_fcall_info_cache *fcc;
 
-	PHP_EVENT_COMMON_THREAD_CTX;
+	PHP_EVENT_COMMON_THREAD_CTX
 } php_event_t;
 
 /* Represents EventConfig object */
 	zend_fcall_info       *fci_event;
 	zend_fcall_info_cache *fcc_event;
 
-	PHP_EVENT_COMMON_THREAD_CTX;
+	PHP_EVENT_COMMON_THREAD_CTX
 } php_event_bevent_t;
 
 /* Represents EventBuffer object */
 	zend_fcall_info       *fci_err;
 	zend_fcall_info_cache *fcc_err;
 
-	PHP_EVENT_COMMON_THREAD_CTX;
+	PHP_EVENT_COMMON_THREAD_CTX
 } php_event_listener_t;
 
 typedef struct _php_event_http_cb_t php_event_http_cb_t;
 	zend_fcall_info       *fci;
 	zend_fcall_info_cache *fcc;
 
-	PHP_EVENT_COMMON_THREAD_CTX;
+	PHP_EVENT_COMMON_THREAD_CTX
 };
 
 /* Represents EventHttp object */
 	/* Linked list of attached callbacks */
 	php_event_http_cb_t   *cb_head;
 
-	PHP_EVENT_COMMON_THREAD_CTX;
+	PHP_EVENT_COMMON_THREAD_CTX
 } php_event_http_t;
 
 /* Represents EventHttpConnection object */
 	zend_fcall_info       *fci_closecb;
 	zend_fcall_info_cache *fcc_closecb;
 	
-	PHP_EVENT_COMMON_THREAD_CTX;
+	PHP_EVENT_COMMON_THREAD_CTX
 } php_event_http_conn_t;
 
 typedef struct {
 	zend_fcall_info       *fci;
 	zend_fcall_info_cache *fcc;
 
-	PHP_EVENT_COMMON_THREAD_CTX;
+	PHP_EVENT_COMMON_THREAD_CTX
 } php_event_http_req_t;
 
 #endif/* HAVE_EVENT_EXTRA_LIB }}} */
 
 #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_SOCKET) {
+#endif
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "fcntl: invalid file descriptor passed");
 		return -1;
 	}
     PHP_EVENT_SOCKETS_REQUIRED_NORET;                                          \
     RETURN_FALSE
 
+#if defined(PHP_WIN32)
+#if defined(ZTS)
+#  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)
+#  define PHP_EVENT_TSRM_DECL
+# endif
+#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 */
 

File tests/07-listener-error-win32.phpt

+--TEST--
+Check for EventListener error behaviour 
+--SKIPIF--
+<?php
+if (!class_exists("EventListener")) die("skip Event extra functions are disabled");
+if ( substr(PHP_OS, 0, 3) != "WIN" ) die('skip Run only on Windows');
+?>
+--FILE--
+<?php
+$base = new EventBase();
+
+$sock_paths = array (
+	sys_get_temp_dir() . DIRECTORY_SEPARATOR . mt_rand().".sock"      => FALSE,
+);
+
+foreach ($sock_paths as $path => $expect) {
+	$listener = @new EventListener($base, function() {}, NULL, 0, -1, $path);
+	if (file_exists($path)) unlink($path);
+
+	var_dump(is_null($listener) != $expect);
+}
+
+?>
+--EXPECT--
+bool(true)

File tests/07-listener-error.phpt

 Check for EventListener error behaviour 
 --SKIPIF--
 <?php
-if (!class_exists("EventListener")) echo "skip Event extra functions are disabled"
+if (!class_exists("EventListener")) die("skip Event extra functions are disabled");
+if (substr(PHP_OS, 0, 3) == "WIN") die('skip Not for Windows');
 ?>
 --FILE--
 <?php