mqttclient supports at framework and add gokit3 board demo...
This commit is contained in:
@@ -10,6 +10,17 @@
|
||||
int platform_net_socket_connect(const char *host, const char *port, int proto)
|
||||
{
|
||||
int fd, ret = MQTT_SOCKET_UNKNOWN_HOST;
|
||||
#ifdef MQTT_NETSOCKET_USE_AT
|
||||
|
||||
fd = tos_sal_module_connect(host, port, TOS_SAL_PROTO_TCP);
|
||||
|
||||
if (fd < 0) {
|
||||
return MQTT_CONNECT_FAILED_ERROR;
|
||||
}
|
||||
ret = fd;
|
||||
|
||||
#else
|
||||
|
||||
struct addrinfo hints, *addr_list, *cur;
|
||||
|
||||
/* Do name resolution with both IPv6 and IPv4 */
|
||||
@@ -39,16 +50,25 @@ int platform_net_socket_connect(const char *host, const char *port, int proto)
|
||||
}
|
||||
|
||||
freeaddrinfo(addr_list);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int platform_net_socket_recv(int fd, void *buf, size_t len, int flags)
|
||||
{
|
||||
#ifdef MQTT_NETSOCKET_USE_AT
|
||||
return tos_sal_module_recv(fd, buf, len);
|
||||
#else
|
||||
return recv(fd, buf, len, flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
int platform_net_socket_recv_timeout(int fd, unsigned char *buf, int len, int timeout)
|
||||
{
|
||||
#ifdef MQTT_NETSOCKET_USE_AT
|
||||
return tos_sal_module_recv_timeout(fd, buf, len, timeout);
|
||||
#else
|
||||
int rc;
|
||||
int bytes = 0;
|
||||
struct timeval tv = {
|
||||
@@ -73,15 +93,23 @@ int platform_net_socket_recv_timeout(int fd, unsigned char *buf, int len, int ti
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
#endif
|
||||
}
|
||||
|
||||
int platform_net_socket_write(int fd, void *buf, size_t len)
|
||||
{
|
||||
#ifdef MQTT_NETSOCKET_USE_AT
|
||||
return tos_sal_module_send(fd, buf, len);
|
||||
#else
|
||||
return write(fd, buf, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
int platform_net_socket_write_timeout(int fd, unsigned char *buf, int len, int timeout)
|
||||
{
|
||||
#ifdef MQTT_NETSOCKET_USE_AT
|
||||
return tos_sal_module_send(fd, buf, len);
|
||||
#else
|
||||
struct timeval tv = {
|
||||
timeout / 1000,
|
||||
(timeout % 1000) * 1000
|
||||
@@ -95,13 +123,20 @@ int platform_net_socket_write_timeout(int fd, unsigned char *buf, int len, int t
|
||||
platform_net_socket_setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv,sizeof(struct timeval));
|
||||
|
||||
return write(fd, buf, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
int platform_net_socket_close(int fd)
|
||||
{
|
||||
#ifdef MQTT_NETSOCKET_USE_AT
|
||||
return tos_sal_module_close(fd);
|
||||
#else
|
||||
return close(fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef MQTT_NETSOCKET_USE_AT
|
||||
|
||||
int platform_net_socket_set_block(int fd)
|
||||
{
|
||||
return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, F_GETFL) & ~O_NONBLOCK);
|
||||
@@ -117,3 +152,4 @@ int platform_net_socket_setsockopt(int fd, int level, int optname, const void *o
|
||||
return setsockopt(fd, level, optname, optval, optlen);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -11,12 +11,20 @@
|
||||
#include "network.h"
|
||||
#include "error.h"
|
||||
|
||||
#ifdef MQTT_NETSOCKET_USE_AT
|
||||
|
||||
#include "sal_module_wrapper.h"
|
||||
|
||||
#else
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/api.h"
|
||||
#include <lwip/sockets.h>
|
||||
#include "lwip/netdb.h"
|
||||
|
||||
#endif
|
||||
|
||||
#define PLATFORM_NET_PROTO_TCP 0 /**< The TCP transport protocol */
|
||||
#define PLATFORM_NET_PROTO_UDP 1 /**< The UDP transport protocol */
|
||||
|
||||
@@ -26,8 +34,11 @@ int platform_net_socket_recv_timeout(int fd, unsigned char *buf, int len, int ti
|
||||
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);
|
||||
|
||||
#ifndef MQTT_NETSOCKET_USE_AT
|
||||
int platform_net_socket_set_block(int fd);
|
||||
int platform_net_socket_set_nonblock(int fd);
|
||||
int platform_net_socket_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen);
|
||||
#endif
|
||||
|
||||
#endif /* _PLATFORM_NET_SOCKET_H_ */
|
||||
|
Reference in New Issue
Block a user