unix: retry on EINTR in uv_sleep()

Reception of a signal makes nanosleep() return prematurely. Restart the
system call when that happens.

PR-URL: https://github.com/libuv/libuv/pull/2552
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Ben Noordhuis 2019-11-28 12:23:14 +01:00 committed by cjihrig
parent 664f9c0011
commit 7a914e7f3d
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5

View File

@ -1558,8 +1558,14 @@ int uv_gettimeofday(uv_timeval64_t* tv) {
void uv_sleep(unsigned int msec) {
struct timespec timeout;
int rc;
timeout.tv_sec = msec / 1000;
timeout.tv_nsec = (msec % 1000) * 1000 * 1000;
nanosleep(&timeout, NULL);
do
rc = nanosleep(&timeout, &timeout);
while (rc == -1 && errno == EINTR);
assert(rc == 0);
}