nettype_tcp.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-15 13:38:52
  5. * @LastEditTime: 2020-05-25 10:13:41
  6. * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  7. */
  8. #include "nettype_tcp.h"
  9. #include "mqtt_log.h"
  10. #include "platform_net_socket.h"
  11. int nettype_tcp_read(network_t *n, unsigned char *read_buf, int len, int timeout)
  12. {
  13. return platform_net_socket_recv_timeout(n->socket, read_buf, len, timeout);
  14. }
  15. int nettype_tcp_write(network_t *n, unsigned char *write_buf, int len, int timeout)
  16. {
  17. return platform_net_socket_write_timeout(n->socket, write_buf, len, timeout);
  18. }
  19. int nettype_tcp_connect(network_t* n)
  20. {
  21. n->socket = platform_net_socket_connect(n->host, n->port, PLATFORM_NET_PROTO_TCP);
  22. if (n->socket < 0)
  23. RETURN_ERROR(n->socket);
  24. RETURN_ERROR(MQTT_SUCCESS_ERROR);
  25. }
  26. void nettype_tcp_disconnect(network_t* n)
  27. {
  28. if (NULL != n)
  29. platform_net_socket_close(n->socket);
  30. n->socket = -1;
  31. }