@@ -349,19 +349,30 @@ static int php_sockop_stat(php_stream *stream, php_stream_statbuf *ssb)
349349
350350static inline int sock_async_poll (php_netstream_data_t * sock , async_poll_event poll_events )
351351{
352- if (UNEXPECTED (sock -> is_blocked && !sock -> nonblocking_applied && ZEND_ASYNC_IS_ACTIVE )) {
352+ if (!sock -> is_blocked || !ZEND_ASYNC_IS_ACTIVE ) {
353+ return 1 ; /* nothing to do */
354+ }
355+
356+ if (UNEXPECTED (!sock -> nonblocking_applied )) {
353357 if (UNEXPECTED (!network_async_set_socket_blocking (sock -> socket , false, sock ))) {
354358 return -1 ;
355359 }
356360 }
357361
358- if (sock -> is_blocked && ZEND_ASYNC_IS_ACTIVE ) {
359- struct timeval * timeout = (sock -> timeout .tv_sec == -1 ) ? NULL : & sock -> timeout ;
360- int poll_result = network_async_await_stream_socket (sock , poll_events , timeout );
362+ struct timeval * timeout = (sock -> timeout .tv_sec == -1 ) ? NULL : & sock -> timeout ;
363+
364+ const int poll_result = network_async_await_stream_socket (sock , poll_events , timeout );
365+
366+ if (UNEXPECTED (poll_result <= 0 )) {
367+ if (poll_result == 0 && timeout ) {
368+ php_error_docref (NULL , E_WARNING , "Socket operation timed out after %ld.%06ld seconds" ,
369+ (long )timeout -> tv_sec , (long )timeout -> tv_usec );
361370
362- if ( UNEXPECTED ( poll_result <= 0 )) {
363- return poll_result ;
371+ sock -> timeout_event = true;
372+ return -1 ;
364373 }
374+
375+ return poll_result ;
365376 }
366377
367378 return 1 ; /* ready to proceed */
0 commit comments