mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 15:46:14 +01:00
Make EthernetInterface code more robust
This commit is contained in:
parent
b061c0b347
commit
280e61e1fc
|
@ -163,6 +163,10 @@ bool EthernetInterface::checkLink() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EthernetInterface::loop2() {
|
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
|
// get client from the server
|
||||||
EthernetClient client = server->accept();
|
EthernetClient client = server->accept();
|
||||||
|
|
||||||
|
@ -217,7 +221,9 @@ void EthernetInterface::loop2() {
|
||||||
|
|
||||||
// handle at most 1 outbound transmission
|
// handle at most 1 outbound transmission
|
||||||
int socketOut=outboundRing->read();
|
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();
|
int count=outboundRing->count();
|
||||||
if (Diag::ETHERNET) DIAG(F("Ethernet reply socket=%d, count=:%d"), socketOut,count);
|
if (Diag::ETHERNET) DIAG(F("Ethernet reply socket=%d, count=:%d"), socketOut,count);
|
||||||
for(;count>0;count--) clients[socketOut].write(outboundRing->read());
|
for(;count>0;count--) clients[socketOut].write(outboundRing->read());
|
||||||
|
|
|
@ -62,7 +62,7 @@ class EthernetInterface {
|
||||||
~EthernetInterface();
|
~EthernetInterface();
|
||||||
void loop2();
|
void loop2();
|
||||||
bool checkLink();
|
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
|
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
|
uint8_t buffer[MAX_ETH_BUFFER+1]; // buffer used by TCP for the recv
|
||||||
RingStream * outboundRing = NULL;
|
RingStream * outboundRing = NULL;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user