Ignore OSError on socket.shutdown()

This fixes #22 and obsoletes PR #23.
This commit is contained in:
Teemu Rytilahti 2017-03-19 15:53:40 +01:00
parent 72cbaa2839
commit 9d3fbfa975

View File

@ -63,8 +63,14 @@ class TPLinkSmartHomeProtocol:
break break
finally: finally:
sock.shutdown(socket.SHUT_RDWR) try:
sock.close() sock.shutdown(socket.SHUT_RDWR)
sock.close()
except OSError:
# OSX raises OSError when shutdown() gets called on a closed
# socket. We ignore it here as the data has already been read
# into the buffer at this point.
pass
response = TPLinkSmartHomeProtocol.decrypt(buffer[4:]) response = TPLinkSmartHomeProtocol.decrypt(buffer[4:])
_LOGGER.debug("< (%i) %s", len(response), response) _LOGGER.debug("< (%i) %s", len(response), response)