From 25ce3bf3ebf8336fdfef260ab520cd6fb4c2c6ba Mon Sep 17 00:00:00 2001 From: Michael Scott Date: Mon, 27 Jan 2020 13:13:01 -0800 Subject: [PATCH] drivers: modem: socket: add modem_socket_next_packet_size Let's hide the internals of sock->packet_sizes[] by adding a function which returns the size of the next waiting packet. Signed-off-by: Michael Scott --- drivers/modem/modem_socket.c | 18 ++++++++++++++++++ drivers/modem/modem_socket.h | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/modem/modem_socket.c b/drivers/modem/modem_socket.c index 92522c72e5..c388c24ad5 100644 --- a/drivers/modem/modem_socket.c +++ b/drivers/modem/modem_socket.c @@ -19,6 +19,24 @@ * Packet Size Support Functions */ +u16_t modem_socket_next_packet_size(struct modem_socket_config *cfg, + struct modem_socket *sock) +{ + u16_t total = 0U; + + k_sem_take(&cfg->sem_lock, K_FOREVER); + + if (!sock || !sock->packet_count) { + goto exit; + } + + total = sock->packet_sizes[0]; + +exit: + k_sem_give(&cfg->sem_lock); + return total; +} + static u16_t modem_socket_packet_get_total(struct modem_socket *sock) { int i; diff --git a/drivers/modem/modem_socket.h b/drivers/modem/modem_socket.h index 4b3e5e7a7d..edda1f1085 100644 --- a/drivers/modem/modem_socket.h +++ b/drivers/modem/modem_socket.h @@ -59,7 +59,9 @@ struct modem_socket_config { const struct socket_op_vtable *vtable; }; -/* return total size of remaining packets */ +/* return size of the first packet */ +u16_t modem_socket_next_packet_size(struct modem_socket_config *cfg, + struct modem_socket *sock); int modem_socket_packet_size_update(struct modem_socket_config *cfg, struct modem_socket *sock, int new_total); int modem_socket_get(struct modem_socket_config *cfg, int family, int type,