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

Socket:: bind() behaviour is inconsistent #2438

Closed
tommikas opened this issue Aug 12, 2016 · 4 comments
Closed

Socket:: bind() behaviour is inconsistent #2438

tommikas opened this issue Aug 12, 2016 · 4 comments

Comments

@tommikas
Copy link
Contributor

  1. A UDPSocket type socket can bind to the same port repeatedly.
  2. Two UDPSocket type sockets cannot bind to the same port at the same time.
  3. A TCPServer type socket cannot bind to the same port repeatedly.
  4. Two TCPServer type sockets cannot bind to the same port at the same time.
  5. A TCPServer type socket and a UDPSocket type socket can bind to the same port at the same time. After that each socket behaves as described previously.

Mostly the last one seems like it could potentially cause issues.

@infinnovation-dev
Copy link
Contributor

A TCPServer type socket and a UDPSocket type socket can bind to the same port

This is expected behaviour. TCP port numbers and UDP port numbers are in different number-spaces; they are different protocols.

@geky
Copy link
Contributor

geky commented Aug 12, 2016

  1. Two UDPSocket type sockets cannot bind to the same port at the same time.
  2. Two TCPServer type sockets cannot bind to the same port at the same time.

This sounds expected, otherwise one socket would get packets intended for the other. This could corrupt transactions from an application that assumes it owns the data stream.

  1. A TCPServer type socket and a UDPSocket type socket can bind to the same port at the same time. After that each socket behaves as described previously.

This is expected as described by @infinnovation.

  1. Two UDPSocket type sockets cannot bind to the same port at the same time.
  2. Two TCPServer type sockets cannot bind to the same port at the same time.

I'm currently looking into this, I suspect lwip has a sort of REUSEADDR setting it is enforcing for the same reasons as preventing two sockets to bind to the same port. However, it is odd that this is only affecting the TCP socket.

@geky
Copy link
Contributor

geky commented Aug 13, 2016

  1. Two UDPSocket type sockets cannot bind to the same port at the same time.
  2. Two TCPServer type sockets cannot bind to the same port at the same time.

Looking into it more, this is a part of a similar mechanism that prevents sockets from binding to the same port as a part of protecting a user from himself. The fact that UDP bind succeeded is curious, but I suspect just an idiosyncrasy of lwip's implementation.

Once #2440 is merged, you can use NSAPI_REUSEADDR to allow socket servers to reuse the same address without waiting.

@tommikas
Copy link
Contributor Author

This is expected behaviour. TCP port numbers and UDP port numbers are in different number-spaces; they are different protocols.

Ah of course. That's no problem then. Thanks.

Looking into it more, this is a part of a similar mechanism that prevents sockets from binding to the same port as a part of protecting a user from himself. The fact that UDP bind succeeded is curious, but I suspect just an idiosyncrasy of lwip's implementation.

Fair enough.

Once #2440 is merged, you can use NSAPI_REUSEADDR to allow socket servers to reuse the same address without waiting.

Cool. I wondered if this might be connected to #2408, but seemed different enough to create its own issue.

artokin pushed a commit to artokin/mbed-os that referenced this issue Sep 2, 2020
…..91acece

91acece Remove test files
6568bc1 Merge branch 'release_internal' into release_external
4192cc8 Added configuration for RADIUS retry timer (ARMmbed#2438)
684b714 Added support for retries and multiple sockets to RADIUS client (ARMmbed#2426)
89e0ae0 WS: Restart auto CCA threshold after discovery (ARMmbed#2435)
dbb09b1 MAC/WS: Min possible Tack to 1ms and CCA interval to 2ms (ARMmbed#2434)
43b2ae2 Cca threshold test (ARMmbed#2436)
28108e1 Added device min sensitivity setting and stack information
7060c70 Cca threshold test (ARMmbed#2432)
640be71 WS: temporarily set default CCA threshold to -80 (ARMmbed#2431)
0a472ae WS: Calculate UFSI drift and trace (ARMmbed#2430)
61d3db8 Create APIs for DNS cache results
587add5 MAC: Validate TX time (ARMmbed#2429)
a1bfed4 Added typecast when computing max_timout from drift (ARMmbed#2428)
089fb3b Neighbour temporary entry update and Enhanced ACK tx update
70244f6 Wi-sun parameter and debug trace update
5752eae Created validate TX time handler (ARMmbed#2423)
022d61f Wi-sun Neighbour table update and DHCP new callback
857b41f Merge pull request ARMmbed#2421 from ARMmbed/update_from_mbed_os
1a9dd13 (via Mbed-OS)WS Management API missing include
4318f37 Calculate drift in critical state (ARMmbed#2419)
01a1909 FHSS WS: Do not use drift compensation with unpredictable linux timer (ARMmbed#2418)

git-subtree-dir: features/nanostack/sal-stack-nanostack
git-subtree-split: 91acece
artokin pushed a commit to artokin/mbed-os that referenced this issue Sep 7, 2020
…..d879e6d

d879e6d Merge branch 'release_internal' into release_external
eef9246 Fixed network border router timeout recovery and EAPOL relay address fix
bac7ca6 Changed RADIUS MTU and small fixes
a9f8b75 Addeed support for DHCP vendor data
d8f0003 DHCPv6 functionality update
7fe0423 Added DHCPv6 vendor data generation for DNS queries
639f9db FHSS: Changed retry backoffs when no BC schedule or TX slots (ARMmbed#2440)
91acece Remove test files
6568bc1 Merge branch 'release_internal' into release_external
4192cc8 Added configuration for RADIUS retry timer (ARMmbed#2438)
684b714 Added support for retries and multiple sockets to RADIUS client (ARMmbed#2426)
89e0ae0 WS: Restart auto CCA threshold after discovery (ARMmbed#2435)
dbb09b1 MAC/WS: Min possible Tack to 1ms and CCA interval to 2ms (ARMmbed#2434)
43b2ae2 Cca threshold test (ARMmbed#2436)
28108e1 Added device min sensitivity setting and stack information
7060c70 Cca threshold test (ARMmbed#2432)
640be71 WS: temporarily set default CCA threshold to -80 (ARMmbed#2431)
0a472ae WS: Calculate UFSI drift and trace (ARMmbed#2430)
61d3db8 Create APIs for DNS cache results
587add5 MAC: Validate TX time (ARMmbed#2429)
a1bfed4 Added typecast when computing max_timout from drift (ARMmbed#2428)
089fb3b Neighbour temporary entry update and Enhanced ACK tx update
70244f6 Wi-sun parameter and debug trace update
5752eae Created validate TX time handler (ARMmbed#2423)
022d61f Wi-sun Neighbour table update and DHCP new callback
857b41f Merge pull request ARMmbed#2421 from ARMmbed/update_from_mbed_os
1a9dd13 (via Mbed-OS)WS Management API missing include
4318f37 Calculate drift in critical state (ARMmbed#2419)
01a1909 FHSS WS: Do not use drift compensation with unpredictable linux timer (ARMmbed#2418)

git-subtree-dir: features/nanostack/sal-stack-nanostack
git-subtree-split: d879e6d
artokin pushed a commit to artokin/mbed-os that referenced this issue Sep 7, 2020
…8609ae..d879e6d

d879e6d Merge branch 'release_internal' into release_external
eef9246 Fixed network border router timeout recovery and EAPOL relay address fix
bac7ca6 Changed RADIUS MTU and small fixes
a9f8b75 Addeed support for DHCP vendor data
d8f0003 DHCPv6 functionality update
7fe0423 Added DHCPv6 vendor data generation for DNS queries
639f9db FHSS: Changed retry backoffs when no BC schedule or TX slots (ARMmbed#2440)
91acece Remove test files
6568bc1 Merge branch 'release_internal' into release_external
4192cc8 Added configuration for RADIUS retry timer (ARMmbed#2438)
684b714 Added support for retries and multiple sockets to RADIUS client (ARMmbed#2426)
89e0ae0 WS: Restart auto CCA threshold after discovery (ARMmbed#2435)
dbb09b1 MAC/WS: Min possible Tack to 1ms and CCA interval to 2ms (ARMmbed#2434)
43b2ae2 Cca threshold test (ARMmbed#2436)
28108e1 Added device min sensitivity setting and stack information
7060c70 Cca threshold test (ARMmbed#2432)
640be71 WS: temporarily set default CCA threshold to -80 (ARMmbed#2431)
0a472ae WS: Calculate UFSI drift and trace (ARMmbed#2430)
61d3db8 Create APIs for DNS cache results
587add5 MAC: Validate TX time (ARMmbed#2429)
a1bfed4 Added typecast when computing max_timout from drift (ARMmbed#2428)
089fb3b Neighbour temporary entry update and Enhanced ACK tx update
70244f6 Wi-sun parameter and debug trace update
5752eae Created validate TX time handler (ARMmbed#2423)
022d61f Wi-sun Neighbour table update and DHCP new callback
857b41f Merge pull request ARMmbed#2421 from ARMmbed/update_from_mbed_os
1a9dd13 (via Mbed-OS)WS Management API missing include
4318f37 Calculate drift in critical state (ARMmbed#2419)
01a1909 FHSS WS: Do not use drift compensation with unpredictable linux timer (ARMmbed#2418)

git-subtree-dir: connectivity/nanostack/sal-stack-nanostack
git-subtree-split: d879e6d
winneymj pushed a commit to winneymj/mbed-os that referenced this issue Sep 29, 2020
…8609ae..d879e6d

d879e6d Merge branch 'release_internal' into release_external
eef9246 Fixed network border router timeout recovery and EAPOL relay address fix
bac7ca6 Changed RADIUS MTU and small fixes
a9f8b75 Addeed support for DHCP vendor data
d8f0003 DHCPv6 functionality update
7fe0423 Added DHCPv6 vendor data generation for DNS queries
639f9db FHSS: Changed retry backoffs when no BC schedule or TX slots (ARMmbed#2440)
91acece Remove test files
6568bc1 Merge branch 'release_internal' into release_external
4192cc8 Added configuration for RADIUS retry timer (ARMmbed#2438)
684b714 Added support for retries and multiple sockets to RADIUS client (ARMmbed#2426)
89e0ae0 WS: Restart auto CCA threshold after discovery (ARMmbed#2435)
dbb09b1 MAC/WS: Min possible Tack to 1ms and CCA interval to 2ms (ARMmbed#2434)
43b2ae2 Cca threshold test (ARMmbed#2436)
28108e1 Added device min sensitivity setting and stack information
7060c70 Cca threshold test (ARMmbed#2432)
640be71 WS: temporarily set default CCA threshold to -80 (ARMmbed#2431)
0a472ae WS: Calculate UFSI drift and trace (ARMmbed#2430)
61d3db8 Create APIs for DNS cache results
587add5 MAC: Validate TX time (ARMmbed#2429)
a1bfed4 Added typecast when computing max_timout from drift (ARMmbed#2428)
089fb3b Neighbour temporary entry update and Enhanced ACK tx update
70244f6 Wi-sun parameter and debug trace update
5752eae Created validate TX time handler (ARMmbed#2423)
022d61f Wi-sun Neighbour table update and DHCP new callback
857b41f Merge pull request ARMmbed#2421 from ARMmbed/update_from_mbed_os
1a9dd13 (via Mbed-OS)WS Management API missing include
4318f37 Calculate drift in critical state (ARMmbed#2419)
01a1909 FHSS WS: Do not use drift compensation with unpredictable linux timer (ARMmbed#2418)

git-subtree-dir: connectivity/nanostack/sal-stack-nanostack
git-subtree-split: d879e6d
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

3 participants