Open dhalbert opened 3 years ago
Yes please. I believe this would allow a non blocking tcp/udp socket to be opened.
I've tried to fix this with limited success in these functions
sp = SocketPool(wifi.radio)
, but this limits our ability to use other networking options as and when they appearsocketpool.Socket
doesn't accept setsockopt
function calls, and there are few other cosmetic changes needed to get these functions working well to start with.core.IOQueue._enqueue
to select.poll.register()
(c code) - which then crashes hard. This is probably because the poll
code expects underlying objects of mp_stream types and the new sockets are very different types. At one point I had to nuke the flash on my pico W to get it functioning again.However, the asyncio.StreamReader
function does seem to at least start to play well with other "file-like" objects, such as UARTs, the usb_cdc.Serial objects and (not tested yet) the _bleio.CharacteristicBuffer
streams - but see my other issue for more info
- CircuitPython uses SocketPool, which needs to be initialised with a radio. We can import wifi and do
sp = SocketPool(wifi.radio)
, but this limits our ability to use other networking options as and when they appear
You could pass in the SocketPool. adafruit_requests
and other libraries are agnostic about the source of sockets, and take it as a parameter.
I've taken a few cracks at this and it's really not so simple as that unfortunately. There are a few issues but the biggest thing is that SocketPool
sockets do not expose a file descriptor, therefore they can't be used with select
(and therefore also IOQueue
and therefore also asyncio.stream.Stream
etc)
esp-idf's examples around connecting and using non-blocking sockets also depend on having a file descriptor to use with select (see here: https://github.com/espressif/esp-idf/blob/master/examples/protocols/sockets/non_blocking/main/non_blocking_socket_example.c)
other issues, like the strange connection behavior I see with non-blocking sockets on my Qualia S3 with CircuitPython 9.2.1, can be worked around, but this piece is pretty fundamental to this particular problem. SocketPool Sockets' underlying file descriptor need to be exposed via a fileno()
method so that select
can work with them before Stream will work with it at all
EDITED: asyncio
not aiohttp
:face_exhaling:
Change
asyncio.open_connection()
andasynico.start_server()
to use CircuitPython's socket support.