You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.8 KiB

  1. From a346a4d0d732fdca306283c18b404679bbf40427 Mon Sep 17 00:00:00 2001
  2. From: Rosen Penev <rosenp@gmail.com>
  3. Date: Fri, 3 Apr 2020 17:51:45 -0700
  4. Subject: [PATCH] Do not use usleep when using newer POSIX C source.
  5. usleep is deprecated and is optionally unavailable with uClibc-ng.
  6. Signed-off-by: Rosen Penev <rosenp@gmail.com>
  7. (cherry picked from commit c91d82a7b74df3a08de2f94a1ec2a75a7803b6bd)
  8. ---
  9. upnp/inc/ithread.h | 10 +++++++++-
  10. upnp/src/genlib/miniserver/miniserver.c | 4 ++--
  11. 2 files changed, 11 insertions(+), 3 deletions(-)
  12. diff --git a/upnp/inc/ithread.h b/upnp/inc/ithread.h
  13. index 38aad3f..cc76440 100644
  14. --- a/upnp/inc/ithread.h
  15. +++ b/upnp/inc/ithread.h
  16. @@ -928,7 +928,15 @@ static UPNP_INLINE int ithread_cleanup_thread(void) {
  17. #ifdef _WIN32
  18. #define imillisleep Sleep
  19. #else
  20. - #define imillisleep(x) usleep(1000*x)
  21. +#if _POSIX_C_SOURCE < 200809L
  22. + #define imillisleep(x) usleep(1000 * x)
  23. +#else
  24. + #define imillisleep(x) \
  25. + do { \
  26. + const struct timespec req = {0, x * 1000 * 1000}; \
  27. + nanosleep(&req, NULL); \
  28. + } while(0)
  29. +#endif
  30. #endif
  31. diff --git a/upnp/src/genlib/miniserver/miniserver.c b/upnp/src/genlib/miniserver/miniserver.c
  32. index 9251d5b..31babd0 100644
  33. --- a/upnp/src/genlib/miniserver/miniserver.c
  34. +++ b/upnp/src/genlib/miniserver/miniserver.c
  35. @@ -905,7 +905,7 @@ int StartMiniServer(
  36. count = 0;
  37. while (gMServState != (MiniServerState)MSERV_RUNNING && count < max_count) {
  38. /* 0.05s */
  39. - usleep(50u * 1000u);
  40. + imillisleep(50);
  41. count++;
  42. }
  43. if (count >= max_count) {
  44. @@ -960,7 +960,7 @@ int StopMiniServer()
  45. ssdpAddr.sin_port = htons(miniStopSockPort);
  46. sendto(sock, buf, bufLen, 0,
  47. (struct sockaddr *)&ssdpAddr, socklen);
  48. - usleep(1000u);
  49. + imillisleep(1);
  50. if (gMServState == (MiniServerState)MSERV_IDLE) {
  51. break;
  52. }
  53. --
  54. 2.25.1