#if !defined(SOCKET_ERROR)
/** error in socket operation */
#define SOCKET_ERROR -1
#endif
#define INVALID_SOCKET SOCKET_ERROR
#include "transport.h"
static int MQTTSocket = INVALID_SOCKET;
/*发包函数*/
int transport_sendPacketBuffer(int sock, unsigned char* buf, int buflen)
{
int rc = 0;
rc=lwip_write(sock,buf,buflen);
return rc;
}
int transport_getdata(unsigned char* buf, int count)
{
int rc = lwip_recv(MQTTSocket, buf, count, 0);
return rc;
}
/*获取数据函数*/
int transport_getdatanb(void *sck, unsigned char* buf, int count)
{
int sock = *((int *)sck); /* sck: pointer to whatever the system may use to identify the transport */
/* this call will return after the timeout set on initialization if no bytes;
in your system you will use whatever you use to get whichever outstanding
bytes your socket equivalent has ready to be extracted right now, if any,
or return immediately */
int rc = lwip_recv(sock, buf, count, 0);
if (rc == -1) {
/* check error conditions from your system here, and return -1 */
return 0;
}
return rc;
}
/*开启传输函数*/
int transport_open(char* addr, int port)
{
struct hostent *server;
struct sockaddr_in serv_addr;
int timeout = 1000;
MQTTSocket = lwip_socket(AF_INET, SOCK_STREAM, 0);
if (MQTTSocket < 0)
{