Open mischif opened 2 weeks ago
This may or may not be related, but main()
is meant to be a tight loop and since I can't say for sure how long ingest()
will take I really need to call it via schedule()
; when I do that I can only get one buffer's worth of data before reading from SERIAL_TWO
fails like I hit EOF. I know there's more there but I can't get to it, could this also be some sort of schedule()
-induced deadlock?
There is a bug here, thanks for the report. When N bytes was read from the CDC interface, N < 64, and the host has more than N bytes still to send then (64-N) bytes were dropped. Fix incoming.
This may or may not be related, but main() is meant to be a tight loop and since I can't say for sure how long ingest() will take I really need to call it via schedule(); when I do that I can only get one buffer's worth of data before reading from SERIAL_TWO fails like I hit EOF. I know there's more there but I can't get to it, could this also be some sort of schedule()-induced deadlock?
This part has the same root cause as #873 - the callbacks for completed USB transfers run using the same mechanism as schedule()
so you can't block waiting for USB data inside a scheduled callback, it will block indefinitely. Need to find a way to exit the callback to allow more USB data transfer.
I will also look at adding a cdc.any()
function that returns the number of buffered bytes. That would make it possible to delay calling the callback again until you know all the bytes are ready. Can also look at putting together an asyncio example for CDC (I believe it shouldn't need any code changes) as this type of application is a lot easier to structure with asyncio.
I tested this on a Pico running MP 1.23 and the latest version of usb-device-cdc on mip main.py:
client.py:
I need to read four bytes off the input to confirm I should call
ingest()
, but in doing so I consistently lose eight bytes after the first call toreadinto()
(the output skips V -> e after 256 bytes) and some of the content never appears to leave the buffer. Moving theread()
call intoingest()
doesn't help, nor does usingreadinto()
instead.