net: tcp2: Switch from k_timer to k_delayed_work
k_timer callback is executed from ISR context, which isn't currenty compatible with Zephyr's shell implementation. This problem was found while testing TCP2 client side. Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
This commit is contained in:
parent
bab5e7bd96
commit
d6f1937fbb
2 changed files with 12 additions and 14 deletions
|
@ -256,8 +256,8 @@ static void tcp_send_queue_flush(struct tcp *conn)
|
||||||
{
|
{
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
|
|
||||||
if (is_timer_subscribed(&conn->send_timer)) {
|
if (k_delayed_work_remaining_get(&conn->send_timer)) {
|
||||||
k_timer_stop(&conn->send_timer);
|
k_delayed_work_cancel(&conn->send_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((pkt = tcp_slist(&conn->send_queue, get,
|
while ((pkt = tcp_slist(&conn->send_queue, get,
|
||||||
|
@ -341,9 +341,9 @@ int net_tcp_unref(struct net_context *context)
|
||||||
return ref_count;
|
return ref_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tcp_send_process(struct k_timer *timer)
|
static void tcp_send_process(struct k_work *work)
|
||||||
{
|
{
|
||||||
struct tcp *conn = k_timer_user_data_get(timer);
|
struct tcp *conn = CONTAINER_OF(work, struct tcp, send_timer);
|
||||||
struct net_pkt *pkt = tcp_slist(&conn->send_queue, peek_head,
|
struct net_pkt *pkt = tcp_slist(&conn->send_queue, peek_head,
|
||||||
struct net_pkt, next);
|
struct net_pkt, next);
|
||||||
|
|
||||||
|
@ -367,15 +367,15 @@ static void tcp_send_process(struct k_timer *timer)
|
||||||
next) : tcp_pkt_clone(pkt);
|
next) : tcp_pkt_clone(pkt);
|
||||||
tcp_send(pkt);
|
tcp_send(pkt);
|
||||||
|
|
||||||
if (forget == false && is_timer_subscribed(
|
if (forget == false && !k_delayed_work_remaining_get(
|
||||||
&conn->send_timer) == false) {
|
&conn->send_timer)) {
|
||||||
conn->send_retries = tcp_retries;
|
conn->send_retries = tcp_retries;
|
||||||
conn->in_retransmission = true;
|
conn->in_retransmission = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conn && conn->in_retransmission) {
|
if (conn && conn->in_retransmission) {
|
||||||
k_timer_start(&conn->send_timer, K_MSEC(tcp_rto), K_NO_WAIT);
|
k_delayed_work_submit(&conn->send_timer, K_MSEC(tcp_rto));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +383,7 @@ static void tcp_send_timer_cancel(struct tcp *conn)
|
||||||
{
|
{
|
||||||
NET_ASSERT(conn->in_retransmission == true, "Not in retransmission");
|
NET_ASSERT(conn->in_retransmission == true, "Not in retransmission");
|
||||||
|
|
||||||
k_timer_stop(&conn->send_timer);
|
k_delayed_work_cancel(&conn->send_timer);
|
||||||
|
|
||||||
{
|
{
|
||||||
struct net_pkt *pkt = tcp_slist(&conn->send_queue, get,
|
struct net_pkt *pkt = tcp_slist(&conn->send_queue, get,
|
||||||
|
@ -396,7 +396,7 @@ static void tcp_send_timer_cancel(struct tcp *conn)
|
||||||
conn->in_retransmission = false;
|
conn->in_retransmission = false;
|
||||||
} else {
|
} else {
|
||||||
conn->send_retries = tcp_retries;
|
conn->send_retries = tcp_retries;
|
||||||
k_timer_start(&conn->send_timer, K_MSEC(tcp_rto), K_NO_WAIT);
|
k_delayed_work_submit(&conn->send_timer, K_MSEC(tcp_rto));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -752,7 +752,7 @@ static void tcp_out(struct tcp *conn, u8_t flags, ...)
|
||||||
|
|
||||||
sys_slist_append(&conn->send_queue, &pkt->next);
|
sys_slist_append(&conn->send_queue, &pkt->next);
|
||||||
|
|
||||||
tcp_send_process(&conn->send_timer);
|
tcp_send_process((struct k_work *)&conn->send_timer);
|
||||||
out:
|
out:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -787,8 +787,7 @@ static struct tcp *tcp_conn_alloc(void)
|
||||||
|
|
||||||
sys_slist_init(&conn->rsv_bufs);
|
sys_slist_init(&conn->rsv_bufs);
|
||||||
|
|
||||||
k_timer_init(&conn->send_timer, tcp_send_process, NULL);
|
k_delayed_work_init(&conn->send_timer, tcp_send_process);
|
||||||
k_timer_user_data_set(&conn->send_timer, conn);
|
|
||||||
|
|
||||||
tcp_conn_ref(conn);
|
tcp_conn_ref(conn);
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include "tp.h"
|
#include "tp.h"
|
||||||
|
|
||||||
#define is(_a, _b) (strcmp((_a), (_b)) == 0)
|
#define is(_a, _b) (strcmp((_a), (_b)) == 0)
|
||||||
#define is_timer_subscribed(_t) (k_timer_remaining_get(_t))
|
|
||||||
|
|
||||||
#define th_seq(_x) ntohl((_x)->th_seq)
|
#define th_seq(_x) ntohl((_x)->th_seq)
|
||||||
#define th_ack(_x) ntohl((_x)->th_ack)
|
#define th_ack(_x) ntohl((_x)->th_ack)
|
||||||
|
@ -156,7 +155,7 @@ struct tcp { /* TCP connection */
|
||||||
u16_t win;
|
u16_t win;
|
||||||
struct tcp_win *rcv;
|
struct tcp_win *rcv;
|
||||||
struct tcp_win *snd;
|
struct tcp_win *snd;
|
||||||
struct k_timer send_timer;
|
struct k_delayed_work send_timer;
|
||||||
sys_slist_t send_queue;
|
sys_slist_t send_queue;
|
||||||
bool in_retransmission;
|
bool in_retransmission;
|
||||||
size_t send_retries;
|
size_t send_retries;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue