1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

emulation on host: fix UDP seek&peek (#8827)

This commit is contained in:
david gauchard
2023-01-24 13:44:50 +01:00
committed by GitHub
parent cf24024292
commit a9675ca837
3 changed files with 17 additions and 30 deletions

View File

@ -117,12 +117,12 @@ public:
size_t getSize()
{
return _inbufsize;
return _inbufsize - _inoffset;
}
size_t tell() const
{
return 0;
return _inoffset;
}
void seek(const size_t pos)
@ -132,7 +132,7 @@ public:
mockverbose("UDPContext::seek too far (%zd >= %zd)\n", pos, _inbufsize);
exit(EXIT_FAILURE);
}
mockUDPSwallow(pos, _inbuf, _inbufsize);
_inoffset = pos;
}
bool isValidOffset(const size_t pos) const
@ -165,6 +165,7 @@ public:
bool next()
{
_inbufsize = 0;
_inoffset = 0;
mockUDPFillInBuf(_sock, _inbuf, _inbufsize, addrsize, addr, _dstport);
if (_inbufsize > 0)
{
@ -182,13 +183,16 @@ public:
size_t read(char* dst, size_t size)
{
return mockUDPRead(_sock, dst, size, _timeout_ms, _inbuf, _inbufsize);
//return mockUDPRead(_sock, dst, size, _timeout_ms, _inbuf, _inbufsize);
auto ret = mockUDPPeekBytes(_sock, dst, _inoffset, size, _timeout_ms, _inbuf, _inbufsize);
_inoffset += ret;
return ret;
}
int peek()
{
char c;
return mockUDPPeekBytes(_sock, &c, 1, _timeout_ms, _inbuf, _inbufsize) ?: -1;
return mockUDPPeekBytes(_sock, &c, _inoffset, 1, _timeout_ms, _inbuf, _inbufsize) ?: -1;
}
void flush()
@ -280,6 +284,7 @@ private:
char _inbuf[CCBUFSIZE];
size_t _inbufsize = 0;
size_t _inoffset = 0;
char _outbuf[CCBUFSIZE];
size_t _outbufsize = 0;