af_inet_at.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #ifdef SAL_USING_POSIX
  28. #include <dfs_poll.h>
  29. #endif
  30. #ifdef SAL_USING_POSIX
  31. static int at_poll(struct dfs_fd *file, struct rt_pollreq *req)
  32. {
  33. int mask = 0;
  34. struct at_socket *sock;
  35. struct sal_socket *sal_sock;
  36. sal_sock = sal_get_socket((int) file->data);
  37. if(!sal_sock)
  38. {
  39. return -1;
  40. }
  41. sock = at_get_socket((int)sal_sock->user_data);
  42. if (sock != NULL)
  43. {
  44. rt_base_t level;
  45. rt_poll_add(&sock->wait_head, req);
  46. level = rt_hw_interrupt_disable();
  47. if (sock->rcvevent)
  48. {
  49. mask |= POLLIN;
  50. }
  51. if (sock->sendevent)
  52. {
  53. mask |= POLLOUT;
  54. }
  55. if (sock->errevent)
  56. {
  57. mask |= POLLERR;
  58. }
  59. rt_hw_interrupt_enable(level);
  60. }
  61. return mask;
  62. }
  63. #endif
  64. static const struct proto_ops at_inet_stream_ops =
  65. {
  66. at_socket,
  67. at_closesocket,
  68. at_bind,
  69. NULL,
  70. at_connect,
  71. NULL,
  72. at_sendto,
  73. at_recvfrom,
  74. at_getsockopt,
  75. at_setsockopt,
  76. at_shutdown,
  77. NULL,
  78. NULL,
  79. NULL,
  80. #ifdef SAL_USING_POSIX
  81. at_poll,
  82. #else
  83. NULL,
  84. #endif /* SAL_USING_POSIX */
  85. };
  86. static int at_create(struct sal_socket *socket, int type, int protocol)
  87. {
  88. RT_ASSERT(socket);
  89. //TODO Check type & protocol
  90. socket->ops = &at_inet_stream_ops;
  91. return 0;
  92. }
  93. static const struct proto_family at_inet_family_ops = {
  94. AF_AT,
  95. AF_INET,
  96. at_create,
  97. at_gethostbyname,
  98. NULL,
  99. at_freeaddrinfo,
  100. at_getaddrinfo,
  101. };
  102. int at_inet_init(void)
  103. {
  104. sal_proto_family_register(&at_inet_family_ops);
  105. return 0;
  106. }
  107. INIT_COMPONENT_EXPORT(at_inet_init);