nettype_tcp.c 1003 B

1234567891011121314151617181920212223242526272829303132333435
  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. int nettype_tcp_read(network_t *n, unsigned char *read_buf, int len, int timeout)
  11. {
  12. return platform_net_socket_recv_timeout(n->socket, read_buf, len, timeout);
  13. }
  14. int nettype_tcp_write(network_t *n, unsigned char *write_buf, int len, int timeout)
  15. {
  16. return platform_net_socket_write_timeout(n->socket, write_buf, len, timeout);
  17. }
  18. int nettype_tcp_connect(network_t* n)
  19. {
  20. n->socket = platform_net_socket_connect(n->host, n->port, PLATFORM_NET_PROTO_TCP);
  21. if (n->socket < 0)
  22. RETURN_ERROR(n->socket);
  23. RETURN_ERROR(MQTT_SUCCESS_ERROR);
  24. }
  25. void nettype_tcp_disconnect(network_t* n)
  26. {
  27. if (NULL != n)
  28. platform_net_socket_close(n->socket);
  29. n->socket = -1;
  30. }