unix-misc.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #define _GNU_SOURCE
  22. #include "core/private.h"
  23. uint64_t
  24. lws_time_in_microseconds(void)
  25. {
  26. struct timeval tv;
  27. gettimeofday(&tv, NULL);
  28. return ((unsigned long long)tv.tv_sec * 1000000LL) + tv.tv_usec;
  29. }
  30. LWS_VISIBLE int
  31. lws_get_random(struct lws_context *context, void *buf, int len)
  32. {
  33. return read(context->fd_random, (char *)buf, len);
  34. }
  35. LWS_VISIBLE void lwsl_emit_syslog(int level, const char *line)
  36. {
  37. int syslog_level = LOG_DEBUG;
  38. switch (level) {
  39. case LLL_ERR:
  40. syslog_level = LOG_ERR;
  41. break;
  42. case LLL_WARN:
  43. syslog_level = LOG_WARNING;
  44. break;
  45. case LLL_NOTICE:
  46. syslog_level = LOG_NOTICE;
  47. break;
  48. case LLL_INFO:
  49. syslog_level = LOG_INFO;
  50. break;
  51. }
  52. syslog(syslog_level, "%s", line);
  53. }
  54. int
  55. lws_plat_write_cert(struct lws_vhost *vhost, int is_key, int fd, void *buf,
  56. int len)
  57. {
  58. int n;
  59. n = write(fd, buf, len);
  60. fsync(fd);
  61. if (lseek(fd, 0, SEEK_SET) < 0)
  62. return 1;
  63. return n != len;
  64. }
  65. int
  66. lws_plat_recommended_rsa_bits(void)
  67. {
  68. return 4096;
  69. }