@@ -172,7 +172,7 @@ static void php_mrloop_readv_cb(void *data, int res)
172
172
cb = (php_mrloop_cb_t * )data ;
173
173
iov = (php_iovec_t * )cb -> data ;
174
174
175
- char next [iov -> iov_len ];
175
+ char next [( size_t ) iov -> iov_len ];
176
176
sprintf (next , "%.*s" , (int )iov -> iov_len , (char * )iov -> iov_base );
177
177
178
178
ZVAL_STRING (& args [0 ], next );
@@ -434,23 +434,32 @@ static void php_mrloop_parse_http_response(INTERNAL_FUNCTION_PARAMETERS)
434
434
435
435
static void php_mrloop_signal_cb (int sig )
436
436
{
437
- zval result ;
438
- int fsignal ;
439
-
440
- MRLOOP_G (sig_cb )-> fci .retval = & result ;
441
- MRLOOP_G (sig_cb )-> fci .param_count = 0 ;
442
- MRLOOP_G (sig_cb )-> fci .params = NULL ;
443
-
444
- fsignal = MRLOOP_G (sig_cb )-> signal ;
445
-
446
- if (fsignal == sig )
437
+ for (size_t idx = 0 ; idx < MRLOOP_G (sigc ); idx ++ )
447
438
{
448
- if (zend_call_function ( & MRLOOP_G (sig_cb )-> fci , & MRLOOP_G ( sig_cb ) -> fci_cache ) == FAILURE )
439
+ if (MRLOOP_G (sig_cb )[ idx ] == NULL )
449
440
{
450
- PHP_MRLOOP_THROW ( "There is an error in your callback" ) ;
441
+ break ;
451
442
}
452
443
453
- zval_ptr_dtor (& result );
444
+ php_mrloop_cb_t * cb = MRLOOP_G (sig_cb )[idx ];
445
+
446
+ if (cb -> signal == sig )
447
+ {
448
+ zval result ;
449
+
450
+ cb -> fci .retval = & result ;
451
+ cb -> fci .param_count = 0 ;
452
+ cb -> fci .params = NULL ;
453
+
454
+ if (zend_call_function (& cb -> fci , & cb -> fci_cache ) == FAILURE )
455
+ {
456
+ PHP_MRLOOP_THROW ("There is an error in your callback" );
457
+ }
458
+
459
+ zval_ptr_dtor (& result );
460
+
461
+ break ;
462
+ }
454
463
}
455
464
456
465
exit (EXIT_SUCCESS );
@@ -466,9 +475,12 @@ static void php_mrloop_add_signal(INTERNAL_FUNCTION_PARAMETERS)
466
475
Z_PARAM_FUNC (fci , fci_cache )
467
476
ZEND_PARSE_PARAMETERS_END ();
468
477
469
- MRLOOP_G (sig_cb ) = emalloc (sizeof (php_mrloop_cb_t ));
470
- PHP_CB_TO_MRLOOP_CB (MRLOOP_G (sig_cb ), fci , fci_cache );
471
- MRLOOP_G (sig_cb )-> signal = (int )php_signal ;
478
+ MRLOOP_G (sigc )++ ;
479
+ size_t next = MRLOOP_G (sigc ) - 1 ;
480
+
481
+ MRLOOP_G (sig_cb )[next ] = emalloc (sizeof (php_mrloop_cb_t ));
482
+ PHP_CB_TO_MRLOOP_CB (MRLOOP_G (sig_cb )[next ], fci , fci_cache );
483
+ MRLOOP_G (sig_cb )[next ]-> signal = (int )php_signal ;
472
484
473
485
signal (SIGINT , php_mrloop_signal_cb );
474
486
signal (SIGHUP , php_mrloop_signal_cb );
@@ -533,7 +545,7 @@ static void php_mrloop_add_read_stream(INTERNAL_FUNCTION_PARAMETERS)
533
545
return ;
534
546
}
535
547
536
- fnbytes = (size_t )(nbytes_null == true ? DEFAULT_STREAM_BUFF_LEN : fnbytes );
548
+ fnbytes = (size_t )(nbytes_null == true ? DEFAULT_STREAM_BUFF_LEN : nbytes );
537
549
538
550
iov = emalloc (sizeof (php_iovec_t ));
539
551
iov -> iov_base = emalloc (fnbytes );
0 commit comments