Skip to content

Commit

Permalink
net: tcp: Add util to loop through all TCP connections
Browse files Browse the repository at this point in the history
This is to be used in net-shell to view currently active
TCP connections.

Change-Id: I9c2a69e3ab6013835a42dfde47d580623998b3fa
Signed-off-by: Jukka Rissanen <[email protected]>
  • Loading branch information
jukkar committed Dec 2, 2016
1 parent 9148567 commit 797b642
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions net/yaip/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,3 +792,24 @@ void net_tcp_change_state(struct net_tcp *tcp,
tcp->context->user_data);
}
}

void net_tcp_foreach(net_tcp_cb_t cb, void *user_data)
{
int i, key;

key = irq_lock();

for (i = 0; i < NET_MAX_TCP_CONTEXT; i++) {
if (!net_tcp_is_used(&tcp_context[i])) {
continue;
}

irq_unlock(key);

cb(&tcp_context[i], user_data);

key = irq_lock();
}

irq_unlock(key);
}
11 changes: 11 additions & 0 deletions net/yaip/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@ int net_tcp_prepare_ack(struct net_tcp *tcp, const struct sockaddr *remote,
int net_tcp_prepare_reset(struct net_tcp *tcp, const struct sockaddr *remote,
struct net_buf **buf);

typedef void (*net_tcp_cb_t)(struct net_tcp *tcp, void *user_data);

/**
* @brief Go through all the TCP connections and call callback
* for each of them.
*
* @param cb User supplied callback function to call.
* @param user_data User specified data.
*/
void net_tcp_foreach(net_tcp_cb_t cb, void *user_data);

#if defined(CONFIG_NET_TCP)
void net_tcp_init(void);
#else
Expand Down

0 comments on commit 797b642

Please sign in to comment.