PaulStoffregen / Ethernet

Ethernet library for Teensy (Wiznet W5100 / W5200 / W5500)
http://www.pjrc.com/teensy/td_libs_Ethernet.html
129 stars 83 forks source link

Client.Stop slow #53

Open electroremy opened 3 years ago

electroremy commented 3 years ago

Hi, I use the Ethernet lib featured by Arduino with the W5500 Arduino Official Ethernet Shield II

I notice that client.stop is slow... I found that Ethernet.socketStatus(sockindex) == SnSR::CLOSED never append.

So I change the function to do not wait until Ethernet.socketStatus(sockindex) == SnSR::CLOSED and it's works fine.

`void EthernetClient::stop() { if (sockindex >= MAX_SOCK_NUM) return; // attempt to close the connection gracefully (send a FIN to other side) Ethernet.socketDisconnect(sockindex);

// Waiting for the connection to close is useless and VERY SLOW !
/*
// wait up to a second for the connection to close
unsigned long start = millis();
do {
    if (Ethernet.socketStatus(sockindex) == SnSR::CLOSED) {
        sockindex = MAX_SOCK_NUM;
        return; // exit the loop
    }
    delay(1); 
} while (millis() - start < _timeout); 
*/

delay(1); 

// if it hasn't closed, close it forcefully
Ethernet.socketClose(sockindex);
sockindex = MAX_SOCK_NUM;

}`

Also, I notice that there are several TODO in your library files (Ethernet, EthernetClient, EthernetServer, Socket, W5100...)

Does the Ethernet library is up to date on Arduino website ?

Bests regards.