Fixing Client::connected() and Client::status() to return reasonable values when the Client isn't associated with a valid socket: issue #34.

This commit is contained in:
David A. Mellis 2009-06-15 20:11:13 +00:00
parent a0ba08b4f4
commit c3baee9f63
1 changed files with 12 additions and 4 deletions

View File

@ -113,13 +113,21 @@ void Client::stop() {
} }
uint8_t Client::connected() { uint8_t Client::connected() {
uint8_t s = status(); if (_sock == 255) {
return !(s == SOCK_LISTEN || s == SOCK_CLOSED || s == SOCK_FIN_WAIT || return 0;
(s == SOCK_CLOSE_WAIT && !available())); } 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() { 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 // the next three functions are a hack so we can compare the client returned