Skip to content

Socket behaviour differs from core sockets #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fasteddy516 opened this issue Mar 22, 2025 · 2 comments
Open

Socket behaviour differs from core sockets #177

fasteddy516 opened this issue Mar 22, 2025 · 2 comments

Comments

@fasteddy516
Copy link
Contributor

fasteddy516 commented Mar 22, 2025

I was trying to get the httpserver_websocket.py example from adafruit_httpserver working with a wired WIZnet5K connection and ran into a couple of issues:

  1. The handle_http_requests() task was slow compared to the same code using the builtin wifi on a Pico 2 W.

  2. The handle_websocket_requests() task failed with an IndexError exception immediately after the websocket connection was established.
     
    I created a test script (available here) that will use the W5K driver if it is available or the builtin WiFi in CircuitPython if it isn't, ran it on a Pico 2 W and a WIZnet W5500-EVB-Pico2 and compared the results. It looks like the non-blocking behaviour defined in adafruit_wiznet5k_socketpool differs from the core socketpool module. adafruit_httpserver expects non-blocking sockets to raise OSError(errno.EAGAIN) when there is nothing to process but the W5K driver returns 0 from recv_into() and ("0.0.0.0", 0) from accept().

I made some quick changes to make the behaviour match, and it seems to make everything work correctly. I can create a pull request, but wasn't sure what other testing should be done to ensure there aren't other unintentional side-effects of the changes.

@justmobilize
Copy link
Collaborator

@fasteddy516 I think creating a pull request is good. That way we can comment and test. There are a bunch of use that will run it through it's paces.

@fasteddy516
Copy link
Contributor Author

@justmobilize Got it. I've found some additional behavioural differences related to the accept() method, though, so I'll try to get those sorted and put it all into one pull request.

@fasteddy516 fasteddy516 changed the title Non-blocking socket behaviour differs from core sockets Socket behaviour differs from core sockets Mar 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants