Make EthernetInterface code more robust

This commit is contained in:
Harald Barth 2022-11-07 11:53:56 +01:00
parent b061c0b347
commit 280e61e1fc
2 changed files with 8 additions and 2 deletions

View File

@ -163,6 +163,10 @@ bool EthernetInterface::checkLink() {
}
void EthernetInterface::loop2() {
if (!outboundRing) { // no idea to call loop2() if we can't handle outgoing data in it
if (Diag::ETHERNET) DIAG(F("No outboundRing"));
return;
}
// get client from the server
EthernetClient client = server->accept();
@ -217,7 +221,9 @@ void EthernetInterface::loop2() {
// handle at most 1 outbound transmission
int socketOut=outboundRing->read();
if (socketOut>=0) {
if (socketOut >= MAX_SOCK_NUM) {
DIAG(F("Ethernet outboundRing socket=%d error"), socketOut);
} else if (socketOut >= 0) {
int count=outboundRing->count();
if (Diag::ETHERNET) DIAG(F("Ethernet reply socket=%d, count=:%d"), socketOut,count);
for(;count>0;count--) clients[socketOut].write(outboundRing->read());

View File

@ -62,7 +62,7 @@ class EthernetInterface {
~EthernetInterface();
void loop2();
bool checkLink();
EthernetServer * server;
EthernetServer * server = NULL;
EthernetClient clients[MAX_SOCK_NUM]; // accept up to MAX_SOCK_NUM client connections at the same time; This depends on the chipset used on the Shield
uint8_t buffer[MAX_ETH_BUFFER+1]; // buffer used by TCP for the recv
RingStream * outboundRing = NULL;