af_inet_at.c 2.0 KB

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