mqtt client release v1.1.0 ...

This commit is contained in:
jiejietop
2020-06-18 19:49:14 +08:00
parent 0202c5b5c9
commit cd2368dbeb
241 changed files with 117626 additions and 1584 deletions

View File

@@ -2,7 +2,7 @@
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2020-01-10 23:45:59
* @LastEditTime: 2020-04-25 18:59:28
* @LastEditTime: 2020-04-25 17:54:44
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#include "platform_net_socket.h"
@@ -45,7 +45,7 @@ int platform_net_socket_connect(const char *host, const char *port, int proto)
break;
}
close(fd);
platform_net_socket_close(fd);
ret = MQTT_CONNECT_FAILED_ERROR;
}
@@ -69,30 +69,35 @@ int platform_net_socket_recv_timeout(int fd, unsigned char *buf, int len, int ti
#ifdef MQTT_NETSOCKET_USE_AT
return tos_sal_module_recv_timeout(fd, buf, len, timeout);
#else
int rc;
int bytes = 0;
struct timeval tv = {
int nread;
int nleft = len;
unsigned char *ptr;
ptr = buf;
struct timeval tv = {
timeout / 1000,
(timeout % 1000) * 1000
};
if (tv.tv_sec < 0 || (tv.tv_sec == 0 && tv.tv_usec <= 0)) {
tv.tv_sec = 0;
tv.tv_usec = 100;
}
if (tv.tv_sec < 0 || (tv.tv_sec == 0 && tv.tv_usec <= 0)) {
tv.tv_sec = 0;
tv.tv_usec = 100;
}
platform_net_socket_setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval));
platform_net_socket_setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval));
while (bytes < len) {
rc = platform_net_socket_recv(fd, &buf[bytes], (size_t)(len - bytes), 0);
if (rc <= 0) {
bytes = rc;
break;
} else {
bytes += rc;
}
}
return bytes;
while (nleft > 0) {
nread = platform_net_socket_recv(fd, ptr, nleft, 0);
if (nread < 0) {
return -1;
} else if (nread == 0) {
break;
}
nleft -= nread;
ptr += nread;
}
return len - nleft;
#endif
}
@@ -110,17 +115,17 @@ int platform_net_socket_write_timeout(int fd, unsigned char *buf, int len, int t
#ifdef MQTT_NETSOCKET_USE_AT
return tos_sal_module_send(fd, buf, len);
#else
struct timeval tv = {
struct timeval tv = {
timeout / 1000,
(timeout % 1000) * 1000
};
if (tv.tv_sec < 0 || (tv.tv_sec == 0 && tv.tv_usec <= 0)) {
tv.tv_sec = 0;
tv.tv_usec = 100;
}
if (tv.tv_sec < 0 || (tv.tv_sec == 0 && tv.tv_usec <= 0)) {
tv.tv_sec = 0;
tv.tv_usec = 100;
}
platform_net_socket_setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv,sizeof(struct timeval));
platform_net_socket_setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv,sizeof(struct timeval));
return write(fd, buf, len);
#endif

View File

@@ -2,14 +2,14 @@
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-15 13:39:00
* @LastEditTime: 2020-02-19 01:02:51
* @LastEditTime: 2020-04-27 23:46:35
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#ifndef _PLATFORM_NET_SOCKET_H_
#define _PLATFORM_NET_SOCKET_H_
#include "network.h"
#include "error.h"
#include "mqtt_error.h"
#ifdef MQTT_NETSOCKET_USE_AT

View File

@@ -1,39 +0,0 @@
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-15 13:38:52
* @LastEditTime : 2020-02-16 02:22:48
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#include "platform_nettype_tcp.h"
#include "log.h"
int platform_nettype_tcp_read(network_t *n, unsigned char *read_buf, int len, int timeout)
{
return platform_net_socket_recv_timeout(n->socket, read_buf, len, timeout);
}
int platform_nettype_tcp_write(network_t *n, unsigned char *write_buf, int len, int timeout)
{
return platform_net_socket_write_timeout(n->socket, write_buf, len, timeout);
}
int platform_nettype_tcp_connect(network_t* n)
{
if (n->socket >= 0) {
platform_net_socket_close(n->socket); // prevent opening too many fd descriptors
}
n->socket = platform_net_socket_connect(n->network_params.addr, n->network_params.port, PLATFORM_NET_PROTO_TCP);
if (n->socket < 0)
RETURN_ERROR(n->socket);
RETURN_ERROR(MQTT_SUCCESS_ERROR);
}
void platform_nettype_tcp_disconnect(network_t* n)
{
if (NULL != n)
platform_net_socket_close(n->socket);
n->socket = -1;
}

View File

@@ -1,20 +0,0 @@
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-15 13:39:00
* @LastEditTime : 2020-01-10 23:48:41
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#ifndef _PLATFORM_NETTYPE_TCP_H_
#define _PLATFORM_NETTYPE_TCP_H_
#include "platform_net_socket.h"
#include "network.h"
#include "error.h"
int platform_nettype_tcp_read(network_t *n, unsigned char *buf, int len, int timeout);
int platform_nettype_tcp_write(network_t *n, unsigned char *buf, int len, int timeout);
int platform_nettype_tcp_connect(network_t* n);
void platform_nettype_tcp_disconnect(network_t* n);
#endif

View File

@@ -1,292 +0,0 @@
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2020-01-11 19:45:35
* @LastEditTime: 2020-03-05 23:52:30
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#include "platform_nettype_tls.h"
#include "platform_net_socket.h"
#include "platform_memory.h"
#include "platform_timer.h"
#include "random.h"
#ifdef MQTT_NETWORK_TYPE_TLS
#include "mbedtls/platform.h"
#include "mbedtls/ssl.h"
#include "mbedtls/entropy.h"
#include "mbedtls/net_sockets.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/error.h"
#include "mbedtls/debug.h"
#include "mbedtls\x509_crt.h"
#include "mbedtls\pk.h"
#if !defined(MBEDTLS_FS_IO)
static const int ciphersuites[] = { MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA, 0 };
#endif
#if defined(MBEDTLS_X509_CRT_PARSE_C)
static int server_certificate_verify(void *hostname, mbedtls_x509_crt *crt, int depth, uint32_t *flags)
{
if (0 != *flags)
LOG_E("%s:%d %s()... server_certificate_verify failed returned 0x%04x\n", __FILE__, __LINE__, __FUNCTION__, *flags);
return *flags;
}
#endif
static int platform_nettype_tls_entropy_source(void *data, uint8_t *output, size_t len, size_t *out_len)
{
uint32_t seed;
(void) data;
seed = random_number();
if (len > sizeof(seed)) {
len = sizeof(seed);
}
memcpy(output, &seed, len);
*out_len = len;
return 0;
}
static int platform_nettype_tls_init(network_t* n, nettype_tls_params_t* nettype_tls_params)
{
int rc = MQTT_SUCCESS_ERROR;
mbedtls_platform_set_calloc_free(platform_memory_calloc, platform_memory_free);
mbedtls_net_init(&(nettype_tls_params->socket_fd));
mbedtls_ssl_init(&(nettype_tls_params->ssl));
mbedtls_ssl_config_init(&(nettype_tls_params->ssl_conf));
mbedtls_ctr_drbg_init(&(nettype_tls_params->ctr_drbg));
#if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt_init(&(nettype_tls_params->ca_cert));
mbedtls_x509_crt_init(&(nettype_tls_params->client_cert));
mbedtls_pk_init(&(nettype_tls_params->private_key));
#endif
mbedtls_entropy_init(&(nettype_tls_params->entropy));
mbedtls_entropy_add_source(&(nettype_tls_params->entropy), platform_nettype_tls_entropy_source, NULL, MBEDTLS_ENTROPY_MAX_GATHER, MBEDTLS_ENTROPY_SOURCE_STRONG);
if ((rc = mbedtls_ctr_drbg_seed(&(nettype_tls_params->ctr_drbg), mbedtls_entropy_func,
&(nettype_tls_params->entropy), NULL, 0)) != 0) {
LOG_E("mbedtls_ctr_drbg_seed failed returned 0x%04x", (rc < 0 )? -rc : rc);
RETURN_ERROR(rc);
}
if ((rc = mbedtls_ssl_config_defaults(&(nettype_tls_params->ssl_conf), MBEDTLS_SSL_IS_CLIENT,
MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
LOG_E("mbedtls_ssl_config_defaults failed returned 0x%04x", (rc < 0 )? -rc : rc);
RETURN_ERROR(rc);
}
mbedtls_ssl_conf_rng(&(nettype_tls_params->ssl_conf), mbedtls_ctr_drbg_random, &(nettype_tls_params->ctr_drbg));
#if defined(MBEDTLS_X509_CRT_PARSE_C)
if (NULL != n->network_params.network_ssl_params.ca_crt) {
n->network_params.network_ssl_params.ca_crt_len = strlen(n->network_params.network_ssl_params.ca_crt);
if (0 != (rc = (mbedtls_x509_crt_parse(&(nettype_tls_params->ca_cert), (unsigned char *)n->network_params.network_ssl_params.ca_crt,
(n->network_params.network_ssl_params.ca_crt_len + 1))))) {
LOG_E("%s:%d %s()... parse ca crt failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
RETURN_ERROR(rc);
}
}
mbedtls_ssl_conf_ca_chain(&(nettype_tls_params->ssl_conf), &(nettype_tls_params->ca_cert), NULL);
if ((rc = mbedtls_ssl_conf_own_cert(&(nettype_tls_params->ssl_conf),
&(nettype_tls_params->client_cert), &(nettype_tls_params->private_key))) != 0) {
LOG_E("%s:%d %s()... mbedtls_ssl_conf_own_cert failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
RETURN_ERROR(rc);
}
mbedtls_ssl_conf_verify(&(nettype_tls_params->ssl_conf), server_certificate_verify, (void *)n->network_params.addr);
mbedtls_ssl_conf_authmode(&(nettype_tls_params->ssl_conf), MBEDTLS_SSL_VERIFY_REQUIRED);
#endif
#if defined(MBEDTLS_FS_IO)
if (n->network_params.network_ssl_params.cert_file != NULL && n->network_params.network_ssl_params.key_file != NULL) {
if ((rc = mbedtls_x509_crt_parse_file(&(nettype_tls_params->client_cert), n->network_params.network_ssl_params.cert_file)) != 0) {
LOG_E("%s:%d %s()... load client cert file failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
return MQTT_SSL_CERT_ERROR;
}
if ((rc = mbedtls_pk_parse_keyfile(&(nettype_tls_params->private_key), n->network_params.network_ssl_params.key_file, "")) != 0) {
LOG_E("%s:%d %s()... load client key file failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
return MQTT_SSL_CERT_ERROR;
}
} else {
LOG_I("%s:%d %s()... cert_file/key_file is empty! | cert_file = %s | key_file = %s", __FILE__, __LINE__, __FUNCTION__,
n->network_params.network_ssl_params.cert_file, n->network_params.network_ssl_params.key_file);
}
#else
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
if (n->network_params.network_ssl_params.psk != NULL && n->network_params.network_ssl_params.psk_id !=NULL) {
const char *psk_id = n->network_params.network_ssl_params.psk_id;
rc = mbedtls_ssl_conf_psk(&(nettype_tls_params->ssl_conf), (unsigned char *)n->network_params.network_ssl_params.psk,
n->network_params.network_ssl_params.psk_length, (const unsigned char *) psk_id, strlen( psk_id ));
mbedtls_ssl_conf_ciphersuites(&(nettype_tls_params->ssl_conf), ciphersuites);
if (0 != rc) {
LOG_E("%s:%d %s()... mbedtls_ssl_conf_psk fail: 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
return rc;
}
}
#endif
#endif
mbedtls_ssl_conf_read_timeout(&(nettype_tls_params->ssl_conf), n->network_params.network_ssl_params.timeout_ms);
if ((rc = mbedtls_ssl_setup(&(nettype_tls_params->ssl), &(nettype_tls_params->ssl_conf))) != 0) {
LOG_E("mbedtls_ssl_setup failed returned 0x%04x", (rc < 0 )? -rc : rc);
RETURN_ERROR(rc);
}
#if defined(MBEDTLS_X509_CRT_PARSE_C)
if ((rc = mbedtls_ssl_set_hostname(&(nettype_tls_params->ssl), n->network_params.addr)) != 0) {
LOG_E("%s:%d %s()... mbedtls_ssl_set_hostname failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
RETURN_ERROR(rc);
}
#endif
mbedtls_ssl_set_bio(&(nettype_tls_params->ssl), &(nettype_tls_params->socket_fd), mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout);
RETURN_ERROR(MQTT_SUCCESS_ERROR);
}
int platform_nettype_tls_connect(network_t* n)
{
int rc;
if (NULL == n)
RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
nettype_tls_params_t *nettype_tls_params = (nettype_tls_params_t *) platform_memory_alloc(sizeof(nettype_tls_params_t));
if (NULL == nettype_tls_params)
RETURN_ERROR(MQTT_MEM_NOT_ENOUGH_ERROR);
rc = platform_nettype_tls_init(n, nettype_tls_params);
if (MQTT_SUCCESS_ERROR != rc)
goto exit;
if (0 != (rc = mbedtls_net_connect(&(nettype_tls_params->socket_fd), n->network_params.addr, n->network_params.port, MBEDTLS_NET_PROTO_TCP)))
goto exit;
while ((rc = mbedtls_ssl_handshake(&(nettype_tls_params->ssl))) != 0) {
if (rc != MBEDTLS_ERR_SSL_WANT_READ && rc != MBEDTLS_ERR_SSL_WANT_WRITE) {
LOG_E("%s:%d %s()...mbedtls handshake failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
#if defined(MBEDTLS_X509_CRT_PARSE_C)
if (rc == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) {
LOG_E("%s:%d %s()...unable to verify the server's certificate", __FILE__, __LINE__, __FUNCTION__);
}
#endif
goto exit;
}
}
if ((rc = mbedtls_ssl_get_verify_result(&(nettype_tls_params->ssl))) != 0) {
LOG_E("%s:%d %s()...mbedtls_ssl_get_verify_result returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
goto exit;
}
n->network_params.nettype_tls_params = nettype_tls_params;
RETURN_ERROR(MQTT_SUCCESS_ERROR)
exit:
platform_memory_free(nettype_tls_params);
RETURN_ERROR(rc);
}
void platform_nettype_tls_disconnect(network_t* n)
{
int rc = 0;
if (NULL == n)
return;
nettype_tls_params_t *nettype_tls_params = (nettype_tls_params_t *) n->network_params.nettype_tls_params;
do {
rc = mbedtls_ssl_close_notify(&(nettype_tls_params->ssl));
} while (rc == MBEDTLS_ERR_SSL_WANT_READ || rc == MBEDTLS_ERR_SSL_WANT_WRITE);
mbedtls_net_free(&(nettype_tls_params->socket_fd));
#if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt_free(&(nettype_tls_params->client_cert));
mbedtls_x509_crt_free(&(nettype_tls_params->ca_cert));
mbedtls_pk_free(&(nettype_tls_params->private_key));
#endif
mbedtls_ssl_free(&(nettype_tls_params->ssl));
mbedtls_ssl_config_free(&(nettype_tls_params->ssl_conf));
mbedtls_ctr_drbg_free(&(nettype_tls_params->ctr_drbg));
mbedtls_entropy_free(&(nettype_tls_params->entropy));
platform_memory_free(nettype_tls_params);
}
int platform_nettype_tls_write(network_t *n, unsigned char *buf, int len, int timeout)
{
int rc = 0;
int write_len = 0;
platform_timer_t timer;
if (NULL == n)
RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
nettype_tls_params_t *nettype_tls_params = (nettype_tls_params_t *) n->network_params.nettype_tls_params;
platform_timer_init(&timer);
platform_timer_cutdown(&timer, timeout);
do {
rc = mbedtls_ssl_write(&(nettype_tls_params->ssl), (unsigned char *)(buf + write_len), len - write_len);
if (rc > 0) {
write_len += rc;
} else if ((rc == 0) || ((rc != MBEDTLS_ERR_SSL_WANT_WRITE) && (rc != MBEDTLS_ERR_SSL_WANT_READ) && (rc != MBEDTLS_ERR_SSL_TIMEOUT))) {
LOG_E("%s:%d %s()... mbedtls_ssl_write failed: 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
break;
}
} while((!platform_timer_is_expired(&timer)) && (write_len < len));
return write_len;
}
int platform_nettype_tls_read(network_t *n, unsigned char *buf, int len, int timeout)
{
int rc = 0;
int read_len = 0;
platform_timer_t timer;
if (NULL == n)
RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
nettype_tls_params_t *nettype_tls_params = (nettype_tls_params_t *) n->network_params.nettype_tls_params;
platform_timer_init(&timer);
platform_timer_cutdown(&timer, timeout);
do {
rc = mbedtls_ssl_read(&(nettype_tls_params->ssl), (unsigned char *)(buf + read_len), len - read_len);
if (rc > 0) {
read_len += rc;
} else if ((rc == 0) || ((rc != MBEDTLS_ERR_SSL_WANT_WRITE) && (rc != MBEDTLS_ERR_SSL_WANT_READ) && (rc != MBEDTLS_ERR_SSL_TIMEOUT))) {
// LOG_E("%s:%d %s()... mbedtls_ssl_read failed: 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
break;
}
} while((!platform_timer_is_expired(&timer)) && (read_len < len));
return read_len;
}
#endif /* MQTT_NETWORK_TYPE_TLS */

View File

@@ -1,40 +0,0 @@
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2020-01-11 19:45:44
* @LastEditTime: 2020-02-25 03:51:37
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#ifndef _PLATFORM_NETTYPE_TLS_H_
#define _PLATFORM_NETTYPE_TLS_H_
#include "platform_net_socket.h"
#include "mqtt_defconfig.h"
#include "network.h"
#include "error.h"
#include "log.h"
#ifdef MQTT_NETWORK_TYPE_TLS
typedef struct nettype_tls_params {
mbedtls_net_context socket_fd; /**< mbed TLS network context. */
mbedtls_entropy_context entropy; /**< mbed TLS entropy. */
mbedtls_ctr_drbg_context ctr_drbg; /**< mbed TLS ctr_drbg. */
mbedtls_ssl_context ssl; /**< mbed TLS control context. */
mbedtls_ssl_config ssl_conf; /**< mbed TLS configuration context. */
#if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt ca_cert; /**< mbed TLS CA certification. */
mbedtls_x509_crt client_cert; /**< mbed TLS Client certification. */
#endif
mbedtls_pk_context private_key; /**< mbed TLS Client key. */
} nettype_tls_params_t;
int platform_nettype_tls_read(network_t *n, unsigned char *buf, int len, int timeout);
int platform_nettype_tls_write(network_t *n, unsigned char *buf, int len, int timeout);
int platform_nettype_tls_connect(network_t* n);
void platform_nettype_tls_disconnect(network_t* n);
#endif /* MQTT_NETWORK_TYPE_TLS */
#endif

View File

@@ -18,18 +18,18 @@ platform_thread_t *platform_thread_init( const char *name,
platform_thread_t *thread;
k_err_t err;
k_stack_t *thread_stack;
thread = platform_memory_calloc(1, sizeof(platform_thread_t));
thread = platform_memory_alloc(sizeof(platform_thread_t));
thread_stack = (k_stack_t*) platform_memory_alloc(stack_size);
err = tos_task_create(&(thread->thread),
(char*)name,
err = tos_task_create(&(thread->thread),
(char*)name,
entry,
param,
priority,
param,
priority,
thread_stack,
stack_size,
tick);
if(err != K_ERR_NONE) {
platform_memory_free(thread);
platform_memory_free(thread_stack);

View File

@@ -2,7 +2,7 @@
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-10 22:16:41
* @LastEditTime : 2020-01-11 01:19:35
* @LastEditTime: 2020-04-27 22:37:33
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
@@ -58,9 +58,13 @@ void platform_timer_usleep(unsigned long usec)
uint32_t ms;
k_tick_t tick;
ms = usec / 1000;
if (ms == 0) {
ms = 1;
if(usec != 0) {
ms = usec / TOS_CFG_CPU_TICK_PER_SECOND;
if (ms == 0) {
ms = 1;
}
}
tick = tos_millisec2tick(ms);

View File

@@ -0,0 +1,3 @@
# 注意
如果用的是AT模组可以结合TencentOS tiny的AT框架与SAL层使用platform_net_socket.c替换原有BSD socket 接口即可。

View File

@@ -0,0 +1,47 @@
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2020-01-10 23:45:59
* @LastEditTime : 2020-01-13 02:48:53
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#include "platform_net_socket.h"
int platform_net_socket_connect(const char *host, const char *port, int proto)
{
int fd;
fd = tos_sal_module_connect(host, port, TOS_SAL_PROTO_TCP);
if (fd < 0) {
return MQTT_CONNECT_FAILED_ERROR;
}
return fd;
}
int platform_net_socket_recv(int fd, void *buf, size_t len, int flags)
{
return tos_sal_module_recv(fd, buf, len);
}
int platform_net_socket_recv_timeout(int fd, unsigned char *buf, int len, int timeout)
{
return tos_sal_module_recv_timeout(fd, buf, len, timeout);
}
int platform_net_socket_write(int fd, void *buf, size_t len)
{
return tos_sal_module_send(fd, buf, len);
}
int platform_net_socket_write_timeout(int fd, unsigned char *buf, int len, int timeout)
{
return tos_sal_module_send(fd, buf, len);
}
int platform_net_socket_close(int fd)
{
return tos_sal_module_close(fd);
}

View File

@@ -0,0 +1,25 @@
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-15 13:39:00
* @LastEditTime: 2020-02-19 01:02:51
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#ifndef _PLATFORM_NET_SOCKET_H_
#define _PLATFORM_NET_SOCKET_H_
#include "network.h"
#include "mqtt_error.h"
#include "stddef.h"
#define PLATFORM_NET_PROTO_TCP 0 /**< The TCP transport protocol */
#define PLATFORM_NET_PROTO_UDP 1 /**< The UDP transport protocol */
int platform_net_socket_connect(const char *host, const char *port, int proto);
int platform_net_socket_recv(int fd, void *buf, size_t len, int flags);
int platform_net_socket_recv_timeout(int fd, unsigned char *buf, int len, int timeout);
int platform_net_socket_write(int fd, void *buf, size_t len);
int platform_net_socket_write_timeout(int fd, unsigned char *buf, int len, int timeout);
int platform_net_socket_close(int fd);
#endif /* _PLATFORM_NET_SOCKET_H_ */