Skip to content

Commit c8b5187

Browse files
committed
net: lib: sntp: extra query send logic
Extract the SNTP query send logic out of `sntp_query` so that it can be used by functions that don't synchronously wait for the response. Signed-off-by: Jordan Yates <[email protected]>
1 parent 2e01288 commit c8b5187

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

subsys/net/lib/sntp/sntp.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,11 @@ int sntp_init(struct sntp_ctx *ctx, struct sockaddr *addr, socklen_t addr_len)
181181
return 0;
182182
}
183183

184-
int sntp_query(struct sntp_ctx *ctx, uint32_t timeout, struct sntp_time *ts)
184+
static int sntp_query_send(struct sntp_ctx *ctx)
185185
{
186186
struct sntp_pkt tx_pkt = { 0 };
187-
int ret = 0;
188187
int64_t ts_us = 0;
189188

190-
if (!ctx || !ts) {
191-
return -EFAULT;
192-
}
193-
194189
/* prepare request pkt */
195190
tx_pkt.li = 0;
196191
tx_pkt.vn = SNTP_VERSION_NUMBER;
@@ -201,7 +196,18 @@ int sntp_query(struct sntp_ctx *ctx, uint32_t timeout, struct sntp_time *ts)
201196
tx_pkt.tx_tm_s = htonl(ctx->expected_orig_ts.seconds);
202197
tx_pkt.tx_tm_f = htonl(ctx->expected_orig_ts.fraction);
203198

204-
ret = zsock_send(ctx->sock.fd, (uint8_t *)&tx_pkt, sizeof(tx_pkt), 0);
199+
return zsock_send(ctx->sock.fd, (uint8_t *)&tx_pkt, sizeof(tx_pkt), 0);
200+
}
201+
202+
int sntp_query(struct sntp_ctx *ctx, uint32_t timeout, struct sntp_time *ts)
203+
{
204+
int ret = 0;
205+
206+
if (!ctx || !ts) {
207+
return -EFAULT;
208+
}
209+
210+
ret = sntp_query_send(ctx);
205211
if (ret < 0) {
206212
NET_ERR("Failed to send over UDP socket %d", ret);
207213
return ret;

0 commit comments

Comments
 (0)