Skip to content

Commit a56d051

Browse files
authored
close socket asynchronously, if short timeouts
- this solves an issue during init(), where we quickly close all sockets without waiting for timeouts. - this may throw socket close URCs when they are actually closed.
1 parent 4bb5a33 commit a56d051

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -2507,7 +2507,10 @@ SARA_R5_error_t SARA_R5::socketClose(int socket, unsigned long timeout)
25072507
free(command);
25082508
return SARA_R5_ERROR_OUT_OF_MEMORY;
25092509
}
2510-
sprintf(command, "%s=%d", SARA_R5_CLOSE_SOCKET, socket);
2510+
// if timeout is short, close asynchronously and don't wait for socket closure (we will get the URC later)
2511+
// this will make sure the AT command parser is not confused during init()
2512+
const char* format = (SARA_R5_STANDARD_RESPONSE_TIMEOUT == timeout) ? "%s=%d,1" : "%s=%d";
2513+
sprintf(command, format, SARA_R5_CLOSE_SOCKET, socket);
25112514

25122515
err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK_OR_ERROR, response, timeout);
25132516

0 commit comments

Comments
 (0)