smoltcp-rs / smoltcp

a smol tcp/ip stack
BSD Zero Clause License
3.64k stars 404 forks source link

Don't error when calling `listen` again on the same local endpoint. #841

Closed MabezDev closed 9 months ago

MabezDev commented 9 months ago

Provided the local endpoint we are listening to is the same, it is safe to call listen multiple times. Fixes the doc comment for the function too.

This isn't much use for this in smoltcp, in embassy-net it's crucial when writing an acceptor loop. Without this, if you try and accept on a socket that's already listening you'll immediately get an error. The only way around this is to first abort the socket, but this means that incoming connections can actually get aborted between the abort() and the next accept(), as I have sadly experienced myself today :smiling_face_with_tear:.

codecov[bot] commented 9 months ago

Codecov Report

Merging #841 (00cde4e) into main (28a5dd1) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #841   +/-   ##
=======================================
  Coverage   79.58%   79.58%           
=======================================
  Files          78       78           
  Lines       27809    27813    +4     
=======================================
+ Hits        22131    22135    +4     
  Misses       5678     5678           
Files Changed Coverage Δ
src/socket/tcp.rs 96.62% <100.00%> (+<0.01%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

thvdveld commented 9 months ago

Thank you!