pahomqtt +wiz+W5500 发布数据较大,rtt就重启了
在下面这个函数发送一次失败后,数据就重启了。
int wiz_sendto(int socket, const void *data, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
{
struct wiz_socket *sock = RT_NULL;
uint8_t socket_state = 0;
int32_t send_len = 0;
int32_t send_pos=0;
/* check WIZnet ini
tialize status */
WIZ_INIT_STATUS_CHECK;
if (data == RT_NULL || size == 0)
{
LOG_E("WIZnet sendto input data or size error!");
return -1;
}
sock = wiz_get_socket(socket);
if (sock == RT_NULL)
{
return -1;
}
socket_state = getSn_SR(socket);
switch (sock->type)
{
case Sn_MR_TCP:
{
if (socket_state == SOCK_CLOSED)
{
return 0;
}
else if (socket_state != SOCK_ESTABLISHED)
{
LOG_E("WIZnet send failed, get socket(%d) register state(%d) error.", socket, socket_state);
return -1;
}
//ball 20200916 修改 如果超过sock单次发送最大数量2048则再接着发送
do{
send_len = wizchip_send(socket, (uint8_t *)data+send_pos, size-send_pos);
send_pos+=send_len;
if (send_len < 0)
{
LOG_E("WIZnet socket(%d) send data failed(%d).", socket, send_len);
return -1;
}
else if(send_pos!=size)
{
rt_kprintf("n ball send_len=%d size=%d send_pos=%dn",send_len,size,send_pos);
}
else
{
send_len=send_pos;
break;
}
}
while(1);
break;
}
case Sn_MR_UDP:
case Sn_MR_IPRAW:
{
ip_addr_t remote_addr;
uint16_t remote_port = 0;
uint8_t ipstr[4] = {0};
if (socket_state != SOCK_UDP && socket_state != SOCK_IPRAW)
{
LOG_E("WIZnet sendto failed, get socket(%d) register state(%d) error.", socket, socket_state);
return -1;
}
if (to)
{
socketaddr_to_ipaddr_port(to, &remote_addr, &remote_port);
ipaddr_to_ipstr(to, ipstr);
}
else if (sock->remote_addr)
{
socketaddr_to_ipaddr_port(sock->remote_addr, &remote_addr, &remote_port);
ipaddr_to_ipstr(sock->remote_addr, ipstr);
}
if ((send_len = wizchip_sendto(socket, (uint8_t *)data, size, ipstr, remote_port)) < 0)
{
LOG_E("WIZnet socket(%d) send data failed(%d).", socket, send_len);
return -1;
}
break;
}
default:
LOG_E("WIZnet socket (%d) type %d is not support.", socket, sock->type);
return -1;
}
return send_len;
}