Closed ssilverman closed 1 year ago
Fixed in 7b3ecbc2.
Thanks for fixing this. I merged the changes from https://github.com/ssilverman/QNEthernet/commit/7b3ecbc2b9ac4415e7b68f5c7898f2fd55519b78 into the library on my system here, and it's now working correctly.
Copied from here: https://forum.pjrc.com/threads/72883-Possible-bug-in-EthernetClient-connected()-and-operator-bool() User: dgnuff
This code reproduces the problem:
I'm trying to use
EthernetClient::connectNoWait()
to establish connections non-blocking. It seemed reasonable thatEthernetClient::connected()
would be a way to poll for completion of the connection. ExceptEthernetClient::connected()
permanently returns false, even when use of WireShark clearly shows the SYN/SYN-ACK/ACK flow on the wire. And when connecting to my PC on the LAN, a test server application registers that a connection has been accepted.EthernetClient::operator bool()
suffers the same problem, even though its logic is slightly different.So I did a bit of digging into
EthernetClient::connected()
, and added a debug line to it as follows:As expected, the debug line was executed, indicating that
conn_->remaining
is indeed empty. Hardly a surprise, it appears that the remaining vector is part of the read logic, and I'd expect it to be empty if the connection hasn't yet been established.Modifying
EthernetClient::connected()
as follows causes the test program above and my main application to start working at lease as far asEthernetClient::connectNoWait()
is concerned, but that's a change that I can't make for the long term, because 40+ years of programming experience tells me that doing so will almost certainly break something else.The solution I'd use is to change the first line so that instead of just blindly testing
!conn_->connected
, that test is also guarded by something that determines we don't yet have a connection because the initial three-way handshake hasn't completed. Only if that condition is true would we check for!conn_->connected
. I just don't know how to do that. Once that change is made, the commented out logic can be restored, and the routine should then continue to work correctly.