You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
echoping/SRC/ttcp/ttcpcliserv/sleepus.c

38 lines
1.2 KiB
C

/*
* Copyright (c) 1996 W. Richard Stevens. All rights reserved.
* Permission to use or modify this software and its documentation only for
* educational purposes and without fee is hereby granted, provided that
* the above copyright notice appear in all copies. The author makes no
* representations about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*/
#include <sys/types.h>
#include <sys/time.h>
#include <errno.h>
#include <stddef.h>
void
sleep_us(unsigned int nusecs)
{
struct timeval tval;
for ( ; ; ) {
tval.tv_sec = nusecs / 1000000;
tval.tv_usec = nusecs % 1000000;
if (select(0, NULL, NULL, NULL, &tval) == 0)
break; /* all OK */
/*
* Note than on an interrupted system call (i.e, SIGIO) there's not
* much we can do, since the timeval{} isn't updated with the time
* remaining. We could obtain the clock time before the call, and
* then obtain the clock time here, subtracting them to determine
* how long select() blocked before it was interrupted, but that
* seems like too much work :-)
*/
if (errno == EINTR)
continue;
err_sys("sleep_us: select error");
}
}