Open goccert25 opened 2 years ago
@karlsoderby @per1234 , this is my first time contributing to the Arduino ecosystem. Please let me know if there's anything missing from the PR or anything else you'd like to see from me :)
Memory usage change @ ec1ed04edf352ea44481ddcd81b89efd3b47d684
Board | flash | % | RAM for global variables | % |
---|---|---|---|---|
arduino:avr:leonardo | 0 - 0 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:avr:mega | 0 - 0 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:avr:nano | :green_heart: -2 - 0 | -0.01 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:megaavr:nona4809 | 0 - 0 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:megaavr:uno2018 | 0 - 0 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:sam:arduino_due_x_dbg | :small_red_triangle: 0 - +8 | 0.0 - 0.0 | N/A | N/A |
arduino:samd:arduino_zero_edbg | :small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkr1000 | :small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkrfox1200 | :small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkrgsm1400 | :small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkrnb1500 | :small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkrvidor4000 | :small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkrwan1300 | :small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkrwan1310 | :small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkrwifi1010 | :small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkrzero | :small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:nano_33_iot | :small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
Hey @karlsoderby @per1234, bumping this. Is there anyway to move this PR forward?
There is an alternative proposal at https://github.com/arduino-libraries/Ethernet/pull/176
I've been experiencing a bug using the Arduino to communicate over ethernet when using multiple EthernetClients, and as far as I can tell this line is the culprit. The exact steps of how the bug happens:
A.connect(HOST, PORT1);
is called first. Inside theconnect
function, the functionsocketBegin
is called, which according to the code here finds the first unused socket number and returns it. Lets say in this case the first unused socket number is 0. This means thatA._socketIndex
ends up being 0.A.connect(HOST, PORT1);
fails on line 63. However, note thatA._socketIndex
is NOT reset back toMAX_SOCK_NUM
and stays at the initialized value (for this example we'll stick with 0).B.connect(HOST, PORT2);
is called second. The process as above happens, andB._socketIndex
is set to 0. However, for some reasonB.connect(HOST, PORT2);
works, and B is able to connect.B._socketIndex == A._socketIndex == 0
. However, sinceA.connect(HOST, PORT1)
returned 0 (which stands for false), calls toA.available()
,A.read()
shouldn't work. Instead, they do work, and even worseA.write()
will write data to the socket that B is connected to.This change should fix the bug, because instead of returning 0 on line 63 we break, we set
_socketIndex
back toMAX_SOCK_NUM
and everything behaves as expected.