From 088289ec28ddc25e45ef179476057b72e140b0a5 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Thu, 19 Jan 2017 16:58:35 +0200 Subject: [PATCH] net: context: Add status to connect callback It is useful that the user API can know whether the connection was established properly or not. So this commit adds status parameter to connect callback in net_context API. The call to connect callback needs to be set properly in TCP code. This commit does not fix the connect callback call which is not properly done right now in net_context.c. Change-Id: I284a60ddd658ceef9e65022e96591f467a936a09 Signed-off-by: Jukka Rissanen --- include/net/net_context.h | 4 ++++ subsys/net/ip/net_context.c | 4 ++-- tests/net/context/src/main.c | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/net/net_context.h b/include/net/net_context.h index ce2e83517b7..6188145aab4 100644 --- a/include/net/net_context.h +++ b/include/net/net_context.h @@ -446,9 +446,13 @@ int net_context_listen(struct net_context *context, * established. * * @param context The context to use. + * @param status Status of the connection establishment. This is 0 + * if the connection was established successfully, <0 if there was an + * error. * @param user_data The user data given in net_context_connect() call. */ typedef void (*net_context_connect_cb_t)(struct net_context *context, + int status, void *user_data); /** diff --git a/subsys/net/ip/net_context.c b/subsys/net/ip/net_context.c index a04092f5831..6525c1d211b 100644 --- a/subsys/net/ip/net_context.c +++ b/subsys/net/ip/net_context.c @@ -1081,7 +1081,7 @@ int net_context_connect(struct net_context *context, #if defined(CONFIG_NET_UDP) if (net_context_get_type(context) == SOCK_DGRAM) { if (cb) { - cb(context, user_data); + cb(context, 0, user_data); } return 0; @@ -1112,7 +1112,7 @@ int net_context_connect(struct net_context *context, send_syn(context, addr); if (cb) { - cb(context, user_data); + cb(context, 0, user_data); } /* in tcp_synack_received() we give back this semaphore */ diff --git a/tests/net/context/src/main.c b/tests/net/context/src/main.c index 76d2df3b854..560e9a28784 100644 --- a/tests/net/context/src/main.c +++ b/tests/net/context/src/main.c @@ -349,7 +349,8 @@ static bool net_ctx_listen_v4(void) return true; } -static void connect_cb(struct net_context *context, void *user_data) +static void connect_cb(struct net_context *context, int status, + void *user_data) { sa_family_t family = POINTER_TO_INT(user_data);