Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

Wifi client frees socket allocation on a listening socket

Open SurferTim opened this issue 12 years ago • 2 comments

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;
}

SurferTim avatar Dec 11 '13 11:12 SurferTim

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.

SurferTim avatar Dec 14 '13 12:12 SurferTim

This issue was moved to arduino-libraries/WiFi#3

agdl avatar Jul 12 '16 13:07 agdl