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

open_tcp_server_transport: allow explicit sock as input. #435

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

jeru
Copy link
Contributor

@jeru jeru commented Mar 3, 2024

When a user doesn't need an exact port, but cares more about getting SOME unused port, they can do:

  • Create a socket outside with port=None or port=0.
  • Use socket.getsockname()[1] to get the allocated port and pass to the TCP client somehow.
  • Use the created socket to create a TCP server transport.

Use-case: unit-testing embedded software that implements a BLE host. The controller will be a Bumble controller, connected to the host via a TCP channel.

  • The host will have a TCP-client HCI transport for testing.
  • The pytest setup code will allocate the TCP server and pass the port number to the host.

Also add some unittests with python mock.

@jeru jeru force-pushed the main branch 2 times, most recently from c9e26b2 to e1216d9 Compare March 5, 2024 20:37
@jeru
Copy link
Contributor Author

jeru commented Mar 5, 2024

Thanks for the suggestion. Indeed that makes the interface cleaner. Refactored accordingly.

And sorry for the noob mistakes on the lint and the extra trouble on re-approving the workflows... Was using an outdated "black" which touched too many files, so didn't even notice "invoke project.pre-commit" has multiple stages.

@jeru jeru marked this pull request as ready for review March 5, 2024 22:24
When a user doesn't need an exact port, but cares more about getting
SOME unused port, they can do:
* Create a socket outside with port=None or port=0.
* Use socket.getsockname()[1] to get the allocated port and pass to the
TCP client somehow.
* Use the created socket to create a TCP server transport.

Use-case: unit-testing embedded software that implements a BLE host. The
controller will be a Bumble controller, connected to the host via a TCP
channel.
* The host will have a TCP-client HCI transport for testing.
* The pytest setup code will allocate the TCP server and pass the port
number to the host.

Also add some unittests with python mock.
@jeru
Copy link
Contributor Author

jeru commented Apr 4, 2024

Any further comments?

@barbibulle
Copy link
Collaborator

Any further comments?

Sorry about that, I forgot the approval was pending. Good to go!

@barbibulle barbibulle merged commit 2698d45 into google:main Apr 5, 2024
51 checks passed
@jeru
Copy link
Contributor Author

jeru commented Apr 5, 2024

Thanks!

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.

2 participants