Fix issue due to repeated status()/connected() call #73
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a sketch repeatedly calls
client.status()
andclient.connected()
functions, the connection occasionally gets stuck.This issue had already been address by PR #50 ,which was then reverted thinking that its functionality was already covered by further code modifications.
Unfortunately it still seems to be needed.
A further modification has been introduce to let the driver correctly detect a client disconnection. In order to avoid lockups, we need to call
available()
function. This function, callinglwip_ioctl_r()
, returns the number of bytes of pending data already received in the socket’s network. At most the result is 0. However,available()
is never able to detect a network disconnection.peek()
, on the other hand, is the function to call to receive data withlwip_recv_r()
. This function can actually return an error if the connection went down.The procedure adopted here is to check if there are already available data and, if not, try to read from the network. In this way we avoid lockups by always checking if there are already available data before trying to receive new ones and we are also able to detect a disconnection.