From 40b51dafcb982c72c2733c8f99132ea820be48d6 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 5 May 2024 20:36:20 -0500 Subject: [PATCH 1/2] socket.connect(): Auto-select UDP_MODE This improves compatibility with the standard socket module --- adafruit_esp32spi/adafruit_esp32spi_socketpool.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/adafruit_esp32spi/adafruit_esp32spi_socketpool.py b/adafruit_esp32spi/adafruit_esp32spi_socketpool.py index 2f7ca78..08015da 100644 --- a/adafruit_esp32spi/adafruit_esp32spi_socketpool.py +++ b/adafruit_esp32spi/adafruit_esp32spi_socketpool.py @@ -108,7 +108,11 @@ def connect(self, address, conntype=None): depending on the underlying interface""" host, port = address if conntype is None: - conntype = self._interface.TCP_MODE + conntype = ( + self._interface.UDP_MODE + if self._type == SocketPool.SOCK_DGRAM + else self._interface.TCP_MODE + ) if not self._interface.socket_connect( self._socknum, host, port, conn_mode=conntype ): From 86ffa6bfc338fa8c81677a8cd1ea3e1ec272df06 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 5 May 2024 20:39:55 -0500 Subject: [PATCH 2/2] socketpool: don't use "is" to compare numbers --- adafruit_esp32spi/adafruit_esp32spi_socketpool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_esp32spi/adafruit_esp32spi_socketpool.py b/adafruit_esp32spi/adafruit_esp32spi_socketpool.py index 08015da..6f653f3 100644 --- a/adafruit_esp32spi/adafruit_esp32spi_socketpool.py +++ b/adafruit_esp32spi/adafruit_esp32spi_socketpool.py @@ -121,7 +121,7 @@ def connect(self, address, conntype=None): def send(self, data): """Send some data to the socket.""" - if self._type is SocketPool.SOCK_DGRAM: + if self._type == SocketPool.SOCK_DGRAM: conntype = self._interface.UDP_MODE else: conntype = self._interface.TCP_MODE