mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-29 18:52:13 +01:00
Optimizations: remove multiple calls to the status() function.
This commit is contained in:
parent
d92bf5bdaa
commit
a9cdd44d27
@ -131,12 +131,17 @@ void EthernetClient::stop() {
|
||||
disconnect(_sock);
|
||||
unsigned long start = millis();
|
||||
|
||||
// wait a second for the connection to close
|
||||
while (status() != SnSR::CLOSED && millis() - start < 1000)
|
||||
// wait up to a second for the connection to close
|
||||
uint8_t s;
|
||||
do {
|
||||
s = status();
|
||||
if (s == SnSR::CLOSED)
|
||||
break; // exit the loop
|
||||
delay(1);
|
||||
} while (millis() - start < 1000);
|
||||
|
||||
// if it hasn't closed, close it forcefully
|
||||
if (status() != SnSR::CLOSED)
|
||||
if (s != SnSR::CLOSED)
|
||||
close(_sock);
|
||||
|
||||
EthernetClass::_server_port[_sock] = 0;
|
||||
|
@ -54,12 +54,13 @@ EthernetClient EthernetServer::available()
|
||||
|
||||
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
|
||||
EthernetClient client(sock);
|
||||
if (EthernetClass::_server_port[sock] == _port &&
|
||||
(client.status() == SnSR::ESTABLISHED ||
|
||||
client.status() == SnSR::CLOSE_WAIT)) {
|
||||
if (client.available()) {
|
||||
// XXX: don't always pick the lowest numbered socket.
|
||||
return client;
|
||||
if (EthernetClass::_server_port[sock] == _port) {
|
||||
uint8_t s = client.status();
|
||||
if (s == SnSR::ESTABLISHED || s == SnSR::CLOSE_WAIT) {
|
||||
if (client.available()) {
|
||||
// XXX: don't always pick the lowest numbered socket.
|
||||
return client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user