diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2009-06-15 20:11:13 +0000 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2009-06-15 20:11:13 +0000 |
commit | c3baee9f63f7876bb30d128ee6e59cc0266312a9 (patch) | |
tree | d8a17cc30cf72cefcad82ed3e086c078b0916468 | |
parent | a0ba08b4f48fb066ba8ffd0b9655bc6135063f4d (diff) |
Fixing Client::connected() and Client::status() to return reasonable values when the Client isn't associated with a valid socket: issue #34.
-rw-r--r-- | libraries/Ethernet/Client.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/libraries/Ethernet/Client.cpp b/libraries/Ethernet/Client.cpp index ebbb08d..0511c7b 100644 --- a/libraries/Ethernet/Client.cpp +++ b/libraries/Ethernet/Client.cpp @@ -113,13 +113,21 @@ void Client::stop() { } uint8_t Client::connected() { - uint8_t s = status(); - return !(s == SOCK_LISTEN || s == SOCK_CLOSED || s == SOCK_FIN_WAIT || - (s == SOCK_CLOSE_WAIT && !available())); + 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() { - return getSn_SR(_sock); + if (_sock == 255) { + return SOCK_CLOSED; + } else { + return getSn_SR(_sock); + } } // the next three functions are a hack so we can compare the client returned |