mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-06 01:08:25 +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);
|
disconnect(_sock);
|
||||||
unsigned long start = millis();
|
unsigned long start = millis();
|
||||||
|
|
||||||
// wait a second for the connection to close
|
// wait up to a second for the connection to close
|
||||||
while (status() != SnSR::CLOSED && millis() - start < 1000)
|
uint8_t s;
|
||||||
|
do {
|
||||||
|
s = status();
|
||||||
|
if (s == SnSR::CLOSED)
|
||||||
|
break; // exit the loop
|
||||||
delay(1);
|
delay(1);
|
||||||
|
} while (millis() - start < 1000);
|
||||||
|
|
||||||
// if it hasn't closed, close it forcefully
|
// if it hasn't closed, close it forcefully
|
||||||
if (status() != SnSR::CLOSED)
|
if (s != SnSR::CLOSED)
|
||||||
close(_sock);
|
close(_sock);
|
||||||
|
|
||||||
EthernetClass::_server_port[_sock] = 0;
|
EthernetClass::_server_port[_sock] = 0;
|
||||||
|
@ -54,15 +54,16 @@ EthernetClient EthernetServer::available()
|
|||||||
|
|
||||||
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
|
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
|
||||||
EthernetClient client(sock);
|
EthernetClient client(sock);
|
||||||
if (EthernetClass::_server_port[sock] == _port &&
|
if (EthernetClass::_server_port[sock] == _port) {
|
||||||
(client.status() == SnSR::ESTABLISHED ||
|
uint8_t s = client.status();
|
||||||
client.status() == SnSR::CLOSE_WAIT)) {
|
if (s == SnSR::ESTABLISHED || s == SnSR::CLOSE_WAIT) {
|
||||||
if (client.available()) {
|
if (client.available()) {
|
||||||
// XXX: don't always pick the lowest numbered socket.
|
// XXX: don't always pick the lowest numbered socket.
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return EthernetClient(MAX_SOCK_NUM);
|
return EthernetClient(MAX_SOCK_NUM);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user