@@ -44,6 +44,8 @@ static zend_object_handlers php_io_poll_context_object_handlers;
4444static zend_object_handlers php_io_poll_watcher_object_handlers ;
4545static zend_object_handlers php_io_poll_handle_object_handlers ;
4646
47+ typedef struct php_io_poll_context_object php_io_poll_context_object ;
48+
4749/* Watcher object structure */
4850typedef struct php_io_poll_watcher_object {
4951 php_poll_handle_object * handle ;
@@ -56,11 +58,11 @@ typedef struct php_io_poll_watcher_object {
5658} php_io_poll_watcher_object ;
5759
5860/* Context object structure */
59- typedef struct php_io_poll_context_object {
61+ struct php_io_poll_context_object {
6062 php_poll_ctx * ctx ;
6163 HashTable * watchers ; /* Maps handle pointer -> watcher object */
6264 zend_object std ;
63- } php_io_poll_context_object ;
65+ };
6466
6567/* Stream poll handle specific data */
6668typedef struct php_stream_poll_handle_data {
@@ -251,8 +253,7 @@ static zend_object *php_io_poll_watcher_create_object(zend_class_entry *ce)
251253 intern -> watched_events = 0 ;
252254 intern -> triggered_events = 0 ;
253255 intern -> active = false;
254- intern -> poll_ctx = NULL ;
255- intern -> watchers = NULL ;
256+ intern -> context = NULL ;
256257 ZVAL_NULL (& intern -> data );
257258
258259 return & intern -> std ;
@@ -294,8 +295,7 @@ static void php_io_poll_context_free_object(zend_object *obj)
294295 ZEND_HASH_FOREACH_VAL (intern -> watchers , zval * zv ) {
295296 php_io_poll_watcher_object * watcher = PHP_POLL_WATCHER_OBJ_FROM_ZOBJ (Z_OBJ_P (zv ));
296297 watcher -> active = false;
297- watcher -> poll_ctx = NULL ;
298- watcher -> watchers = NULL ;
298+ watcher -> context = NULL ;
299299 } ZEND_HASH_FOREACH_END ();
300300 }
301301
@@ -351,7 +351,7 @@ static zend_always_inline zend_ulong php_io_poll_compute_ptr_key(void *ptr)
351351static zend_result php_io_poll_watcher_modify_events (
352352 php_io_poll_watcher_object * watcher , uint32_t events )
353353{
354- if (!watcher -> active || !watcher -> poll_ctx ) {
354+ if (!watcher -> active || !watcher -> context || ! watcher -> context -> ctx ) {
355355 zend_throw_exception (
356356 php_io_poll_inactive_watcher_class_entry , "Cannot modify inactive watcher" , 0 );
357357 return FAILURE ;
@@ -365,8 +365,9 @@ static zend_result php_io_poll_watcher_modify_events(
365365 }
366366
367367 /* Modify in poll context */
368- if (php_poll_modify (watcher -> poll_ctx , (int ) fd , events , watcher ) != SUCCESS ) {
369- php_poll_error err = php_poll_get_error (watcher -> poll_ctx );
368+ php_poll_ctx * poll_ctx = watcher -> context -> ctx ;
369+ if (php_poll_modify (poll_ctx , (int ) fd , events , watcher ) != SUCCESS ) {
370+ php_poll_error err = php_poll_get_error (poll_ctx );
370371 php_io_poll_throw_failed_operation (php_io_poll_failed_watcher_mod_class_entry ,
371372 "Failed to modify watcher in polling system" , err );
372373 return FAILURE ;
@@ -634,23 +635,23 @@ PHP_METHOD(Io_Poll_Watcher, remove)
634635
635636 php_io_poll_watcher_object * intern = PHP_POLL_WATCHER_OBJ_FROM_ZV (getThis ());
636637
637- if (!intern -> active || !intern -> poll_ctx ) {
638+ if (!intern -> active || !intern -> context || ! intern -> context -> ctx ) {
638639 zend_throw_exception (
639640 php_io_poll_inactive_watcher_class_entry , "Cannot remove inactive watcher" , 0 );
640641 RETURN_THROWS ();
641642 }
642643
643- php_poll_ctx * poll_ctx = intern -> poll_ctx ;
644- HashTable * watchers = intern -> watchers ;
644+ php_io_poll_context_object * context = intern -> context ;
645+ php_poll_ctx * poll_ctx = context -> ctx ;
646+ HashTable * watchers = context -> watchers ;
645647 zend_ulong hash_key = php_io_poll_compute_ptr_key (intern -> handle );
646648 php_socket_t fd = php_poll_handle_get_fd (intern -> handle );
647649 if (fd != SOCK_ERR ) {
648650 php_poll_remove (poll_ctx , (int ) fd );
649651 }
650652
651653 intern -> active = false;
652- intern -> poll_ctx = NULL ;
653- intern -> watchers = NULL ;
654+ intern -> context = NULL ;
654655
655656 if (watchers ) {
656657 zend_hash_index_del (watchers , hash_key );
@@ -768,8 +769,7 @@ PHP_METHOD(Io_Poll_Context, add)
768769 zend_hash_index_add_new (intern -> watchers , hash_key , & watcher_zv );
769770
770771 watcher -> active = true;
771- watcher -> poll_ctx = intern -> ctx ;
772- watcher -> watchers = intern -> watchers ;
772+ watcher -> context = intern ;
773773}
774774
775775PHP_METHOD (Io_Poll_Context , wait )
0 commit comments