Skip to content

Commit

Permalink
net: app: Fix connection closure issues with net_app_ctx
Browse files Browse the repository at this point in the history
In case of TCP and node acting as a APP_SERVER it can have multiple
concurrent connections. Calling close callback when there are still
active connections exists, causing an issue.

e.g. When a node acting as a HTTP server and can support multiple
TCP connections. Let's say one of the connection is in closing
state and the rest are still in active state. net_app_ctx is
calling close (http_closed) callback of registered upper layers.
HTTP assumes all the connections are closed and unref all the
connection related stuff.

Call the close callback only when there are no active connections.
Patch has also moved TCP stuff under one #ifdef.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
  • Loading branch information
rveerama1 authored and jukkar committed Feb 20, 2018
1 parent a495b31 commit 88e8119
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions subsys/net/lib/app/net_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,21 @@ void _net_app_received(struct net_context *net_ctx,

#if defined(CONFIG_NET_APP_SERVER)
if (ctx->app_type == NET_APP_SERVER) {
if (!pkt) {
#if defined(CONFIG_NET_TCP)
int i;
#endif
bool close = true;

if (ctx->cb.close) {
ctx->cb.close(ctx, status, ctx->user_data);
if (pkt) {
if (ctx->cb.recv) {
ctx->cb.recv(ctx, pkt, status, ctx->user_data);
}

return;
}

#if defined(CONFIG_NET_TCP)
for (i = 0;
ctx->proto == IPPROTO_TCP &&
i < CONFIG_NET_APP_SERVER_NUM_CONN;
i++) {
if (ctx->proto == IPPROTO_TCP) {
int i;

for (i = 0; i < CONFIG_NET_APP_SERVER_NUM_CONN; i++) {
if (ctx->server.net_ctxs[i] == net_ctx &&
ctx == net_ctx->net_app) {
net_context_put(net_ctx);
Expand All @@ -193,13 +194,21 @@ void _net_app_received(struct net_context *net_ctx,
break;
}
}
#endif

return;
/* Go through the loop and check if there are any
* active net_contexts. If there is any active net
* context do not call the close callback.
*/
for (i = 0; i < CONFIG_NET_APP_SERVER_NUM_CONN; i++) {
if (!ctx->server.net_ctxs[i]) {
close = false;
break;
}
}
}

if (ctx->cb.recv) {
ctx->cb.recv(ctx, pkt, status, ctx->user_data);
#endif
if (close && ctx->cb.close) {
ctx->cb.close(ctx, status, ctx->user_data);
}
}
#endif
Expand Down

0 comments on commit 88e8119

Please sign in to comment.