Arduino
Arduino copied to clipboard
Wifi client frees socket allocation on a listening socket
If using a server, this incorrectly released a socket that should still be reserved for the server. If the server_port array entry for that socket is non-zero, it should not release the socket. This is in WiFiClient.cpp. IDE v1.0.5 and v1.5.5.
void WiFiClient::stop() {
if (_sock == 255)
return;
ServerDrv::stopClient(_sock);
// add this line to prevent release of a listening socket (server)
if(WiFiClass::_server_port[_sock] == 0)
WiFiClass::_state[_sock] = NA_STATE;
int count = 0;
// wait maximum 5 secs for the connection to close
while (status() != CLOSED && ++count < 50)
delay(100);
_sock = 255;
}
I think that was not complete. There should be a call there to start the socket listening again. It should not be listening for another connection until this moment if it is a tcp server socket.
// add this line to prevent release of a listening socket (server)
if(WiFiClass::_server_port[_sock] == 0)
WiFiClass::_state[_sock] = NA_STATE;
else server.listen();
BTW, there is no server.listen() function that I found. There should be one though.
This issue was moved to arduino-libraries/WiFi#3