Skip to content

Commit

Permalink
samples: nrf9160: modem_shell: sock send: support for abort
Browse files Browse the repository at this point in the history
Support to kill/abort sock tool sending by
long pressing DK button #1.
Jira: MOSH-143

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
  • Loading branch information
jhirsi authored and rlubos committed Aug 16, 2021
1 parent 53c95fd commit 8f89e31
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions samples/nrf9160/modem_shell/src/sock/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "net_utils.h"
#include "str_utils.h"

extern struct k_poll_signal mosh_signal;

/* Maximum number of sockets takes into account AT command socket */
#define MAX_SOCKETS (CONFIG_POSIX_MAX_FDS - 1)
#define SOCK_SEND_BUFFER_SIZE_UDP 1200
Expand Down Expand Up @@ -695,6 +697,15 @@ static int sock_send(
{
int bytes;
int dest_addr_len = 0;
int set, res;

k_poll_signal_check(&mosh_signal, &set, &res);
if (set && res == MOSH_SIGNAL_KILL) {
k_poll_signal_reset(&mosh_signal);
shell_error(shell_global,
"KILL signal received - exiting");
return -ECANCELED;
}

if (log_data) {
if (data_hex_format) {
Expand Down Expand Up @@ -741,6 +752,7 @@ static void data_send_work_handler(struct k_work *item)
struct data_transfer_info *data_send_info_ptr =
CONTAINER_OF(item, struct data_transfer_info, work);
struct sock_info *socket_info = data_send_info_ptr->parent;
int ret;

if (!socket_info->in_use) {
shell_print(
Expand All @@ -751,16 +763,17 @@ static void data_send_work_handler(struct k_work *item)
return;
}

sock_send(
ret = sock_send(
socket_info,
socket_info->send_buffer,
socket_info->send_buffer_size,
true,
data_send_info_ptr->data_format_hex);

k_work_schedule(
&socket_info->send_info.work,
K_SECONDS(socket_info->send_info.interval));
if (ret != -ECANCELED) {
k_work_schedule(&socket_info->send_info.work,
K_SECONDS(socket_info->send_info.interval));
}
}

static void sock_send_random_data_length(struct sock_info *socket_info)
Expand All @@ -779,6 +792,11 @@ static void sock_send_random_data_length(struct sock_info *socket_info)
bytes = sock_send(socket_info, socket_info->send_buffer,
strlen(socket_info->send_buffer), false, false);

if (bytes == -ECANCELED) {
socket_info->send_poll = false;
break;
}

if (bytes < 0) {
/* Wait for socket to allow sending again */
socket_info->send_poll = true;
Expand Down

0 comments on commit 8f89e31

Please sign in to comment.