windows-misc.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * libwebsockets - small server side websockets and web server implementation
  3. *
  4. * Copyright (C) 2010 - 2018 Andy Green <[email protected]>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation:
  9. * version 2.1 of the License.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19. * MA 02110-1301 USA
  20. */
  21. #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
  22. #define _WINSOCK_DEPRECATED_NO_WARNINGS
  23. #endif
  24. #include "core/private.h"
  25. uint64_t
  26. lws_time_in_microseconds()
  27. {
  28. #ifndef DELTA_EPOCH_IN_MICROSECS
  29. #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
  30. #endif
  31. FILETIME filetime;
  32. ULARGE_INTEGER datetime;
  33. #ifdef _WIN32_WCE
  34. GetCurrentFT(&filetime);
  35. #else
  36. GetSystemTimeAsFileTime(&filetime);
  37. #endif
  38. /*
  39. * As per Windows documentation for FILETIME, copy the resulting
  40. * FILETIME structure to a ULARGE_INTEGER structure using memcpy
  41. * (using memcpy instead of direct assignment can prevent alignment
  42. * faults on 64-bit Windows).
  43. */
  44. memcpy(&datetime, &filetime, sizeof(datetime));
  45. /* Windows file times are in 100s of nanoseconds. */
  46. return (datetime.QuadPart / 10) - DELTA_EPOCH_IN_MICROSECS;
  47. }
  48. #ifdef _WIN32_WCE
  49. time_t time(time_t *t)
  50. {
  51. time_t ret = lws_time_in_microseconds() / 1000000;
  52. if(t != NULL)
  53. *t = ret;
  54. return ret;
  55. }
  56. #endif
  57. LWS_VISIBLE int
  58. lws_get_random(struct lws_context *context, void *buf, int len)
  59. {
  60. int n;
  61. char *p = (char *)buf;
  62. for (n = 0; n < len; n++)
  63. p[n] = (unsigned char)rand();
  64. return n;
  65. }
  66. LWS_VISIBLE void
  67. lwsl_emit_syslog(int level, const char *line)
  68. {
  69. lwsl_emit_stderr(level, line);
  70. }
  71. int kill(int pid, int sig)
  72. {
  73. lwsl_err("Sorry Windows doesn't support kill().");
  74. exit(0);
  75. }
  76. int fork(void)
  77. {
  78. lwsl_err("Sorry Windows doesn't support fork().");
  79. exit(0);
  80. }
  81. int
  82. lws_plat_recommended_rsa_bits(void)
  83. {
  84. return 4096;
  85. }