convert usleep to nanosleep

usleep is removed in POSIX 2008.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
pull/249/head
Rosen Penev 2020-10-11 22:00:32 -07:00
parent 18573d1dd2
commit d7df79e687
No known key found for this signature in database
GPG Key ID: 36D31CFA845F0E3B
3 changed files with 17 additions and 3 deletions

View File

@ -114,6 +114,7 @@
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
#include <time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
@ -180,8 +181,12 @@ int main(void)
saddr.sin_port = htons(PORT); saddr.sin_port = htons(PORT);
while(bind(sl,(struct sockaddr*)&saddr, sizeof(saddr)) < 0) { while(bind(sl,(struct sockaddr*)&saddr, sizeof(saddr)) < 0) {
struct timespec f = {
.tv_nsec = 100 * 1000 * 1000,
};
printf(".");fflush(NULL); printf(".");fflush(NULL);
usleep(100000); nanosleep(&f, NULL);
} }
if (listen(sl,3) != 0) { if (listen(sl,3) != 0) {

View File

@ -281,8 +281,12 @@ int main(int argc, char **argv)
inaddr.sin_port = htons(port); inaddr.sin_port = htons(port);
while(bind(socki, (struct sockaddr*)&inaddr, sizeof(inaddr)) < 0) { while(bind(socki, (struct sockaddr*)&inaddr, sizeof(inaddr)) < 0) {
struct timespec f = {
.tv_nsec = 100 * 1000 * 1000,
};
printf(".");fflush(NULL); printf(".");fflush(NULL);
usleep(100000); nanosleep(&f, NULL);
} }
if (listen(socki, 3) != 0) { if (listen(socki, 3) != 0) {

View File

@ -64,6 +64,7 @@
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
#include <time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
@ -299,9 +300,13 @@ int main(int argc, char **argv)
saddr.sin_port = htons(local_port); saddr.sin_port = htons(local_port);
while(bind(sl,(struct sockaddr*)&saddr, sizeof(saddr)) < 0) { while(bind(sl,(struct sockaddr*)&saddr, sizeof(saddr)) < 0) {
struct timespec f = {
.tv_nsec = 100 * 1000 * 1000,
};
printf("."); printf(".");
fflush(NULL); fflush(NULL);
usleep(100000); nanosleep(&f, NULL);
} }
if (listen(sl, 3) != 0) { if (listen(sl, 3) != 0) {