Skip to content

Commit 072bcf1

Browse files
committed
replace deprecated usleep with nanosleep
1 parent 29d9818 commit 072bcf1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

test/wh_test_comm.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
#if defined(WOLFHSM_CFG_TEST_POSIX)
4545
#include <pthread.h> /* For pthread_create/cancel/join/_t */
46-
#include <unistd.h> /* For usleep */
46+
#include <unistd.h> /* For nanosleep */
4747
#include "port/posix/posix_transport_tcp.h"
4848
#include "port/posix/posix_transport_shm.h"
4949
#endif
@@ -54,7 +54,8 @@
5454
#define REQ_SIZE 32
5555
#define RESP_SIZE 64
5656
#define REPEAT_COUNT 10
57-
#define ONE_MS 1000
57+
58+
const struct timespec ONE_MS = { .tv_sec = 0, .tv_nsec = 1000000 };
5859

5960
#if defined(WOLFHSM_CFG_ENABLE_CLIENT) && defined(WOLFHSM_CFG_ENABLE_SERVER)
6061
int whTest_CommMem(void)
@@ -239,7 +240,7 @@ static void* _whCommClientTask(void* cf)
239240
tx_req);
240241
}
241242
#endif
242-
} while ((ret == WH_ERROR_NOTREADY) && (usleep(ONE_MS) == 0));
243+
} while ((ret == WH_ERROR_NOTREADY) && (nanosleep(&ONE_MS, NULL) == 0));
243244

244245
if (ret != 0) {
245246
printf("Client had failure. Exiting\n");
@@ -260,7 +261,7 @@ static void* _whCommClientTask(void* cf)
260261
rx_resp);
261262
}
262263
#endif
263-
} while ((ret == WH_ERROR_NOTREADY) && (usleep(ONE_MS) == 0));
264+
} while ((ret == WH_ERROR_NOTREADY) && (nanosleep(&ONE_MS, NULL) == 0));
264265

265266
if (ret != 0) {
266267
printf("Client had failure. Exiting\n");
@@ -309,7 +310,7 @@ static void* _whCommServerTask(void* cf)
309310
rx_req);
310311
}
311312
#endif
312-
} while ((ret == WH_ERROR_NOTREADY) && (usleep(ONE_MS) == 0));
313+
} while ((ret == WH_ERROR_NOTREADY) && (nanosleep(&ONE_MS, NULL) == 0));
313314

314315
if (ret != 0) {
315316
printf("Server had failure. Exiting\n");
@@ -333,7 +334,7 @@ static void* _whCommServerTask(void* cf)
333334
tx_resp);
334335
}
335336
#endif
336-
} while ((ret == WH_ERROR_NOTREADY) && (usleep(ONE_MS) == 0));
337+
} while ((ret == WH_ERROR_NOTREADY) && (nanosleep(&ONE_MS, NULL) == 0));
337338

338339
if (ret != 0) {
339340
printf("Server had failure. Exiting\n");

0 commit comments

Comments
 (0)