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

host emulation: improve udp, persistent spiffs (#5605)

This commit is contained in:
david gauchard
2019-01-15 22:56:54 +01:00
committed by GitHub
parent 8a64a1236f
commit 6bd26a3b4a
16 changed files with 266 additions and 142 deletions

View File

@ -156,18 +156,28 @@ public:
size_t getSize()
{
return _inbufsize?: mockFillInBuf(_sock, _inbuf, _inbufsize);
if (_sock < 0)
return 0;
if (_inbufsize)
return _inbufsize;
return mockFillInBuf(_sock, _inbuf, _inbufsize);
}
int read()
{
char c;
return read(&c, 1)? c: -1;
return read(&c, 1)? (unsigned char)c: -1;
}
size_t read (char* dst, size_t size)
{
return mockRead(_sock, dst, size, 0, _inbuf, _inbufsize);
ssize_t ret = mockRead(_sock, dst, size, 0, _inbuf, _inbufsize);
if (ret < 0)
{
abort(); // close, CLOSED
return 0;
}
return ret;
}
int peek()
@ -198,7 +208,13 @@ public:
size_t write(const uint8_t* data, size_t size)
{
return mockWrite(_sock, data, size, _timeout_ms);
ssize_t ret = mockWrite(_sock, data, size, _timeout_ms);
if (ret < 0)
{
abort(); // close, CLOSED
return 0;
}
return ret;
}
size_t write(Stream& stream)
@ -208,7 +224,7 @@ public:
avail = stream.readBytes(buf, avail);
size_t totwrote = 0;
uint8_t* w = buf;
while (avail)
while (avail && _sock >= 0)
{
size_t wrote = write(w, avail);
w += wrote;

View File

@ -79,20 +79,12 @@ public:
_sock = -1;
}
#if 0
void setMulticastInterface(const ip_addr_t& addr)
{
(void)addr;
// user multicast, and this is how it works with posix: send to multicast address:
_dst.addr = staticMCastAddr;
}
#endif
void setMulticastInterface(const ip_addr_t* addr)
{
(void)addr;
// user multicast, and this is how it works with posix: send to multicast address:
_dst.addr = staticMCastAddr;
}
void setMulticastTTL(int ttl)
{
@ -118,12 +110,12 @@ public:
void seek(const size_t pos)
{
fprintf(stderr, MOCK "TODO: implement UDP offset\n");
if (!isValidOffset(pos))
{
fprintf(stderr, MOCK "UDPContext::seek too far (%zd >= %zd)\n", pos, _inbufsize);
exit(EXIT_FAILURE);
}
mockUDPSwallow(pos, _inbuf, _inbufsize);
}
bool isValidOffset(const size_t pos) const {