Skip to content

Commit 1d78f9d

Browse files
committed
ethernetIdle() weak handler was added in order to execute some code while DNS requests and TCP:open/close awaiting for results
1 parent 75a3c37 commit 1d78f9d

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/Dhcp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Ethernet.h"
66
#include "Dhcp.h"
77
#include "utility/w5100.h"
8+
extern void ethernetIdle(void);
89

910
int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)
1011
{
@@ -244,7 +245,8 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr
244245
if ((millis() - startTime) > responseTimeout) {
245246
return 255;
246247
}
247-
delay(50);
248+
ethernetIdle();
249+
delay(1);
248250
}
249251
// start reading in the packet
250252
RIP_MSG_FIXED fixedMsg;

src/Dns.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "Ethernet.h"
77
#include "Dns.h"
88
#include "utility/w5100.h"
9-
9+
extern void ethernetIdle(void);
1010

1111
#define SOCKET_NONE 255
1212
// Various flags and header field values for a DNS message
@@ -120,6 +120,8 @@ int DNSClient::getHostByName(const char* aHostname, IPAddress& aResult, uint16_t
120120
while ((wait_retries < 3) && (ret == TIMED_OUT)) {
121121
ret = ProcessResponse(timeout, aResult);
122122
wait_retries++;
123+
ethernetIdle();
124+
delay(1);
123125
}
124126
}
125127
}
@@ -220,7 +222,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
220222
if ((millis() - startTime) > aTimeout) {
221223
return TIMED_OUT;
222224
}
223-
delay(50);
225+
ethernetIdle();
224226
}
225227

226228
// We've had a reply!

src/Ethernet.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,6 @@ void EthernetClass::setRetransmissionCount(uint8_t num)
244244

245245

246246
EthernetClass Ethernet;
247+
248+
void ethernetIdle(void) __attribute__ ((weak));
249+
void ethernetIdle(void) {delay(10);};

src/EthernetClient.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "Ethernet.h"
2323
#include "Dns.h"
2424
#include "utility/w5100.h"
25+
extern void ethernetIdle(void);
2526

2627
int EthernetClient::connect(const char * host, uint16_t port)
2728
{
@@ -62,6 +63,7 @@ int EthernetClient::connect(IPAddress ip, uint16_t port)
6263
if (stat == SnSR::CLOSE_WAIT) return 1;
6364
if (stat == SnSR::CLOSED) return 0;
6465
if (millis() - start > _timeout) break;
66+
ethernetIdle();
6567
delay(1);
6668
}
6769
Ethernet.socketClose(sockindex);
@@ -143,6 +145,7 @@ void EthernetClient::stop()
143145
sockindex = MAX_SOCK_NUM;
144146
return; // exit the loop
145147
}
148+
ethernetIdle();
146149
delay(1);
147150
} while (millis() - start < _timeout);
148151

0 commit comments

Comments
 (0)