@@ -58,6 +58,10 @@ def __init__(self, socket: CircuitPythonSocketType, tls_mode: int) -> None:
58
58
self .recv = socket .recv
59
59
self .close = socket .close
60
60
self .recv_into = socket .recv_into
61
+ # For sockets that come from software socketpools (like the esp32api), they track
62
+ # the interface and socket pool. We need to make sure the clones do as well
63
+ self ._interface = getattr (socket , "_interface" , None )
64
+ self ._socket_pool = getattr (socket , "_socket_pool" , None )
61
65
62
66
def connect (self , address : Tuple [str , int ]) -> None :
63
67
"""Connect wrapper to add non-standard mode parameter"""
@@ -94,7 +98,10 @@ def create_fake_ssl_context(
94
98
* `Adafruit AirLift FeatherWing – ESP32 WiFi Co-Processor
95
99
<https://www.adafruit.com/product/4264>`_
96
100
"""
97
- socket_pool .set_interface (iface )
101
+ if hasattr (socket_pool , "set_interface" ):
102
+ # this is to manually support legacy hardware like the fona
103
+ socket_pool .set_interface (iface )
104
+
98
105
return _FakeSSLContext (iface )
99
106
100
107
@@ -104,6 +111,13 @@ def create_fake_ssl_context(
104
111
_global_ssl_contexts = {}
105
112
106
113
114
+ def _get_radio_hash_key (radio ):
115
+ try :
116
+ return hash (radio )
117
+ except TypeError :
118
+ return radio .__class__ .__name__
119
+
120
+
107
121
def get_radio_socketpool (radio ):
108
122
"""Helper to get a socket pool for common boards.
109
123
@@ -113,8 +127,9 @@ def get_radio_socketpool(radio):
113
127
* Using the ESP32 WiFi Co-Processor (like the Adafruit AirLift)
114
128
* Using a WIZ5500 (Like the Adafruit Ethernet FeatherWing)
115
129
"""
116
- class_name = radio .__class__ .__name__
117
- if class_name not in _global_socketpools :
130
+ key = _get_radio_hash_key (radio )
131
+ if key not in _global_socketpools :
132
+ class_name = radio .__class__ .__name__
118
133
if class_name == "Radio" :
119
134
import ssl # pylint: disable=import-outside-toplevel
120
135
@@ -124,12 +139,15 @@ def get_radio_socketpool(radio):
124
139
ssl_context = ssl .create_default_context ()
125
140
126
141
elif class_name == "ESP_SPIcontrol" :
127
- import adafruit_esp32spi .adafruit_esp32spi_socket as pool # pylint: disable=import-outside-toplevel
142
+ import adafruit_esp32spi .adafruit_esp32spi_socketpool as socketpool # pylint: disable=import-outside-toplevel
128
143
144
+ pool = socketpool .SocketPool (radio )
129
145
ssl_context = create_fake_ssl_context (pool , radio )
130
146
131
147
elif class_name == "WIZNET5K" :
132
- import adafruit_wiznet5k .adafruit_wiznet5k_socket as pool # pylint: disable=import-outside-toplevel
148
+ import adafruit_wiznet5k .adafruit_wiznet5k_socketpool as socketpool # pylint: disable=import-outside-toplevel
149
+
150
+ pool = socketpool .SocketPool (radio )
133
151
134
152
# Note: At this time, SSL/TLS connections are not supported by older
135
153
# versions of the Wiznet5k library or on boards withouut the ssl module
@@ -141,7 +159,6 @@ def get_radio_socketpool(radio):
141
159
import ssl # pylint: disable=import-outside-toplevel
142
160
143
161
ssl_context = ssl .create_default_context ()
144
- pool .set_interface (radio )
145
162
except ImportError :
146
163
# if SSL not on board, default to fake_ssl_context
147
164
pass
@@ -152,11 +169,11 @@ def get_radio_socketpool(radio):
152
169
else :
153
170
raise AttributeError (f"Unsupported radio class: { class_name } " )
154
171
155
- _global_key_by_socketpool [pool ] = class_name
156
- _global_socketpools [class_name ] = pool
157
- _global_ssl_contexts [class_name ] = ssl_context
172
+ _global_key_by_socketpool [pool ] = key
173
+ _global_socketpools [key ] = pool
174
+ _global_ssl_contexts [key ] = ssl_context
158
175
159
- return _global_socketpools [class_name ]
176
+ return _global_socketpools [key ]
160
177
161
178
162
179
def get_radio_ssl_context (radio ):
@@ -168,9 +185,8 @@ def get_radio_ssl_context(radio):
168
185
* Using the ESP32 WiFi Co-Processor (like the Adafruit AirLift)
169
186
* Using a WIZ5500 (Like the Adafruit Ethernet FeatherWing)
170
187
"""
171
- class_name = radio .__class__ .__name__
172
188
get_radio_socketpool (radio )
173
- return _global_ssl_contexts [class_name ]
189
+ return _global_ssl_contexts [_get_radio_hash_key ( radio ) ]
174
190
175
191
176
192
# main class
0 commit comments