Skip to content
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

Allow Non-Blocking Socket Calls #10

Merged
merged 2 commits into from
Jul 22, 2022
Merged

Conversation

karlfl
Copy link
Contributor

@karlfl karlfl commented Jul 20, 2022

Set socket blocking to false in HTTPServer.poll(). This will allow calling code to continue to process even when there are no web requests coming in. Without this it would block at the self._sock.accept() waiting for the next request.

Handle EAGAIN & ECONNRESET errors in HTTPServer.poll() These errors indicate there are no requests coming in (EAGAIN) or the peer has reset the connection (ECONNRESET). The calling code shouldn't have to handle these conditions as they are part of normal web interactions and can be safely handled in HTTPServer.

Fix example file name to follow standard naming of "modulename_simple.py"

This PR closes #9

Handle EAGAIN & ECONNRESET
Fix sample file name.
@karlfl
Copy link
Contributor Author

karlfl commented Jul 20, 2022

Not sure how to link an issue, but this PR will fix issue #9 - socket.accept() is blocking by default.

@dhalbert
Copy link
Contributor

(You can link an issue by clicking the gear icon to the right of "Development" in the right sidebar, or by mentioning the issue in a specific way in the original post:
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a comment question.

adafruit_httpserver.py Outdated Show resolved Hide resolved
@karlfl karlfl requested a review from dhalbert July 21, 2022 20:35
Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dhalbert dhalbert merged commit b218af3 into adafruit:main Jul 22, 2022
@karlfl karlfl deleted the NonBlockingSocket branch July 22, 2022 15:23
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jul 23, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_BME680 to 3.4.7 from 3.4.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_BME680#51 from tekktrik/dev/populate-version
  > Changed .env to .venv in README.rst

Updating https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground to 5.2.4 from 5.2.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_CircuitPlayground#119 from adafruit/pypi
  > Removed duplicate-code from library pylint disable

Updating https://github.com/adafruit/Adafruit_CircuitPython_CLUE to 3.0.9 from 3.0.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_CLUE#55 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_floppy to 1.0.3 from 1.0.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_floppy#6 from adafruit/pypi
  > Removed duplicate-code from library pylint disable
  > Updated readthedocs

Updating https://github.com/adafruit/Adafruit_CircuitPython_INA219 to 3.4.16 from 3.4.15:
  > Merge pull request adafruit/Adafruit_CircuitPython_INA219#33 from tekktrik/dev/populate-version
  > Changed .env to .venv in README.rst

Updating https://github.com/adafruit/Adafruit_CircuitPython_MONSTERM4SK to 0.3.8 from 0.3.5:
  > Updated release.yml to most common version for testing
  > Update release.yml
  > Merge pull request adafruit/Adafruit_CircuitPython_MONSTERM4SK#13 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_OV2640 to 1.1.5 from 1.1.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_OV2640#18 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_OV5640 to 1.1.6 from 1.1.2:
  > New release.yml but with single quotes
  > Rolled back release.yml version
  > Update setup.py
  > Merge pull request adafruit/Adafruit_CircuitPython_OV5640#15 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_OV to 1.0.7 from 1.0.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_OV#16 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_PyPortal to 6.2.4 from 6.2.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_PyPortal#122 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_RFM9x to 2.2.9 from 2.2.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_RFM9x#79 from tekktrik/dev/populate-version
  > Changed .env to .venv in README.rst

Updating https://github.com/adafruit/Adafruit_CircuitPython_SHT31D to 2.3.15 from 2.3.14:
  > Merge pull request adafruit/Adafruit_CircuitPython_SHT31D#31 from tekktrik/dev/fix-toml
  > Merge pull request adafruit/Adafruit_CircuitPython_SHT31D#30 from tekktrik/dev/populate-version

Updating https://github.com/adafruit/Adafruit_CircuitPython_VEML7700 to 1.1.14 from 1.1.13:
  > Merge pull request adafruit/Adafruit_CircuitPython_VEML7700#22 from tekktrik/dev/populate-version
  > Changed .env to .venv in README.rst

Updating https://github.com/adafruit/Adafruit_CircuitPython_BoardTest to 1.2.13 from 1.2.12:
  > Merge pull request adafruit/Adafruit_CircuitPython_BoardTest#22 from adafruit/pypi
  > Removed duplicate-code from library pylint disable

Updating https://github.com/adafruit/Adafruit_CircuitPython_Colorsys to 2.0.10 from 2.0.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_Colorsys#22 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_Dash_Dis to 1.1.9 from 1.1.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_Dash_Dis#6 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32S2TFT to 1.1.3 from 1.1.1:
  > Rolled back release.yml
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32S2TFT#7 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_FunHouse to 2.1.15 from 2.1.14:
  > Merge pull request adafruit/Adafruit_CircuitPython_FunHouse#38 from adafruit/pypi
  > Removed duplicate-code from library pylint disable

Updating https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer to 0.3.0 from 0.2.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#10 from karlfl/NonBlockingSocket

Updating https://github.com/adafruit/Adafruit_CircuitPython_IterTools to 2.0.0 from 1.1.10:
  > Merge pull request adafruit/Adafruit_CircuitPython_IterTools#16 from FoamyGuy/match_cpython_import
  > Merge pull request adafruit/Adafruit_CircuitPython_IterTools#17 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_MacroPad to 2.1.4 from 2.1.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_MacroPad#42 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_MagTag to 2.1.12 from 2.1.11:
  > Merge pull request adafruit/Adafruit_CircuitPython_MagTag#87 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_MatrixPortal to 3.0.7 from 3.0.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_MatrixPortal#87 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_PyBadger to 3.7.3 from 3.7.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_PyBadger#60 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_PYOA to 2.5.7 from 2.5.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_PYOA#35 from adafruit/pypi

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_CircuitPlayground, Adafruit_CircuitPython_CLUE, Adafruit_CircuitPython_floppy, Adafruit_CircuitPython_OV2640, Adafruit_CircuitPython_OV7670, Adafruit_CircuitPython_BoardTest, Adafruit_CircuitPython_Colorsys, Adafruit_CircuitPython_Dash_Display, Adafruit_CircuitPython_FunHouse, Adafruit_CircuitPython_IterTools, Adafruit_CircuitPython_MacroPad, Adafruit_CircuitPython_MagTag, Adafruit_CircuitPython_MatrixPortal, Adafruit_CircuitPython_PYOA
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

Successfully merging this pull request may close these issues.

socket.accept() is blocking by default
2 participants