Coros which are passed to .add_reader()/.add_writer() are marked as
I/O-bound using .pend_throw(False). Before scheduling it for normal
execution again, we need to unmark it with .pend_throw(None).
It performs handshake in blocking manner, hopes that writes
work without short writes, and hopes that non-blocking read
is implemented properly by ussl module (there're known issues
with axTLS module for example).
Poll socket is what's passed to uselect.poll(), while I/O socket is what's
used for .read(). This is a workaround of the issue that MicroPython doesn't
support proxying poll functionality for stream wrappers (like SSL, websocket,
etc.)
This issue is tracked as https://github.com/micropython/micropython/issues/3394
It may be that it's more efficient to apply such a workaround on uasyncio
level rather than implementing full solution of uPy side.
POLLHUP/POLERR may be returned anytime (per POSIX, these flags aren't
even valid in input flags, they just appear in output flags). Subsequent
I/O operation on stream will lead to exception. If an application
doesn't do proper exception handling, the stream won't be closed, and
following calls will return POLLHUP/POLLERR status again (infinitely).
So, proactively unregister such a stream.
This change is questionable, because apps should handle errors properly
and close the stream in such case (or it will be leaked), and closing
will remove the stream from poller too.
But again, if that's not done, it may lead to cascade of adverse effects,
e.g. after eef054d98, benchmark/test_http_server_heavy.py regressed and
started and started to throw utimeq queue overflow exceptions. The story
behind it is: Boom benchmarker does an initial probe request to the app
under test which it apparently doen't handle properly, leading to
EPIPE/ECONNRESET on the side of the test app, the app didn't close the
socket, so each invocation to .wait() resulted in that socket being
returned with POLLHUP again and again. Given that after eef054d98, .wait()
is called on each even loop iteration, that create positive feedback in
the queue leading to it growing to overflow.
If there is a coroutine to run immediately (with wait delay <= 0),
uasyncio.core never calls .wait() method, which is required to
process I/O events (and schedule coroutines waiting for them).
This test demonstrates the problem.
set_debug() from uasyncio.core doesn't have effect on the main uasyncio
package, so let them both have set_debug() function, and allow to enable
debug logging independently.
Use MicroPython .write() extension of passing offset/size to efficiently
spool buffers larger than socket output buffer. Also, make awrite()
accept these params too.
The default queue length is set to take under 0.5K RAM on 32-bit system.
A queue length can be passed to get_event_loop() to override it. This
change follows similar change in uasyncio.core.