1 /* 2 * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 */ 4 5 #ifndef _INFRA_NET_H_ 6 #define _INFRA_NET_H_ 7 8 #include "linkkit/infra/infra_types.h" 9 10 /** 11 * @brief The structure of network connection(TCP or SSL). 12 * The user has to allocate memory for this structure. 13 */ 14 15 struct utils_network; 16 typedef struct utils_network utils_network_t, *utils_network_pt; 17 18 struct utils_network { 19 const char *pHostAddress; 20 uint16_t port; 21 uint16_t ca_crt_len; 22 23 /**< NULL, TCP connection; NOT NULL, SSL connection */ 24 const char *ca_crt; 25 /**< NOT NULL,iTLS connection*/ 26 char *product_key; 27 /**< connection handle: 0, NOT connection; NOT 0, handle of the connection 28 */ 29 uintptr_t handle; 30 31 /**< Read data from server function pointer. */ 32 int (*read)(utils_network_pt, char *, uint32_t, uint32_t); 33 34 /**< Send data to server function pointer. */ 35 int (*write)(utils_network_pt, const char *, uint32_t, uint32_t); 36 37 /**< Disconnect the network */ 38 int (*disconnect)(utils_network_pt); 39 40 /**< Establish the network */ 41 int (*connect)(utils_network_pt); 42 }; 43 44 int utils_net_read(utils_network_pt pNetwork, char *buffer, uint32_t len, 45 uint32_t timeout_ms); 46 int utils_net_write(utils_network_pt pNetwork, const char *buffer, uint32_t len, 47 uint32_t timeout_ms); 48 int iotx_net_disconnect(utils_network_pt pNetwork); 49 int iotx_net_connect(utils_network_pt pNetwork); 50 int iotx_net_init(utils_network_pt pNetwork, const char *host, uint16_t port, 51 const char *ca_crt); 52 53 #endif /* IOTX_COMMON_NET_H */ 54