JAndrassy / WiFiEspAT

Arduino networking library. Standard Arduino WiFi networking API over ESP8266 or ESP32 AT commands.
GNU Lesser General Public License v2.1
272 stars 44 forks source link

[request] please re enable getLinkId() function again #34

Closed atesin closed 3 years ago

atesin commented 3 years ago

as requested in #5 ...

is helpful for me, and for many people will and would be also, everytime the lib gets updated i have to patch it manually

i understand your argument about overwriting a link object with still unread data could lead to data loss and break sync

but C and C++ language philosophy is about give all tools, flexibility and freedom to programmers to do anything we want with the system at any level (hardware level, low level, user level, etc), together with the most complete documentation possible, so we could develop whatever tool we want/need, and if we commit a mistake we could assume our responsibility, fix it, learn about it, avoid mistakes in the future, write better programs, and grow as a developer

think in commands like memcpy() that don't check for cstring terminators '\0', it still exists and can be used to greatly improve some things, but warns strongly about buffer overflows... if memcpy() wouldn't exist because of buffer overflow risks, a lot of great things couldn't be done also

and about data loss, it could be just prevented by checking old client before overwriting new

WiFiClient newClient = server.accept();
if ( newClient )
{
  for ( byte i=0; i < MAX_CLIENTS; ++i )
  {
    if ( !clients[i] )
    {
      // ...
      // check if old client has still unread data before replacing it
      // anyway is already disconnected so it won't send any more data
      if ( clients[i].available() )
        consumeRemainingDataSomeWay(clients[i]);
      clients[i] = newClient;
      break;
    }
  }
}

the unlikely data loss risk done by uncareful programmers doesn't worth all the benefits we will gain with getLinkId(), if done in right way with the correct documentation... the use we give to the library is up to us, you will give more usefulness to the library and freedom to us

please reconsider, document the risks and re enable it