These checks won't tell you if the connection is actually opening or closing, since you could get a true value when it is already opened, or a false value when it is already closed. This function isn't necessarily called only when the state changes.