Revised Ethernet Library Client code

Hi etracer,

I am using your new ethernet library above.

When you have issued a client.stop(), what should client.connected() and client.status() return?

I am getting a '1' for both which suggests that the connection is still active.

There are bugs in the status() and connected() functions. The good news is that the bugs only manifest themselves when the connection is in fact closed. Basically the functions are failing to check if a socket is bound to the client before checking the status of the connection. When the connection is closed, the socket is released and the code is trying to pass an invalid socket reference in the call to the Wiznet chip.

I'll write up a patch for this and send it to the developer list. In the meantime if you want to fix it yourself, replace the status() and connected() functions in Client.cpp with the code below (be sure to delete the .o files as well).

uint8_t Client::connected() {
  if (_sock == 255) {
    return 0;
  } else {
    uint8_t s = status();
    return !(s == SOCK_LISTEN || s == SOCK_CLOSED || s == SOCK_FIN_WAIT ||
      (s == SOCK_CLOSE_WAIT && !available()));
  }
}

uint8_t Client::status() {
  if (_sock == 255) {
    return SOCK_CLOSED;
  } else {
    return getSn_SR(_sock);
  }
}

Note that these bugs were in the earlier versions of the Ethernet library and weren't addressed by my revisions. As a result, the bugs are still in the current release 0016.