File tree Expand file tree Collapse file tree 4 files changed +19
-2
lines changed Expand file tree Collapse file tree 4 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ void __cheri_compartment("sntp_example") example()
1919 {
2020 Debug::log (" Failed to update NTP time" );
2121 Timeout oneSecond{MS_TO_TICKS (1000 )};
22+ t = Timeout{MS_TO_TICKS (5000 )};
2223 }
2324 Debug::log (" Updating NTP took {} ticks" , t.elapsed );
2425 t = UnlimitedTimeout;
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ void __cheri_compartment("https_example") example()
3232 {
3333 Debug::log (" Failed to update NTP time" );
3434 Timeout oneSecond{MS_TO_TICKS (1000 )};
35+ t = Timeout{MS_TO_TICKS (5000 )};
3536 }
3637 Debug::log (" Updating NTP took {} ticks" , t.elapsed );
3738 t = UnlimitedTimeout;
Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ void __cheri_compartment("mqtt_example") example()
9696 {
9797 Debug::log (" Failed to update NTP time" );
9898 Timeout oneSecond{MS_TO_TICKS (1000 )};
99+ t = Timeout{MS_TO_TICKS (5000 )};
99100 }
100101 Debug::log (" Updating NTP took {} ticks" , t.elapsed );
101102 t = UnlimitedTimeout;
Original file line number Diff line number Diff line change @@ -410,6 +410,7 @@ namespace
410410 SntpStatus_t lastStatus = SntpSuccess;
411411 do
412412 {
413+ // `timeout` is updated through `context`.
413414 status = Sntp_ReceiveTimeResponse (&context, 0 );
414415 if (status != lastStatus)
415416 {
@@ -423,8 +424,21 @@ namespace
423424 thread_sleep (&t);
424425 timeout->elapse (t.elapsed );
425426 }
426- } while (status == SntpNoResponseReceived);
427- Debug::log (" Received new time fron NTP!" );
427+ } while (status == SntpNoResponseReceived &&
428+ timeout->may_block ());
429+
430+ if (status != SntpSuccess)
431+ {
432+ Debug::log (" Failed to receive SNTP time response: {}" ,
433+ status);
434+ Timeout t{UnlimitedTimeout};
435+ network_socket_close (
436+ &t, MALLOC_CAPABILITY, udpContext.socket );
437+ timeout->elapse (t.elapsed );
438+ return ntp_error_to_errno (status);
439+ }
440+
441+ Debug::log (" Received new time from NTP!" );
428442 }
429443 else
430444 {
You can’t perform that action at this time.
0 commit comments