Skip to content

Commit 8f89e31

Browse files
jhirsirlubos
authored andcommitted
samples: nrf9160: modem_shell: sock send: support for abort
Support to kill/abort sock tool sending by long pressing DK button #1. Jira: MOSH-143 Signed-off-by: Jani Hirsimäki <[email protected]>
1 parent 53c95fd commit 8f89e31

File tree

1 file changed

+22
-4
lines changed
  • samples/nrf9160/modem_shell/src/sock

1 file changed

+22
-4
lines changed

samples/nrf9160/modem_shell/src/sock/sock.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "net_utils.h"
2929
#include "str_utils.h"
3030

31+
extern struct k_poll_signal mosh_signal;
32+
3133
/* Maximum number of sockets takes into account AT command socket */
3234
#define MAX_SOCKETS (CONFIG_POSIX_MAX_FDS - 1)
3335
#define SOCK_SEND_BUFFER_SIZE_UDP 1200
@@ -695,6 +697,15 @@ static int sock_send(
695697
{
696698
int bytes;
697699
int dest_addr_len = 0;
700+
int set, res;
701+
702+
k_poll_signal_check(&mosh_signal, &set, &res);
703+
if (set && res == MOSH_SIGNAL_KILL) {
704+
k_poll_signal_reset(&mosh_signal);
705+
shell_error(shell_global,
706+
"KILL signal received - exiting");
707+
return -ECANCELED;
708+
}
698709

699710
if (log_data) {
700711
if (data_hex_format) {
@@ -741,6 +752,7 @@ static void data_send_work_handler(struct k_work *item)
741752
struct data_transfer_info *data_send_info_ptr =
742753
CONTAINER_OF(item, struct data_transfer_info, work);
743754
struct sock_info *socket_info = data_send_info_ptr->parent;
755+
int ret;
744756

745757
if (!socket_info->in_use) {
746758
shell_print(
@@ -751,16 +763,17 @@ static void data_send_work_handler(struct k_work *item)
751763
return;
752764
}
753765

754-
sock_send(
766+
ret = sock_send(
755767
socket_info,
756768
socket_info->send_buffer,
757769
socket_info->send_buffer_size,
758770
true,
759771
data_send_info_ptr->data_format_hex);
760772

761-
k_work_schedule(
762-
&socket_info->send_info.work,
763-
K_SECONDS(socket_info->send_info.interval));
773+
if (ret != -ECANCELED) {
774+
k_work_schedule(&socket_info->send_info.work,
775+
K_SECONDS(socket_info->send_info.interval));
776+
}
764777
}
765778

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

795+
if (bytes == -ECANCELED) {
796+
socket_info->send_poll = false;
797+
break;
798+
}
799+
782800
if (bytes < 0) {
783801
/* Wait for socket to allow sending again */
784802
socket_info->send_poll = true;

0 commit comments

Comments
 (0)