Skip to content

New get_timestamp() API that separates error code and time value #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LDong-Arm
Copy link

@LDong-Arm LDong-Arm commented Dec 2, 2020

Replaces #12

The ARM toolchain's time_t is unsigned, so we can't return a negative time_t to indicate an error - it gets casted to a very large positive time.

This commit adds a new overload

  int NTPClient::get_timestamp(time_t &timestamp, int timeout);

which returns 0 on success and a negative value on failure. On success, the time is written to the timestamp variable. This deprecates the old NTPClient::get_timestamp().

Note: The NTPClient is used by cloud connector examples (e.g. mbed-os-example-for-azure), and we have no way to catch NTP errors and retry when using the Arm Compiler due to the error being addressed here. We improved NTP stability by using time.google.com, but even that one seems to time out occasionally.

The ARM toolchain's time_t is unsigned, so we can't return
a negative time_t to indicate an error - it gets casted to
a very large positive time.

This commit adds a new overload

  int NTPClient::get_timestamp(time_t &timestamp, int timeout);

which returns 0 on success and a negative value on failure. On
success, the time is written to the timestamp variable. This
deprecates the old NTPClient::get_timestamp().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants