Skip to content

Commit ffd95f3

Browse files
committed
CPython-ify send
1 parent 84d4743 commit ffd95f3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

adafruit_esp32spi/adafruit_esp32spi_socket.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def set_interface(iface):
2727
_the_interface = iface
2828

2929

30-
SOCK_STREAM = const(1)
30+
SOCK_STREAM = const(0)
31+
SOCK_DGRAM = const(1)
3132
AF_INET = const(2)
3233
NO_SOCKET_AVAIL = const(255)
3334

@@ -56,8 +57,7 @@ def __init__(
5657
):
5758
if family != AF_INET:
5859
raise RuntimeError("Only AF_INET family supported")
59-
if type != SOCK_STREAM:
60-
raise RuntimeError("Only SOCK_STREAM type supported")
60+
self._type = type
6161
self._buffer = b""
6262
self._socknum = socknum if socknum else _the_interface.get_socket()
6363
self.settimeout(0)
@@ -77,10 +77,12 @@ def connect(self, address, conntype=None):
7777
raise RuntimeError("Failed to connect to host", host)
7878
self._buffer = b""
7979

80-
def send(self, data, conntype=None): # pylint: disable=no-self-use
80+
def send(self, data): # pylint: disable=no-self-use
8181
"""Send some data to the socket. 'conntype' is an extra that may
8282
indicate UDP or not, depending on the underlying interface"""
83-
if conntype is None:
83+
if self._type is SOCK_DGRAM:
84+
conntype = _the_interface.UDP_MODE
85+
else:
8486
conntype = _the_interface.TCP_MODE
8587
_the_interface.socket_write(self._socknum, data, conn_mode=conntype)
8688
gc.collect()

0 commit comments

Comments
 (0)