PikaPlatform_socket.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 pika_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 pika_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 pika_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 pika_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 pika_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 pika_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 pika_platform_recv(int __fd,
  58. void* __buf,
  59. size_t __n,
  60. int __flags) {
  61. #if defined(__linux__) || PIKA_LWIP_ENABLE
  62. return recv(__fd, __buf, __n, __flags);
  63. #else
  64. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  65. return -1;
  66. #endif
  67. }
  68. /* gethostname */
  69. PIKA_WEAK int pika_platform_gethostname(char* __name, size_t __len) {
  70. #if defined(__linux__)
  71. return gethostname(__name, __len);
  72. #else
  73. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  74. return -1;
  75. #endif
  76. }
  77. PIKA_WEAK int pika_platform_getaddrinfo(const char* __name,
  78. const char* __service,
  79. const struct addrinfo* __req,
  80. struct addrinfo** __pai) {
  81. #if defined(__linux__) || PIKA_LWIP_ENABLE
  82. return getaddrinfo(__name, __service, __req, __pai);
  83. #else
  84. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  85. #endif
  86. }
  87. PIKA_WEAK void pika_platform_freeaddrinfo(struct addrinfo* __ai) {
  88. #if defined(__linux__) || PIKA_LWIP_ENABLE
  89. freeaddrinfo(__ai);
  90. #else
  91. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  92. #endif
  93. }
  94. PIKA_WEAK int pika_platform_setsockopt(int __fd,
  95. int __level,
  96. int __optname,
  97. const void* __optval,
  98. socklen_t __optlen) {
  99. #if defined(__linux__) || PIKA_LWIP_ENABLE
  100. return setsockopt(__fd, __level, __optname, __optval, __optlen);
  101. #else
  102. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  103. #endif
  104. }
  105. PIKA_WEAK int pika_platform_fcntl(int fd, int cmd, long arg) {
  106. #if defined(__linux__) || PIKA_LWIP_ENABLE
  107. return fcntl(fd, cmd, arg);
  108. #else
  109. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  110. #endif
  111. }
  112. /* os file API */
  113. PIKA_WEAK int pika_platform_close(int __fd) {
  114. #if defined(__linux__) || PIKA_LWIP_ENABLE
  115. return close(__fd);
  116. #elif PIKA_FREERTOS_ENABLE
  117. return closesocket(__fd);
  118. #else
  119. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  120. #endif
  121. }
  122. PIKA_WEAK int pika_platform_write(int __fd, const void* __buf, size_t __nbyte) {
  123. #if defined(__linux__) || PIKA_LWIP_ENABLE
  124. return write(__fd, __buf, __nbyte);
  125. #else
  126. WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
  127. #endif
  128. }