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

Network connection goes deaf. #35

Open
pvrfr opened this issue May 23, 2022 · 3 comments
Open

Network connection goes deaf. #35

pvrfr opened this issue May 23, 2022 · 3 comments

Comments

@pvrfr
Copy link

pvrfr commented May 23, 2022

Hello;

I am having the same problem with EthernetENC as I did with UIPEthernet. That is the
stack stops receiving packets. You fixed the problem and afterwards the code ran without
problems. Perhaps there is a similar bug in your new code. The processor is an ESP-12N.
The code is part of the OpenSprinkler project.

The issue was previously discussed here:
UIPEthernet/UIPEthernet#129

@JAndrassy
Copy link
Owner

JAndrassy commented May 23, 2022

the error I found 'hidden in plain sight' was not an error, but my confusion about if (*this) (which executes the bool operator). I replaced it with if (data) and after I realized my misunderstanding of if (*this) I changed it back.

UIPClient::operator bool()
{
  UIPEthernetClass::tick();
  return data && (!(data->state & UIP_CLIENT_REMOTECLOSED) || data->packets_in[0] != NOBLOCK);
}

data is not null if the client is initialized.
!(data->state & UIP_CLIENT_REMOTECLOSED) is that it is connected
data->packets_in[0] != NOBLOCK is that it has data.
so it is initialized and (connected or has_data)

if (*this) is used to skip available(), peek(), read() and discardReceived() (which is flush() n UIPEthernet).

@pvrfr
Copy link
Author

pvrfr commented May 24, 2022

The "fix" really did solve the problem in my case. The idea that I had was that the fix prevented
dereferencing an invalid pointer, which generally results in difficult to understand bugs.

I am very fluent in C but not so much with C++. I tried to get GDB running on the ESP chip but
was not successful, so debugging required using printf. Can you suggest some debug test that
I can do to help find this problem.

@JAndrassy
Copy link
Owner

the difference is tick() and this part of the bool operator implementation:
(!(data->state & UIP_CLIENT_REMOTECLOSED) || data->packets_in[0] != NOBLOCK)
instead of *this in available(), peek(), read() try
data && (!(data->state & UIP_CLIENT_REMOTECLOSED) || data->packets_in[0] != NOBLOCK)
this will remove tick() from available(), peek(), read()

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

2 participants