tests: net: tcp: Add support for close callback
Add a function callback that is called when the TCP connection is closed. This is only available if doing network tests. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
parent
9b11fbd54c
commit
35e1df6bb4
|
@ -714,6 +714,12 @@ static void tcp_conn_release(struct k_work *work)
|
|||
struct tcp *conn = CONTAINER_OF(work, struct tcp, conn_release);
|
||||
struct net_pkt *pkt;
|
||||
|
||||
#if defined(CONFIG_NET_TEST)
|
||||
if (conn->test_closed_cb != NULL) {
|
||||
conn->test_closed_cb(conn, conn->test_user_data);
|
||||
}
|
||||
#endif
|
||||
|
||||
k_mutex_lock(&tcp_lock, K_FOREVER);
|
||||
|
||||
/* Application is no longer there, unref any remaining packets on the
|
||||
|
@ -762,6 +768,18 @@ static void tcp_conn_release(struct k_work *work)
|
|||
k_mutex_unlock(&tcp_lock);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_TEST)
|
||||
void tcp_install_close_cb(struct net_context *ctx,
|
||||
net_tcp_closed_cb_t cb,
|
||||
void *user_data)
|
||||
{
|
||||
NET_ASSERT(ctx->tcp != NULL);
|
||||
|
||||
((struct tcp *)ctx->tcp)->test_closed_cb = cb;
|
||||
((struct tcp *)ctx->tcp)->test_user_data = user_data;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int tcp_conn_unref(struct tcp *conn)
|
||||
{
|
||||
int ref_count = atomic_get(&conn->ref_count);
|
||||
|
|
|
@ -250,6 +250,9 @@ struct tcp_collision_avoidance_reno {
|
|||
};
|
||||
#endif
|
||||
|
||||
struct tcp;
|
||||
typedef void (*net_tcp_closed_cb_t)(struct tcp *conn, void *user_data);
|
||||
|
||||
struct tcp { /* TCP connection */
|
||||
sys_snode_t next;
|
||||
struct net_context *context;
|
||||
|
@ -263,6 +266,10 @@ struct tcp { /* TCP connection */
|
|||
struct tcp *accepted_conn;
|
||||
};
|
||||
net_context_connect_cb_t connect_cb;
|
||||
#if defined(CONFIG_NET_TEST)
|
||||
net_tcp_closed_cb_t test_closed_cb;
|
||||
void *test_user_data;
|
||||
#endif
|
||||
struct k_mutex lock;
|
||||
struct k_sem connect_sem; /* semaphore for blocking connect */
|
||||
struct k_sem tx_sem; /* Semaphore indicating if transfers are blocked . */
|
||||
|
@ -345,3 +352,9 @@ struct tcp { /* TCP connection */
|
|||
_flags(_fl, _op, _mask, sizeof(#_args) > 1 ? _args : true)
|
||||
|
||||
typedef void (*net_tcp_cb_t)(struct tcp *conn, void *user_data);
|
||||
|
||||
#if defined(CONFIG_NET_TEST)
|
||||
void tcp_install_close_cb(struct net_context *ctx,
|
||||
net_tcp_closed_cb_t cb,
|
||||
void *user_data);
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue