Skip to content

Commit 1058493

Browse files
committed
ext/ftp: prefer zend_monotime_fallback over zend_hrtime for timeout handling
1 parent fdabd9b commit 1058493

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

ext/ftp/ftp.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,22 +1370,21 @@ static int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) {
13701370

13711371
static int my_poll(php_socket_t fd, int events, int timeout) {
13721372
int n;
1373-
zend_hrtime_t timeout_hr = (zend_hrtime_t) timeout * 1000000;
1373+
uint64_t timeout_ns = (uint64_t) timeout * 1000000;
13741374

13751375
while (true) {
1376-
zend_hrtime_t start_ns = zend_hrtime();
1377-
n = php_pollfd_for_ms(fd, events, (int) (timeout_hr / 1000000));
1376+
uint64_t start_ns = zend_monotime_fallback();
1377+
n = php_pollfd_for_ms(fd, events, (int) (timeout_ns / 1000000));
13781378

13791379
if (n == -1 && php_socket_errno() == EINTR) {
1380-
zend_hrtime_t delta_ns = zend_hrtime() - start_ns;
1381-
/* delta_ns == 0 is only possible with a platform that does not support a high-res timer. */
1382-
if (delta_ns > timeout_hr || UNEXPECTED(delta_ns == 0)) {
1380+
uint64_t delta_ns = zend_monotime_fallback() - start_ns;
1381+
if (delta_ns > timeout_ns) {
13831382
#ifndef PHP_WIN32
13841383
errno = ETIMEDOUT;
13851384
#endif
13861385
break;
13871386
}
1388-
timeout_hr -= delta_ns;
1387+
timeout_ns -= delta_ns;
13891388
} else {
13901389
break;
13911390
}

0 commit comments

Comments
 (0)