AsyncUDP: Added lastErr helper variable (#4789)
The variable is useful when debugging AsyncUDP send problems. The upper application can read and analyze the error reason.
This commit is contained in:
parent
e831680a41
commit
f13ff65691
@ -479,6 +479,7 @@ AsyncUDP::AsyncUDP()
|
||||
{
|
||||
_pcb = NULL;
|
||||
_connected = false;
|
||||
_lastErr = ERR_OK;
|
||||
_handler = NULL;
|
||||
}
|
||||
|
||||
@ -517,8 +518,8 @@ bool AsyncUDP::connect(const ip_addr_t *addr, uint16_t port)
|
||||
}
|
||||
close();
|
||||
UDP_MUTEX_LOCK();
|
||||
err_t err = _udp_connect(_pcb, addr, port);
|
||||
if(err != ERR_OK) {
|
||||
_lastErr = _udp_connect(_pcb, addr, port);
|
||||
if(_lastErr != ERR_OK) {
|
||||
UDP_MUTEX_UNLOCK();
|
||||
return false;
|
||||
}
|
||||
@ -646,7 +647,7 @@ size_t AsyncUDP::writeTo(const uint8_t * data, size_t len, const ip_addr_t * add
|
||||
if(len > CONFIG_TCP_MSS) {
|
||||
len = CONFIG_TCP_MSS;
|
||||
}
|
||||
err_t err = ERR_OK;
|
||||
_lastErr = ERR_OK;
|
||||
pbuf* pbt = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
|
||||
if(pbt != NULL) {
|
||||
uint8_t* dst = reinterpret_cast<uint8_t*>(pbt->payload);
|
||||
@ -656,16 +657,16 @@ size_t AsyncUDP::writeTo(const uint8_t * data, size_t len, const ip_addr_t * add
|
||||
void * nif = NULL;
|
||||
tcpip_adapter_get_netif((tcpip_adapter_if_t)tcpip_if, &nif);
|
||||
if(!nif){
|
||||
err = _udp_sendto(_pcb, pbt, addr, port);
|
||||
_lastErr = _udp_sendto(_pcb, pbt, addr, port);
|
||||
} else {
|
||||
err = _udp_sendto_if(_pcb, pbt, addr, port, (struct netif *)nif);
|
||||
_lastErr = _udp_sendto_if(_pcb, pbt, addr, port, (struct netif *)nif);
|
||||
}
|
||||
} else {
|
||||
err = _udp_sendto(_pcb, pbt, addr, port);
|
||||
_lastErr = _udp_sendto(_pcb, pbt, addr, port);
|
||||
}
|
||||
UDP_MUTEX_UNLOCK();
|
||||
pbuf_free(pbt);
|
||||
if(err < ERR_OK) {
|
||||
if(_lastErr < ERR_OK) {
|
||||
return 0;
|
||||
}
|
||||
return len;
|
||||
@ -870,6 +871,10 @@ bool AsyncUDP::connected()
|
||||
return _connected;
|
||||
}
|
||||
|
||||
esp_err_t AsyncUDP::lastErr() {
|
||||
return _lastErr;
|
||||
}
|
||||
|
||||
void AsyncUDP::onPacket(AuPacketHandlerFunctionWithArg cb, void * arg)
|
||||
{
|
||||
onPacket(std::bind(cb, arg, std::placeholders::_1));
|
||||
|
@ -95,6 +95,7 @@ protected:
|
||||
udp_pcb *_pcb;
|
||||
//xSemaphoreHandle _lock;
|
||||
bool _connected;
|
||||
esp_err_t _lastErr;
|
||||
AuPacketHandlerFunction _handler;
|
||||
|
||||
bool _init();
|
||||
@ -144,6 +145,7 @@ public:
|
||||
IPAddress listenIP();
|
||||
IPv6Address listenIPv6();
|
||||
bool connected();
|
||||
esp_err_t lastErr();
|
||||
operator bool();
|
||||
|
||||
static void _s_recv(void *arg, udp_pcb *upcb, pbuf *p, const ip_addr_t *addr, uint16_t port, struct netif * netif);
|
||||
|
Loading…
Reference in New Issue
Block a user