Go Down

Topic: Bug in Ethernet/Server.cpp (Read 721 times) previous topic - next topic


There's a bug in Ethernet/Server.cpp that causes very short client connections to be missed, which in turn leaves the connection state around and eventually preventing new connections from being established.

This is the patch:

[font=Courier New][size=12]--- Server.cpp# 2010-09-03 16:43:28.000000000 -0700
+++ Server.cpp  2010-09-07 00:50:54.000000000 -0700
@@ -55,7 +55,8 @@
  for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
    Client client(sock);
    if (EthernetClass::_server_port[sock] == _port &&
-      client.status() == SnSR::ESTABLISHED) {
+        (client.status() == SnSR::ESTABLISHED ||
+         client.status() == SnSR::CLOSE_WAIT)) {
      if (client.available()) {
        // XXX: don't always pick the lowest numbered socket.
        return client;[/size][/font]

What happens is that if a client connects, sends a small amount of data, and disconnects all before Server::available() is called, then client.status() is left in CLOSE_WAIT and available() never returns the connection.

Also, I think a client that connects and disconnects without sending any data should also be recognized as a valid connection.  After all, no data is also information.  I'll look into a fix (in both accept() and available()), but that one is an incompatible change (such connections are currently ignored so existing programs may not be equipped to handle it), so I'm not sure it's a good idea to do now.

Go Up