windows-misc.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * libwebsockets - small server side websockets and web server implementation
  3. *
  4. * Copyright (C) 2010 - 2019 Andy Green <[email protected]>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to
  8. * deal in the Software without restriction, including without limitation the
  9. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. * sell copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  22. * IN THE SOFTWARE.
  23. */
  24. #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
  25. #define _WINSOCK_DEPRECATED_NO_WARNINGS
  26. #endif
  27. #include "private-lib-core.h"
  28. /*
  29. * Normally you don't want this, use lws_sul instead inside the event loop.
  30. * But sometimes for drivers it makes sense, so there's an internal-only
  31. * crossplatform api for it.
  32. */
  33. void
  34. lws_msleep(unsigned int ms)
  35. {
  36. Sleep(ms);
  37. }
  38. lws_usec_t
  39. lws_now_usecs(void)
  40. {
  41. #ifndef DELTA_EPOCH_IN_MICROSECS
  42. #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
  43. #endif
  44. FILETIME filetime;
  45. ULARGE_INTEGER datetime;
  46. #ifdef _WIN32_WCE
  47. GetCurrentFT(&filetime);
  48. #else
  49. GetSystemTimeAsFileTime(&filetime);
  50. #endif
  51. /*
  52. * As per Windows documentation for FILETIME, copy the resulting
  53. * FILETIME structure to a ULARGE_INTEGER structure using memcpy
  54. * (using memcpy instead of direct assignment can prevent alignment
  55. * faults on 64-bit Windows).
  56. */
  57. memcpy(&datetime, &filetime, sizeof(datetime));
  58. /* Windows file times are in 100s of nanoseconds. */
  59. return (datetime.QuadPart / 10) - DELTA_EPOCH_IN_MICROSECS;
  60. }
  61. #ifdef _WIN32_WCE
  62. time_t time(time_t *t)
  63. {
  64. time_t ret = lws_now_usecs() / 1000000;
  65. if(t != NULL)
  66. *t = ret;
  67. return ret;
  68. }
  69. #endif
  70. size_t
  71. lws_get_random(struct lws_context *context, void *buf, size_t len)
  72. {
  73. size_t n;
  74. char *p = (char *)buf;
  75. for (n = 0; n < len; n++)
  76. p[n] = (unsigned char)rand();
  77. return n;
  78. }
  79. void
  80. lwsl_emit_syslog(int level, const char *line)
  81. {
  82. lwsl_emit_stderr(level, line);
  83. }
  84. int kill(int pid, int sig)
  85. {
  86. lwsl_err("Sorry Windows doesn't support kill().");
  87. exit(0);
  88. }
  89. int fork(void)
  90. {
  91. lwsl_err("Sorry Windows doesn't support fork().");
  92. exit(0);
  93. }
  94. int
  95. lws_plat_recommended_rsa_bits(void)
  96. {
  97. return 4096;
  98. }