Skip to content
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

Add Sntp_ReceiveTimeResponse API #16

Merged
merged 11 commits into from
May 13, 2021

Conversation

aggarw13
Copy link
Contributor

@aggarw13 aggarw13 commented May 12, 2021

Add a Sntp_ReceiveTimeResponse API to allow application to obtain the response for a time request that was made to a server (with Sntp_SendTimeRequest API).

The API looks at 3 different timeouts in its operations:

  1. Server Response timeout - This PR adds a responseTimeoutMs state to the SntpContext_t to allow the application to specify timeouts for server responses (to time requests). The timeout period for a server starts after the Sntp_SendTimeRequest API is called to send a request to the server. The Sntp_ReceiveTimeResponse API keeps a track of whether server response has timed out whenever it is called, and returns a SntpServerResponseTimeout error code (even if the blockTimeMs value still allows more time window for waiting on server response).

  2. Block Time - The API takes a blockTimeMs parameter which determines the maximum amount of time the function will block waiting for the server response UNLESS either the server response is received OR the server response has timed out OR there is a network read error encountered (like hitting a read retry timeout)

  3. Read Retry Timeout - This PR adds an SNTP_RECV_POLLING_TIMEOUT_MS configuration macro that represents the maximum time window of retrying zero data reads. This window is only initiated after some partial data is initially read from the network. The rationale is that when some initial data is available from the network, then it is likely that the remaining SNTP response packet will be available and thus, the read retry timeout window starts. The Sntp_ReceiveTimeResponse API uses this configuration value to retry partial data reads on the network.

@aggarw13 aggarw13 force-pushed the api/sntp-receive-time-response branch from 1cc09f7 to 81c79f5 Compare May 12, 2021 23:25
@aggarw13 aggarw13 force-pushed the api/sntp-receive-time-response branch from 81c79f5 to 47adf0a Compare May 12, 2021 23:28
source/core_sntp_client.c Outdated Show resolved Hide resolved
SntpStatus_t Sntp_Init( SntpContext_t * pContext,
const SntpServerInfo_t * pTimeServers,
size_t numOfServers,
uint32_t serverResponseTimeoutMs,
uint8_t * pNetworkBuffer,
size_t bufferSize,
SntpResolveDns_t resolveDnsFunc,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a caller of this function, it's hard for me to tell how each parameter is related to one another. Might it be worth grouping parameters into separate structs to make the relationships self-documenting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, can take that hygiene in a separate PR 🙂

Co-authored-by: Oscar Michael Abrina <[email protected]>
@aggarw13 aggarw13 merged commit cb9a306 into FreeRTOS:main May 13, 2021
@aggarw13 aggarw13 deleted the api/sntp-receive-time-response branch May 13, 2021 17:45
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.

3 participants