network.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-09 21:31:02
  5. * @LastEditTime: 2020-10-17 14:14:41
  6. * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  7. */
  8. #ifndef _NETWORK_H_
  9. #define _NETWORK_H_
  10. #include "mqtt_defconfig.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define NETWORK_CHANNEL_TCP 0
  15. #define NETWORK_CHANNEL_TLS 1
  16. typedef struct network {
  17. const char *host;
  18. const char *port;
  19. int socket;
  20. #ifndef MQTT_NETWORK_TYPE_NO_TLS
  21. int channel; /* tcp or tls */
  22. const char *ca_crt;
  23. unsigned int ca_crt_len;
  24. unsigned int timeout_ms; // SSL handshake timeout in millisecond
  25. void *nettype_tls_params;
  26. #endif
  27. } network_t;
  28. int network_init(network_t *n, const char *host, const char *port, const char *ca);
  29. int network_set_ca(network_t *n, const char *ca);
  30. void network_set_channel(network_t *n, int channel);
  31. int network_set_host_port(network_t* n, char *host, char *port);
  32. int network_read(network_t* n, unsigned char* buf, int len, int timeout);
  33. int network_write(network_t* n, unsigned char* buf, int len, int timeout);
  34. int network_connect(network_t* n);
  35. void network_disconnect(network_t *n);
  36. void network_release(network_t* n);
  37. #ifdef __cplusplus
  38. }
  39. #endif
  40. #endif