Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/EthernetICMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ void EthernetICMPPing::openSocket()
W5100.execCmdSn(_socket, Sock_OPEN);
}

void EthernetICMPPing::closeSocket()
{
W5100.execCmdSn(_socket, Sock_CLOSE);
W5100.writeSnIR(_socket, 0xFF);
}


void EthernetICMPPing::operator()(const IPAddress& addr, int nRetries, EthernetICMPEchoReply& result)
Expand Down Expand Up @@ -256,16 +261,24 @@ bool EthernetICMPPing::asyncComplete(EthernetICMPEchoReply& result)
// - failed to send; or
// - are no longer waiting on this packet.
// either way, we're done

// Close RAW socket to allow device being pinged again
closeSocket();

return true;
}


if (W5100.getRXReceivedSize(_socket))
if (W5100.readSnRX_SIZE(_socket))
{
// ooooh, we've got a pending reply
EthernetICMPEcho echoReq(ICMP_ECHOREQ, _id, _curSeq, _payload);
receiveEchoReply(echoReq, _addr, result);
_asyncstatus = result.status; // make note of this status, whatever it is.

// Close RAW socket to allow device being pinged again
closeSocket();

return true; // whatever the result of the receiveEchoReply(), the async op is done.
}

Expand All @@ -286,13 +299,21 @@ bool EthernetICMPPing::asyncComplete(EthernetICMPEchoReply& result)

// this send has failed. too bad,
// we are done.

// Close RAW socket to allow device being pinged again
closeSocket();

return true;
}

// we timed out and have no more attempts left...
// hello? is anybody out there?
// guess not:
result.status = NO_RESPONSE;

// Close RAW socket to allow device being pinged again
closeSocket();

return true;
}

Expand All @@ -301,4 +322,4 @@ bool EthernetICMPPing::asyncComplete(EthernetICMPEchoReply& result)

}

#endif /* ICMPPING_ASYNCH_ENABLE */
#endif /* ICMPPING_ASYNCH_ENABLE */
3 changes: 2 additions & 1 deletion src/EthernetICMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class EthernetICMPPing
static uint16_t ping_timeout;

void openSocket();
void closeSocket();

Status sendEchoRequest(const IPAddress& addr, const EthernetICMPEcho& echoReq);
void receiveEchoReply(const EthernetICMPEcho& echoReq, const IPAddress& addr, EthernetICMPEchoReply& echoReply);
Expand All @@ -329,4 +330,4 @@ class EthernetICMPPing

#pragma pack(1)

#endif
#endif