mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-29 05:21:37 +03:00
emulation on host: fix nasty delay (#5840)
emulation with socket: fix nasty delay properly check all return values (read() returning 0 indicates closed peer) ClientContext::state() triggers read() to check for closed peer uart emulation on tty: add cmdline -b debug option to disable raw tty hide annoying MOCK messages, add cmdline -v option to show them uart emulation on tty: check more return values emulation on host: tcp/udp port shifting: new cmdline -s(port Shift) option
This commit is contained in:
@ -52,7 +52,10 @@ public:
|
||||
err_t abort()
|
||||
{
|
||||
if (_sock >= 0)
|
||||
{
|
||||
::close(_sock);
|
||||
mockverbose("socket %d closed\n", _sock);
|
||||
}
|
||||
_sock = -1;
|
||||
return ERR_ABRT;
|
||||
}
|
||||
@ -111,12 +114,12 @@ public:
|
||||
|
||||
void setNoDelay(bool nodelay)
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO setNoDelay(%d)\n", (int)nodelay);
|
||||
mockverbose("TODO setNoDelay(%d)\n", (int)nodelay);
|
||||
}
|
||||
|
||||
bool getNoDelay() const
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO getNoDelay()\n");
|
||||
mockverbose("TODO getNoDelay()\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -132,25 +135,25 @@ public:
|
||||
|
||||
uint32_t getRemoteAddress() const
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO getRemoteAddress()\n");
|
||||
mockverbose("TODO getRemoteAddress()\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t getRemotePort() const
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO getRemotePort()\n");
|
||||
mockverbose("TODO getRemotePort()\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t getLocalAddress() const
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO getLocalAddress()\n");
|
||||
mockverbose("TODO getLocalAddress()\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t getLocalPort() const
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO getLocalPort()\n");
|
||||
mockverbose("TODO getLocalPort()\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -160,7 +163,13 @@ public:
|
||||
return 0;
|
||||
if (_inbufsize)
|
||||
return _inbufsize;
|
||||
return mockFillInBuf(_sock, _inbuf, _inbufsize);
|
||||
ssize_t ret = mockFillInBuf(_sock, _inbuf, _inbufsize);
|
||||
if (ret < 0)
|
||||
{
|
||||
abort();
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int read()
|
||||
@ -174,7 +183,7 @@ public:
|
||||
ssize_t ret = mockRead(_sock, dst, size, 0, _inbuf, _inbufsize);
|
||||
if (ret < 0)
|
||||
{
|
||||
abort(); // close, CLOSED
|
||||
abort();
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
@ -188,12 +197,18 @@ public:
|
||||
|
||||
size_t peekBytes(char *dst, size_t size)
|
||||
{
|
||||
return mockPeekBytes(_sock, dst, size, _timeout_ms, _inbuf, _inbufsize);
|
||||
ssize_t ret = mockPeekBytes(_sock, dst, size, _timeout_ms, _inbuf, _inbufsize);
|
||||
if (ret < 0)
|
||||
{
|
||||
abort();
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void discard_received()
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO: ClientContext::discard_received()\n");
|
||||
mockverbose("TODO: ClientContext::discard_received()\n");
|
||||
}
|
||||
|
||||
bool wait_until_sent(int max_wait_ms = WIFICLIENT_MAX_FLUSH_WAIT_MS)
|
||||
@ -202,8 +217,9 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t state() const
|
||||
uint8_t state()
|
||||
{
|
||||
(void)getSize(); // read on socket to force detect closed peer
|
||||
return _sock >= 0? ESTABLISHED: CLOSED;
|
||||
}
|
||||
|
||||
@ -212,7 +228,7 @@ public:
|
||||
ssize_t ret = mockWrite(_sock, data, size, _timeout_ms);
|
||||
if (ret < 0)
|
||||
{
|
||||
abort(); // close, CLOSED
|
||||
abort();
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
@ -242,42 +258,42 @@ public:
|
||||
|
||||
void keepAlive (uint16_t idle_sec = TCP_DEFAULT_KEEPALIVE_IDLE_SEC, uint16_t intv_sec = TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC, uint8_t count = TCP_DEFAULT_KEEPALIVE_COUNT)
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO ClientContext::keepAlive()\n");
|
||||
mockverbose("TODO ClientContext::keepAlive()\n");
|
||||
}
|
||||
|
||||
bool isKeepAliveEnabled () const
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO ClientContext::isKeepAliveEnabled()\n");
|
||||
mockverbose("TODO ClientContext::isKeepAliveEnabled()\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t getKeepAliveIdle () const
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO ClientContext::getKeepAliveIdle()\n");
|
||||
mockverbose("TODO ClientContext::getKeepAliveIdle()\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t getKeepAliveInterval () const
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO ClientContext::getKeepAliveInternal()\n");
|
||||
mockverbose("TODO ClientContext::getKeepAliveInternal()\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t getKeepAliveCount () const
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO ClientContext::getKeepAliveCount()\n");
|
||||
mockverbose("TODO ClientContext::getKeepAliveCount()\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool getSync () const
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO ClientContext::getSync()\n");
|
||||
mockverbose("TODO ClientContext::getSync()\n");
|
||||
return _sync;
|
||||
}
|
||||
|
||||
void setSync (bool sync)
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO ClientContext::setSync()\n");
|
||||
mockverbose("TODO ClientContext::setSync()\n");
|
||||
_sync = sync;
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ public:
|
||||
void setMulticastTTL(int ttl)
|
||||
{
|
||||
(void)ttl;
|
||||
//fprintf(stderr, MOCK "TODO: UdpContext::setMulticastTTL\n");
|
||||
//mockverbose("TODO: UdpContext::setMulticastTTL\n");
|
||||
}
|
||||
|
||||
// warning: handler is called from tcp stack context
|
||||
@ -112,7 +112,7 @@ public:
|
||||
{
|
||||
if (!isValidOffset(pos))
|
||||
{
|
||||
fprintf(stderr, MOCK "UDPContext::seek too far (%zd >= %zd)\n", pos, _inbufsize);
|
||||
mockverbose("UDPContext::seek too far (%zd >= %zd)\n", pos, _inbufsize);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
mockUDPSwallow(pos, _inbuf, _inbufsize);
|
||||
@ -134,13 +134,13 @@ public:
|
||||
|
||||
uint32_t getDestAddress()
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO: implement UDP getDestAddress\n");
|
||||
mockverbose("TODO: implement UDP getDestAddress\n");
|
||||
return 0; //ip_hdr* iphdr = GET_IP_HDR(_rx_buf);
|
||||
}
|
||||
|
||||
uint16_t getLocalPort()
|
||||
{
|
||||
fprintf(stderr, MOCK "TODO: implement UDP getLocalPort\n");
|
||||
mockverbose("TODO: implement UDP getLocalPort\n");
|
||||
return 0; //
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ public:
|
||||
|
||||
void flush()
|
||||
{
|
||||
//fprintf(stderr, MOCK "UdpContext::flush() does not follow arduino's flush concept\n");
|
||||
//mockverbose("UdpContext::flush() does not follow arduino's flush concept\n");
|
||||
//exit(EXIT_FAILURE);
|
||||
// would be:
|
||||
_inbufsize = 0;
|
||||
@ -185,7 +185,7 @@ public:
|
||||
{
|
||||
if (size + _outbufsize > sizeof _outbuf)
|
||||
{
|
||||
fprintf(stderr, MOCK "UdpContext::append: increase CCBUFSIZE (%d -> %zd)\n", CCBUFSIZE, (size + _outbufsize));
|
||||
mockverbose("UdpContext::append: increase CCBUFSIZE (%d -> %zd)\n", CCBUFSIZE, (size + _outbufsize));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ private:
|
||||
//ip4_addr_set_u32(&ip_2_ip4(_dst), *(uint32_t*)addr);
|
||||
}
|
||||
else
|
||||
fprintf(stderr, MOCK "TODO unhandled udp address of size %d\n", (int)addrsize);
|
||||
mockverbose("TODO unhandled udp address of size %d\n", (int)addrsize);
|
||||
}
|
||||
|
||||
int _sock = -1;
|
||||
|
Reference in New Issue
Block a user