tarnsports函数中lwip_socket函数无定义
#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)
{
return -1;
}
server = lwip_getsockname(addr);
if(server == NULL)
{
lwip_close(MQTTSocket);
return -1;
}
memset(&serv_addr,0,sizeof(serv_addr));
serv_addr.sin_family = 2;
serv_addr.sin_port = htons(port);
//serv_addr.sin_addr.s_addr = inet_addr(addr);
memcpy(&serv_addr.sin_addr.s_addr,server->h_addr,server->h_length);
memset(&(serv_addr.sin_zero), 0, sizeof(serv_addr.sin_zero));
if (lwip_connect(MQTTSocket,(struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) == -1)
{
lwip_close(MQTTSocket);
return -1;
}
lwip_getsockopt(MQTTSocket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout,sizeof(timeout));
return MQTTSocket;
}
/*关闭传输函数*/
int transport_close(int sock)
{
int rc;
rc = lwip_shutdown(sock, SHUT_WR);
rc = lwip_recv(sock, NULL, (size_t)0, 0);
rc = lwip_close(sock);
return rc;
}
|