Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Cellular fix for sockets: spot dead sockets. (#845)
Browse files Browse the repository at this point in the history
If, for some reason, a socket is dropped and no URC is emitted to say so (shouldn't happen but can be caused with an injection of AT+COPS=2, and of course, who knows?) the uCellSockRead() and uCellSockReceiveFrom() functions won't necessarily notice.

With this commit the "pending" check at the start of both functions is modified to flag an IO error if the AT command querying the amount of data pending on the socket fails; previously the pending check would have ignored any errors, relying on the subsequent half of the read call to pick those up.
  • Loading branch information
RobMeades authored Mar 3, 2023
1 parent ed9d6b7 commit bf09120
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cell/src/u_cell_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,11 @@ int32_t uCellSockReceiveFrom(uDeviceHandle_t cellHandle,
// They will get their received data, there
// is no need to worry.
}
uAtClientUnlock(atHandle);
if ((uAtClientUnlock(atHandle) != 0) || (x < 0)) {
// Looks like the socket has gone
pSocket->pendingBytes = 0;
negErrnoLocalOrSize = -U_SOCK_EIO;
}
}
if (pSocket->pendingBytes > 0) {
// In the UDP case we HAVE to read the number
Expand Down Expand Up @@ -1708,7 +1712,11 @@ int32_t uCellSockRead(uDeviceHandle_t cellHandle,
// They will get their received data, there
// is no need to worry.
}
uAtClientUnlock(atHandle);
if ((uAtClientUnlock(atHandle) != 0) || (x < 0)) {
// Looks like the socket has gone
pSocket->pendingBytes = 0;
negErrnoLocalOrSize = -U_SOCK_EIO;
}
}
if (pSocket->pendingBytes > 0) {
negErrnoLocalOrSize = U_SOCK_ENONE;
Expand Down

0 comments on commit bf09120

Please sign in to comment.