mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
Fixed bug in parsePacket where it could block indefinitely if called when no packets were available to be read.
This commit is contained in:
parent
a9c2ebf455
commit
1b56de694b
@ -121,20 +121,25 @@ void UDP::write(const uint8_t *buffer, size_t size)
|
|||||||
|
|
||||||
int UDP::parsePacket()
|
int UDP::parsePacket()
|
||||||
{
|
{
|
||||||
//HACK - hand-parse the UDP packet using TCP recv method
|
if (available() > 0)
|
||||||
uint8_t tmpBuf[8];
|
|
||||||
int ret =0;
|
|
||||||
//read 8 header bytes and get IP and port from it
|
|
||||||
ret = recv(_sock,tmpBuf,8);
|
|
||||||
if (ret > 0)
|
|
||||||
{
|
{
|
||||||
_remoteIP = tmpBuf;
|
//HACK - hand-parse the UDP packet using TCP recv method
|
||||||
_remotePort = tmpBuf[4];
|
uint8_t tmpBuf[8];
|
||||||
_remotePort = (_remotePort << 8) + tmpBuf[5];
|
int ret =0;
|
||||||
// When we get here, any remaining bytes are the data
|
//read 8 header bytes and get IP and port from it
|
||||||
ret = available();
|
ret = recv(_sock,tmpBuf,8);
|
||||||
|
if (ret > 0)
|
||||||
|
{
|
||||||
|
_remoteIP = tmpBuf;
|
||||||
|
_remotePort = tmpBuf[4];
|
||||||
|
_remotePort = (_remotePort << 8) + tmpBuf[5];
|
||||||
|
// When we get here, any remaining bytes are the data
|
||||||
|
ret = available();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
return ret;
|
// There aren't any packets available
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UDP::read()
|
int UDP::read()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user