af_inet_at.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * File : af_inet_at.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program 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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2018-06-06 ChenYong First version
  23. */
  24. #include <netdb.h>
  25. #include <sal.h>
  26. #include <at_socket.h>
  27. #include <af_inet.h>
  28. #ifdef SAL_USING_POSIX
  29. #include <dfs_poll.h>
  30. #endif
  31. #ifdef SAL_USING_POSIX
  32. static int at_poll(struct dfs_fd *file, struct rt_pollreq *req)
  33. {
  34. int mask = 0;
  35. struct at_socket *sock;
  36. struct sal_socket *sal_sock;
  37. sal_sock = sal_get_socket((int) file->data);
  38. if(!sal_sock)
  39. {
  40. return -1;
  41. }
  42. sock = at_get_socket((int)sal_sock->user_data);
  43. if (sock != NULL)
  44. {
  45. rt_base_t level;
  46. rt_poll_add(&sock->wait_head, req);
  47. level = rt_hw_interrupt_disable();
  48. if (sock->rcvevent)
  49. {
  50. mask |= POLLIN;
  51. }
  52. if (sock->sendevent)
  53. {
  54. mask |= POLLOUT;
  55. }
  56. if (sock->errevent)
  57. {
  58. mask |= POLLERR;
  59. }
  60. rt_hw_interrupt_enable(level);
  61. }
  62. return mask;
  63. }
  64. #endif
  65. static const struct proto_ops at_inet_stream_ops =
  66. {
  67. at_socket,
  68. at_closesocket,
  69. at_bind,
  70. NULL,
  71. at_connect,
  72. NULL,
  73. at_sendto,
  74. at_recvfrom,
  75. at_getsockopt,
  76. at_setsockopt,
  77. at_shutdown,
  78. NULL,
  79. NULL,
  80. NULL,
  81. #ifdef SAL_USING_POSIX
  82. at_poll,
  83. #else
  84. NULL,
  85. #endif /* SAL_USING_POSIX */
  86. };
  87. static int at_create(struct sal_socket *socket, int type, int protocol)
  88. {
  89. RT_ASSERT(socket);
  90. //TODO Check type & protocol
  91. socket->ops = &at_inet_stream_ops;
  92. return 0;
  93. }
  94. static const struct proto_family at_inet_family_ops = {
  95. "at",
  96. AF_AT,
  97. AF_INET,
  98. at_create,
  99. at_gethostbyname,
  100. NULL,
  101. at_freeaddrinfo,
  102. at_getaddrinfo,
  103. };
  104. int at_inet_init(void)
  105. {
  106. sal_proto_family_register(&at_inet_family_ops);
  107. return 0;
  108. }
  109. INIT_COMPONENT_EXPORT(at_inet_init);