/* * usleep(delay) -- * * Possible usleep replacement. Delay in microseconds. * Another possiblity is to use poll(2). On Solaris * 2.x, select is just a wrapper for poll, so you * are better off using it directly. If you use, * poll, note that it uses millisecond resolution, * and is not affected by the O_NDELAY and O_NONBLOCK * flags. * * Note that using nanosleep has portability implications, * even across different versions of Solaris 2.x. In * particular, only Solaris 2.3 has libposix4, and * hence nanosleep. Select (or poll) is a better option if * you need portability across those versions. * * If you define USE_NANOSLEEP, be sure to link with -lposix4 * */ #include #include #include #include #include #include #include #include #ifdef USE_POLL #include #include #endif /* USE_POLL */ int usleep(unsigned long int useconds) { #ifdef USE_NANOSLEEP struct timespec rqtp; rqtp.tv_sec = useconds / (unsigned long) 1000000; rqtp.tv_nsec = (useconds % (unsigned long) 1000000) * 1000 ; if (nanosleep(&rqtp, (struct timespec *) NULL) == -1) perror("nanosleep"); return (0); #elif USE_POOL struct pollfd unused; if (poll(&unused,0,(useconds/1000)) == -1) perror("poll"); return(0); #elif USE_USLEEP struct timeval delay; delay.tv_sec = 0; delay.tv_usec = useconds; if (select(0, (fd_set *) NULL, (fd_set *) NULL, (fd_set *) NULL, &delay) == -1) perror("select"); return (0); #endif /* USE_NANOSLEEP */