af_inet_at.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-06-06 ChenYong First version
  9. */
  10. #include <rtthread.h>
  11. #include <netdb.h>
  12. #include <sal.h>
  13. #include <at_socket.h>
  14. #include <af_inet.h>
  15. #ifdef SAL_USING_POSIX
  16. #include <dfs_poll.h>
  17. #endif
  18. #ifdef SAL_USING_POSIX
  19. static int at_poll(struct dfs_fd *file, struct rt_pollreq *req)
  20. {
  21. int mask = 0;
  22. struct at_socket *sock;
  23. struct sal_socket *sal_sock;
  24. sal_sock = sal_get_socket((int) file->data);
  25. if(!sal_sock)
  26. {
  27. return -1;
  28. }
  29. sock = at_get_socket((int)sal_sock->user_data);
  30. if (sock != NULL)
  31. {
  32. rt_base_t level;
  33. rt_poll_add(&sock->wait_head, req);
  34. level = rt_hw_interrupt_disable();
  35. if (sock->rcvevent)
  36. {
  37. mask |= POLLIN;
  38. }
  39. if (sock->sendevent)
  40. {
  41. mask |= POLLOUT;
  42. }
  43. if (sock->errevent)
  44. {
  45. mask |= POLLERR;
  46. }
  47. rt_hw_interrupt_enable(level);
  48. }
  49. return mask;
  50. }
  51. #endif
  52. static const struct proto_ops at_inet_stream_ops =
  53. {
  54. at_socket,
  55. at_closesocket,
  56. at_bind,
  57. NULL,
  58. at_connect,
  59. NULL,
  60. at_sendto,
  61. at_recvfrom,
  62. at_getsockopt,
  63. at_setsockopt,
  64. at_shutdown,
  65. NULL,
  66. NULL,
  67. NULL,
  68. #ifdef SAL_USING_POSIX
  69. at_poll,
  70. #endif /* SAL_USING_POSIX */
  71. };
  72. static int at_create(struct sal_socket *socket, int type, int protocol)
  73. {
  74. RT_ASSERT(socket);
  75. //TODO Check type & protocol
  76. socket->ops = &at_inet_stream_ops;
  77. return 0;
  78. }
  79. static const struct proto_family at_inet_family_ops = {
  80. "at",
  81. AF_AT,
  82. AF_INET,
  83. at_create,
  84. at_gethostbyname,
  85. NULL,
  86. at_freeaddrinfo,
  87. at_getaddrinfo,
  88. };
  89. int at_inet_init(void)
  90. {
  91. sal_proto_family_register(&at_inet_family_ops);
  92. return 0;
  93. }
  94. INIT_COMPONENT_EXPORT(at_inet_init);