PikaPlatform_socket.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "PikaPlatform_socket.h"
  2. /*
  3. The functinos start with PIKA_WEAK are weak functions,
  4. you need to override them in your platform.
  5. */
  6. PIKA_WEAK int __platform_socket(int __domain, int __type, int __protocol) {
  7. #if defined(__linux__) || PIKA_LWIP_ENABLE
  8. return socket(__domain, __type, __protocol);
  9. #else
  10. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  11. #endif
  12. }
  13. PIKA_WEAK int __platform_bind(int __fd,
  14. const struct sockaddr* __addr,
  15. socklen_t __addr_len) {
  16. #if defined(__linux__) || PIKA_LWIP_ENABLE
  17. return bind(__fd, __addr, __addr_len);
  18. #else
  19. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  20. #endif
  21. }
  22. PIKA_WEAK int __platform_listen(int __fd, int __n) {
  23. #if defined(__linux__) || PIKA_LWIP_ENABLE
  24. return listen(__fd, __n);
  25. #else
  26. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  27. #endif
  28. }
  29. PIKA_WEAK int __platform_accept(int __fd,
  30. struct sockaddr* __addr,
  31. socklen_t* __addr_len) {
  32. #if defined(__linux__) || PIKA_LWIP_ENABLE
  33. return accept(__fd, __addr, __addr_len);
  34. #else
  35. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  36. #endif
  37. }
  38. PIKA_WEAK int __platform_connect(int __fd,
  39. const struct sockaddr* __addr,
  40. socklen_t __addr_len) {
  41. #if defined(__linux__) || PIKA_LWIP_ENABLE
  42. return connect(__fd, __addr, __addr_len);
  43. #else
  44. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  45. #endif
  46. }
  47. PIKA_WEAK int __platform_send(int __fd,
  48. const void* __buf,
  49. size_t __n,
  50. int __flags) {
  51. #if defined(__linux__) || PIKA_LWIP_ENABLE
  52. return send(__fd, __buf, __n, __flags);
  53. #else
  54. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  55. #endif
  56. }
  57. PIKA_WEAK int __platform_recv(int __fd, void* __buf, size_t __n, int __flags) {
  58. #if defined(__linux__) || PIKA_LWIP_ENABLE
  59. return recv(__fd, __buf, __n, __flags);
  60. #else
  61. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  62. #endif
  63. }
  64. /* gethostname */
  65. PIKA_WEAK int __platform_gethostname(char* __name, size_t __len) {
  66. #if defined(__linux__)
  67. return gethostname(__name, __len);
  68. #else
  69. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  70. #endif
  71. }
  72. PIKA_WEAK int __platform_getaddrinfo(const char* __name,
  73. const char* __service,
  74. const struct addrinfo* __req,
  75. struct addrinfo** __pai) {
  76. #if defined(__linux__) || PIKA_LWIP_ENABLE
  77. return getaddrinfo(__name, __service, __req, __pai);
  78. #else
  79. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  80. #endif
  81. }
  82. PIKA_WEAK void __platform_freeaddrinfo(struct addrinfo* __ai) {
  83. #if defined(__linux__) || PIKA_LWIP_ENABLE
  84. freeaddrinfo(__ai);
  85. #else
  86. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  87. #endif
  88. }
  89. PIKA_WEAK int __platform_setsockopt(int __fd,
  90. int __level,
  91. int __optname,
  92. const void* __optval,
  93. socklen_t __optlen) {
  94. #if defined(__linux__) || PIKA_LWIP_ENABLE
  95. return setsockopt(__fd, __level, __optname, __optval, __optlen);
  96. #else
  97. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  98. #endif
  99. }
  100. PIKA_WEAK int __platform_fcntl(int fd, int cmd, long arg) {
  101. #ifdef __linux__
  102. return fcntl(fd, cmd, arg);
  103. #else
  104. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  105. #endif
  106. }
  107. /* os file API */
  108. PIKA_WEAK int __platform_close(int __fd) {
  109. #ifdef __linux__
  110. return close(__fd);
  111. #elif PIKA_FREERTOS_ENABLE
  112. return closesocket(__fd);
  113. #else
  114. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  115. #endif
  116. }
  117. PIKA_WEAK int __platform_write(int __fd, const void* __buf, size_t __nbyte) {
  118. #if defined(__linux__) || PIKA_LWIP_ENABLE
  119. return write(__fd, __buf, __nbyte);
  120. #else
  121. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  122. #endif
  123. }